Re: [ITK-users] [ITK] Resizing DICOM images

"Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]" <[email protected]>
Newsgroups gmane.comp.lib.itk.user
Message-ID <[email protected]>
Hello Tony,

Short answer is yes.

To shrink a volume using integral sizes, use the BinShrinkImageFilter (https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1BinShrinkImageFilter.html).
Using the procedural interface to shrink an image by 4 in x, by 4 in y and by 2 in z would be:
bShrinkImage = sitk.BinShrink(img, [4,4,2])

The BinShrink filter also averages the neighborhood, so it deals to some extent with potential aliasing. Don’t use this filter if your volume represents a discrete set of labels (i.e. segmentation).


Longer answer:

For truly arbitrary resizing use the ResampleImageFilter (https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ResampleImageFilter.html).

Using the procedural interface to modify the original (style is verbose for clarity):

new_x_size = 700 #upsample
new_y_size = 64 #downsample
new_z_size = 5 #downsample
new_size = [new_x_size, new_y_size, new_z_size]
new_spacing = [old_sz*old_spc/new_sz  for old_sz, old_spc, new_sz in zip(img.GetSize(), img.GetSpacing(), new_size)]

interpolator_type = sitk.sitkLinear

new_img = sitk.Resample(img, new_size, sitk.Transform(), interpolator_type, img.GetOrigin(), new_spacing, img.GetDirection(), 0.0, img.GetPixelIDValue())

The ResampleImageFilter does not deal with aliasing, so if you are downsampling it is recommended to blur prior to resampling. If you are resampling a volume with discrete labels you would use the sitk.sitkNearestNeighbor
interpolator type.

    hope this helps
            Ziv




From: G Reina <[email protected]>
Date: Monday, July 17, 2017 at 6:52 PM
To: "[email protected]" <[email protected]>
Subject: [ITK] [ITK-users] Resizing DICOM images

I've seen in pydicom and opencv how to resize a DICOM image to an arbitrary pixel resolution (e.g. going from 512x512 down to 128x128).

Does SimpleITK have a way to do this for 3D image volumes (i.e. rescale height, width, and slice at the same time?

I'm looking to have a method to make my DICOM volumes uniform in shape.

Thanks.
-Tony

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.