コード例 #1
0
ファイル: makeDataset.py プロジェクト: rm-wu/bioinfo_project
def crop_images(img_list, seg_list, imag_path, seg_path):
    """
    Function that crops the image into N = 2000 / SLICE_LEN tiles

    :param img_list: list of the images to crop
    :param seg_list: list of the segmentations to crop
    :param imag_path: path where to save the cropped images
    :param seg_path: path where to save the cropped segmentations
    :return:
    """
    for idx, (img_path, mask_path) in enumerate(zip(img_list, seg_list)):
        image = cv2.imread(str(img_path))
        image = F.pad(image, min_height=IMG_DIM, min_width=IMG_DIM)

        mask = cv2.imread(str(mask_path))
        mask = F.pad(mask, min_height=IMG_DIM, min_width=IMG_DIM)

        tile = 0
        for i in range(0, 2000, SLICE_LEN):
            for j in range(0, 2000, SLICE_LEN):
                tile += 1
                cv2.imwrite(os.path.join(imag_path, f"{idx:04}_{tile:02}.png"),
                            image[i:i + INPUT_DIM, j:j + INPUT_DIM])
                cv2.imwrite(os.path.join(seg_path, f"{idx:04}_{tile:02}.png"),
                            mask[i:i + INPUT_DIM, j:j + INPUT_DIM])
コード例 #2
0
def test_pad_float(target):
    img = np.array([[0.1, 0.2], [0.3, 0.4]], dtype=np.float32)
    expected = np.array([[0.4, 0.3, 0.4, 0.3], [0.2, 0.1, 0.2, 0.1],
                         [0.4, 0.3, 0.4, 0.3], [0.2, 0.1, 0.2, 0.1]],
                        dtype=np.float32)
    img, expected = convert_2d_to_target_format([img, expected], target=target)
    padded_img = F.pad(img, min_height=4, min_width=4)
    assert_array_almost_equal_nulp(padded_img, expected)
コード例 #3
0
def test_pad(target):
    img = np.array([[1, 2], [3, 4]], dtype=np.uint8)
    expected = np.array(
        [[4, 3, 4, 3], [2, 1, 2, 1], [4, 3, 4, 3], [2, 1, 2, 1]],
        dtype=np.uint8)
    img, expected = convert_2d_to_target_format([img, expected], target=target)
    padded = F.pad(img, min_height=4, min_width=4)
    assert np.array_equal(padded, expected)
コード例 #4
0
ファイル: data.py プロジェクト: artbataev/digital_peter
 def pad_pil_image(img, **params):
     height, width, _ = img.shape
     tail = width % image_len_divisible_by
     if tail == 0:
         return img
     # args for pad: left, top, right, bottom
     # return functional.pad(img, (0, 0, image_len_divisible_by - tail, 0), padding_mode="edge")
     return AF.pad(img,
                   min_height=height,
                   min_width=width + image_len_divisible_by - tail)
コード例 #5
0
def test_pad(target):
    img = np.array([[1, 2], [3, 4]], dtype=np.uint8)
    expected = np.array(
        [[4, 3, 4, 3], [2, 1, 2, 1], [4, 3, 4, 3], [2, 1, 2, 1]],
        dtype=np.uint8)
    if target == 'image':
        img = convert_2d_to_3d(img)
        expected = convert_2d_to_3d(expected)
    padded = F.pad(img, min_height=4, min_width=4)
    assert np.array_equal(padded, expected)
コード例 #6
0
def test_pad(target):
    img = np.array(
        [[1, 2],
         [3, 4]], dtype=np.uint8)
    expected = np.array(
        [[4, 3, 4, 3],
         [2, 1, 2, 1],
         [4, 3, 4, 3],
         [2, 1, 2, 1]], dtype=np.uint8)
    if target == 'image':
        img = convert_2d_to_3d(img)
        expected = convert_2d_to_3d(expected)
    padded = F.pad(img, min_height=4, min_width=4)
    assert np.array_equal(padded, expected)
コード例 #7
0
 def albumentations(self, img):
     return albumentations.pad(img, min_height=512, min_width=512)
コード例 #8
0
 def albumentations(self, img):
     return albumentations.pad(img, min_height=512, min_width=512)