Esempio n. 1
0
 def test_split_fullpath_2(self):
     test_resource_sample_img_path = path.split_fullpath(
         os.path.join(self.test_path, self.test_resource_folder_name,
                      "sample.png"))
     print(test_resource_sample_img_path)
     self.assertEqual(test_resource_sample_img_path[1], "sample")
     self.assertEqual(test_resource_sample_img_path[2], ".png")
Esempio n. 2
0
def slice_and_write_single_image(
    full_image_path,
    as_gray,
    tile_size,
    inbox_size,
    stride_size,
    add_same_padding,
    not_discard_rest_horizontal_tile,
    not_discard_rest_vertical_tile,
    target_folder,
):
    _, _base_filename, _base_ext = split_fullpath(full_image_path)
    _image = cv2.imread(full_image_path)
    if as_gray:
        _image = cv2.cvtColor(_image, cv2.COLOR_BGR2GRAY)
    _sliced_images = slice_by_pixel_size(
        _image,
        tile_height_width=(tile_size, tile_size),
        inbox_height_width=(inbox_size, inbox_size),
        stride_height_width=(stride_size, stride_size),
        add_same_padding=add_same_padding,
        discard_horizontal_overflow=not not_discard_rest_horizontal_tile,
        discard_vertical_overflow=not not_discard_rest_vertical_tile,
    )

    def _write_image(_row_num, _col_num, sliced_img):
        result_path = os.path.join(
            target_folder,
            "{}_{:02d}_{:02d}{}".format(_base_filename, _row_num, _col_num,
                                        _base_ext),
        )
        cv2.imwrite(result_path, sliced_img)

    apply_each_slice(_sliced_images, _write_image)
Esempio n. 3
0
def bw_space_single_image(
    full_image_path,
    edge_size,
    target_folder,
):
    _, _base_filename, _base_ext = split_fullpath(full_image_path)
    image = cv2.imread(full_image_path)
    bw_spaced_image = draw__mask_with_edge(image, edge_size)
    result_path = os.path.join(target_folder,
                               "{}{}".format(_base_filename, _base_ext))
    cv2.imwrite(result_path, bw_spaced_image)
Esempio n. 4
0
def resize_single_image(
    full_image_path,
    target_size,
    target_folder,
):
    _, _base_filename, _base_ext = split_fullpath(full_image_path)
    image = cv2.imread(full_image_path, cv2.IMREAD_UNCHANGED)
    resized_image = img_resize(image, target_size)
    result_path = os.path.join(target_folder,
                               "{}{}".format(_base_filename, _base_ext))
    cv2.imwrite(result_path, resized_image)
Esempio n. 5
0
def mask_single_image(
    full_image_path,
    mask_bw_image_path,
    target_folder,
):
    _, _base_filename, _base_ext = split_fullpath(full_image_path)
    image = cv2.imread(full_image_path)
    masking_image = cv2.imread(mask_bw_image_path, cv2.IMREAD_GRAYSCALE)
    masked_image = mask_image(image, masking_image)
    result_path = os.path.join(target_folder,
                               "{}{}".format(_base_filename, _base_ext))
    cv2.imwrite(result_path, masked_image)
Esempio n. 6
0
def create_image_frame(
    full_image_path,
    zero_folder,
    prev_folders,
    next_folders,
    num_fillzero,
    target_folder,
    separator: str = "_",
):
    _, _base_filename, _base_ext = split_fullpath(full_image_path)

    zero_folder_2 = os.path.join(target_folder, zero_folder)
    zero_file = os.path.join(zero_folder_2,
                             "{}{}".format(_base_filename, _base_ext))
    shutil.copyfile(full_image_path, zero_file)

    zero_file_number: str = _base_filename[:_base_filename.find(separator)]
    zero_file_after: str = _base_filename[_base_filename.find(separator):]

    for index, prev_folder in enumerate(prev_folders):
        new_number: int = int(zero_file_number) + (index + 1)
        new_name: str = "{}{}".format(
            str(new_number).zfill(num_fillzero), zero_file_after)
        prev_folder_2 = os.path.join(target_folder, prev_folder)
        prev_file = os.path.join(prev_folder_2,
                                 "{}{}".format(new_name, _base_ext))
        shutil.copyfile(full_image_path, prev_file)

    for index, next_folder in enumerate(next_folders):
        new_number: int = int(zero_file_number) - (index + 1)
        new_name: str = "{}{}".format(
            str(new_number).zfill(num_fillzero), zero_file_after)
        next_folder_2 = os.path.join(target_folder, next_folder)
        next_file = os.path.join(next_folder_2,
                                 "{}{}".format(new_name, _base_ext))
        shutil.copyfile(full_image_path, next_file)
Esempio n. 7
0
 def test_split_fullpath_3(self):
     test_filename_path = path.split_fullpath(
         os.path.join(self.working_path, "LICENSE"))
     print(test_filename_path)
     self.assertEqual(test_filename_path[1], "LICENSE")
     self.assertEqual(test_filename_path[2], "")
Esempio n. 8
0
 def test_split_fullpath_1(self):
     test_resource_path = path.split_fullpath(
         os.path.join(self.test_path, self.test_resource_folder_name))
     print(test_resource_path)
     self.assertEqual(test_resource_path[1], None)
     self.assertEqual(test_resource_path[2], None)
Esempio n. 9
0
    args = parser.parse_args()

    # parameter
    full_image_abspath: str = args.full_image_abspath
    num_prev_frame: int = args.num_prev_frame
    num_next_frame: int = args.num_next_frame
    num_fillzero: int = args.num_fillzero
    common_folder_name: Optional[str] = args.common_folder_name
    target_folder: str = os.path.join(args.target_folder)

    if not os.path.exists(full_image_abspath):
        raise Exception("'{}' does not exist.".format(full_image_abspath))

    create_folder_if_not_exist(target_folder)

    fp, _, _ = split_fullpath(full_image_abspath)
    if common_folder_name is None:
        last_path = basename(fp)
    else:
        last_path = common_folder_name

    zero_folder = "{}zero".format(last_path)
    prev_folders = []
    next_folders = []

    path = os.path.join(target_folder, zero_folder)
    create_folder_if_not_exist(path)

    for prev_i in range(num_prev_frame):
        prev_folder = "{}p{}".format(last_path, prev_i + 1)
        path = os.path.join(target_folder, prev_folder)