def test_set_patches_around_landmarks(): patch_shape = (21, 12) image = mio.import_builtin_asset.lenna_png() patches1 = image.extract_patches_around_landmarks( patch_shape=patch_shape, as_single_array=True) new_image1 = Image.init_blank(image.shape, image.n_channels) new_image1.landmarks['LJSON'] = image.landmarks['LJSON'] new_image1.set_patches_around_landmarks(patches1) patches2 = image.extract_patches_around_landmarks( patch_shape=patch_shape, as_single_array=False) new_image2 = Image.init_blank(image.shape, image.n_channels) new_image2.landmarks['LJSON'] = image.landmarks['LJSON'] new_image2.set_patches_around_landmarks(patches2) assert_array_equal(new_image1.pixels, new_image2.pixels)
def test_set_patches_around_landmarks(): patch_shape = (21, 12) image = mio.import_builtin_asset.takeo_ppm() patches1 = image.extract_patches_around_landmarks(patch_shape=patch_shape, as_single_array=True) new_image1 = Image.init_blank(image.shape, image.n_channels) new_image1.landmarks["PTS"] = image.landmarks["PTS"] extracted1 = new_image1.set_patches_around_landmarks(patches1) patches2 = image.extract_patches_around_landmarks(patch_shape=patch_shape, as_single_array=False) new_image2 = Image.init_blank(image.shape, image.n_channels) new_image2.landmarks["PTS"] = image.landmarks["PTS"] extracted2 = new_image2.set_patches_around_landmarks(patches2) assert_array_equal(extracted1.pixels, extracted2.pixels)
def test_set_patches_around_landmarks(): patch_shape = (21, 12) image = mio.import_builtin_asset.takeo_ppm() patches1 = image.extract_patches_around_landmarks( patch_shape=patch_shape, as_single_array=True) new_image1 = Image.init_blank(image.shape, image.n_channels) new_image1.landmarks['PTS'] = image.landmarks['PTS'] extracted1 = new_image1.set_patches_around_landmarks(patches1) patches2 = image.extract_patches_around_landmarks( patch_shape=patch_shape, as_single_array=False) new_image2 = Image.init_blank(image.shape, image.n_channels) new_image2.landmarks['PTS'] = image.landmarks['PTS'] extracted2 = new_image2.set_patches_around_landmarks(patches2) assert_array_equal(extracted1.pixels, extracted2.pixels)
def test_int_pointcloud(): image = Image.init_blank([100, 100]) patch_shape = (16, 16) landmarks = PointCloud(np.array([[50, 50]])) patches = image.extract_patches( landmarks, patch_shape=patch_shape, as_single_array=False ) assert patches[0].pixels.dtype == np.float
def test_uint16_type(): image = Image.init_blank([100, 100], dtype=np.uint16) patch_shape = (16, 16) landmarks = PointCloud(np.array([[50, 50.]])) patches = image.extract_patches(landmarks, patch_shape=patch_shape, as_single_array=False) assert (patches[0].pixels.dtype == np.uint16)
def test_int_pointcloud(): image = Image.init_blank([100, 100]) patch_shape = (16, 16) landmarks = PointCloud(np.array([[50, 50]])) patches = image.extract_patches(landmarks, patch_shape=patch_shape, as_single_array=False) assert(patches[0].pixels.dtype == np.float)
def test_single_list_patch(): patch_shape = (21, 7) n_channels = 4 im = Image.init_blank(patch_shape, n_channels) patch = [Image(np.ones((n_channels,) + patch_shape)), Image(2 * np.ones((n_channels,) + patch_shape))] patch_center = PointCloud(np.array([[10., 3.], [11., 3.]])) im.set_patches(patch, patch_center, offset=(0, 0), offset_index=0) res = np.ones(patch_shape) res[1:-1, :] = 2 assert_array_equal(im.pixels[2, ...], res)
def test_single_ndarray_patch(): patch_shape = (21, 7) n_channels = 4 im = Image.init_blank(patch_shape, n_channels) patch = np.zeros((2, 2, n_channels) + patch_shape) patch[1, 0, ...] = np.ones((n_channels, ) + patch_shape) patch[1, 1, ...] = 2 * np.ones((n_channels, ) + patch_shape) patch_center = PointCloud(np.array([[10., 3.], [11., 3.]])) new_im = im.set_patches(patch, patch_center, offset=(0, 0), offset_index=1) res = np.zeros(patch_shape) res[1:-1, :] = 2 assert_array_equal(new_im.pixels[2, ...], res)
def test_single_ndarray_patch(): patch_shape = (21, 7) n_channels = 4 im = Image.init_blank(patch_shape, n_channels) patch = np.zeros((2, 2, n_channels) + patch_shape) patch[1, 0, ...] = np.ones((n_channels,) + patch_shape) patch[1, 1, ...] = 2 * np.ones((n_channels,) + patch_shape) patch_center = PointCloud(np.array([[10., 3.], [11., 3.]])) new_im = im.set_patches(patch, patch_center, offset=(0, 0), offset_index=1) res = np.zeros(patch_shape) res[1:-1, :] = 2 assert_array_equal(new_im.pixels[2, ...], res)
def test_single_ndarray_patch(): patch_shape = (8, 7) n_channels = 4 im = Image.init_blank((32, 32), n_channels) patch = np.zeros((2, 2, n_channels) + patch_shape) patch[0, 0, ...] = np.full((n_channels,) + patch_shape, 1) # Should be unused patch[0, 1, ...] = np.full((n_channels,) + patch_shape, 2) patch[1, 0, ...] = np.full((n_channels,) + patch_shape, 3) # Should be unused patch[1, 1, ...] = np.full((n_channels,) + patch_shape, 4) patch_center = PointCloud(np.array([[4.0, 4.0], [16.0, 16.0]])) new_im = im.set_patches(patch, patch_center, offset_index=1) res = np.zeros((32, 32)) res[:8, 1:8] = 2 res[12:20, 13:20] = 4 assert_array_equal(new_im.pixels[2], res)
def test_single_list_patch(): patch_shape = (8, 7) n_channels = 4 im = Image.init_blank((32, 32), n_channels) patch = [ Image(np.full((n_channels,) + patch_shape, 1)), Image(np.full((n_channels,) + patch_shape, 2)), # Should be unused Image(np.full((n_channels,) + patch_shape, 3)), Image(np.full((n_channels,) + patch_shape, 4)), ] # Should be unused patch_center = PointCloud(np.array([[4.0, 4.0], [16.0, 16.0]])) new_im = im.set_patches(patch, patch_center, offset_index=0) res = np.zeros((32, 32)) res[:8, 1:8] = 1 res[12:20, 13:20] = 3 assert_array_equal(new_im.pixels[0], res)