Skip to content

Commit

Permalink
fix affine_transform_nearest bug on edge; mode 'nearest' by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl5766 committed Oct 8, 2024
1 parent 28f461e commit a6e621d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/cvpl_tools/im/algs/dask_ndinterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def affine_transform_nearest(
matrix = matrix[:image.ndim, :image.ndim]

cval = kwargs.pop('cval', 0)
mode = kwargs.pop('mode', 'constant')
mode = kwargs.pop('mode', 'nearest')
prefilter = kwargs.pop('prefilter', False)

supported_modes = ['constant', 'nearest']
Expand Down Expand Up @@ -188,7 +188,7 @@ def affine_transform_nearest(
out_chunk_offset = [block_offsets[dim][block_ind[dim]]
for dim in range(n)]

out_chunk_edges = np.array([i for i in np.ndindex(tuple([2] * n))]) \
out_chunk_edges = np.array([i for i in np.ndindex((2,) * n)]) \
* np.array(out_chunk_shape) + np.array(out_chunk_offset)

# map output chunk edges onto input image coordinates
Expand All @@ -210,8 +210,8 @@ def affine_transform_nearest(
rel_image_i[dim] = np.floor(rel_image_i[dim] + .5)
rel_image_f[dim] = np.floor(rel_image_f[dim] + .5)

rel_image_i[dim] = np.clip(rel_image_i[dim], 0, s)
rel_image_f[dim] = np.clip(rel_image_f[dim], 0, s)
rel_image_i[dim] = np.clip(rel_image_i[dim], 0, s - 1)
rel_image_f[dim] = np.clip(rel_image_f[dim], 1, s)

rel_image_slice = []
for dim in range(n):
Expand All @@ -222,9 +222,6 @@ def affine_transform_nearest(

rel_image = image[rel_image_slice]

print('-----', block_ind, '-----')
print(rel_image_slice)

"""Block comment for future developers explaining how `offset` is
transformed into `offset_prime` for each output chunk.
Modify offset to point into cropped image.
Expand Down

0 comments on commit a6e621d

Please sign in to comment.