Skip to content

Add anti aliasing #32

@kurmukovai

Description

@kurmukovai

Can we add anti aliasing to zoom and zoom_to_shape? Zooming to coarse resolution results in interpolation artifcats:

from amid import AMOS
from einops import reduce
dataset = AMOS()
i = dataset.ids[0]
image = dataset.image(i)
spacing = dataset.spacing(i)

print(image.shape, spacing) # (768, 768, 90) [0.5703125 0.5703125 5.]
target_spacing = np.array([5,5,5])

def plot_projections(zi):
    front = reduce(zoomed_image, 'w d h -> h w', reduction='max')
    side = reduce(zoomed_image, 'w d h -> h d', reduction='max')
    top = reduce(zoomed_image, 'w d h -> w d', reduction='max')

    fig, axs = plt.subplots(1, 3, figsize=(15,5))
    axs[0].imshow(front[::-1], cmap='gray')
    axs[1].imshow(side[::-1], cmap='gray')
    axs[2].imshow(top, cmap='gray');

from imops import zoom
image_imops = zoom(image, scale_factor=spacing/target_spacing, order=0)
plot_projections(image_imops)

image

This is a known problem, and is typically solved with anti aliasing:

from skimage.transform import rescale
image_skimage = rescale(image, scale=spacing/target_spacing, order=1, anti_aliasing=True)
plot_projections(image_skimage)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions