Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anti aliasing #32

Open
kurmukovai opened this issue Aug 7, 2023 · 0 comments
Open

Add anti aliasing #32

kurmukovai opened this issue Aug 7, 2023 · 0 comments

Comments

@kurmukovai
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant