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_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)
def test_convert_patches_list_to_single_array(): patch_shape = (7, 2) n_channels = 10 n_centers = 2 n_offsets = 2 patches_list = [Image(1 * np.ones((n_channels,) + patch_shape)), Image(2 * np.ones((n_channels,) + patch_shape)), Image(3 * np.ones((n_channels,) + patch_shape)), Image(4 * np.ones((n_channels,) + patch_shape))] patches_array = np.zeros((n_centers, n_offsets, n_channels) + patch_shape) patches_array[0, 0, ...] = patches_list[0].pixels patches_array[0, 1, ...] = patches_list[1].pixels patches_array[1, 0, ...] = patches_list[2].pixels patches_array[1, 1, ...] = patches_list[3].pixels assert_array_equal( _convert_patches_list_to_single_array(patches_list, n_centers), patches_array)