[ITK-users] [ITK] Resizing DICOM images

Bill Lorensen bill.lorensen at gmail.com
Tue Jul 18 13:31:06 EDT 2017


If you don't mind using C++, here is an example:
https://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM


On Tue, Jul 18, 2017 at 12:34 PM, G Reina <greina at eng.ucsd.edu> wrote:
> Thanks so much.
>
> That's very helpful.
>
> Tony
>
> On Jul 18, 2017 8:09 AM, "Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]"
> <zivrafael.yaniv at nih.gov> wrote:
>>
>> 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 <greina at eng.ucsd.edu>
>> Date: Monday, July 17, 2017 at 6:52 PM
>> To: "insight-users at itk.org" <insight-users at itk.org>
>> 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
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the Insight-users mailing list