Discussion:
[ITK-users] Resizing DICOM images
G Reina
2017-07-17 22:52:03 UTC
Permalink
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
Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]
2017-07-18 15:08:46 UTC
Permalink
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 <***@eng.ucsd.edu>
Date: Monday, July 17, 2017 at 6:52 PM
To: "insight-***@itk.org" <insight-***@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
G Reina
2017-07-18 16:34:20 UTC
Permalink
Thanks so much.

That's very helpful.

Tony

On Jul 18, 2017 8:09 AM, "Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]" <
Post by Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]
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
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).
For truly arbitrary resizing use the ResampleImageFilter (https://itk.org/
SimpleITKDoxygen/html/classitk_1_1simple_1_1ResampleImageFilter.html).
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
*Date: *Monday, July 17, 2017 at 6:52 PM
*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
Bill Lorensen
2017-07-18 17:31:06 UTC
Permalink
If you don't mind using C++, here is an example:
https://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM
Post by G Reina
Thanks so much.
That's very helpful.
Tony
On Jul 18, 2017 8:09 AM, "Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]"
Post by Yaniv, Ziv Rafael (NIH/NLM/LHC) [C]
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
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).
For truly arbitrary resizing use the ResampleImageFilter
(https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ResampleImageFilter.html).
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
Date: Monday, July 17, 2017 at 6:52 PM
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
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
--
Unpaid intern in BillsBasement at noware dot com
_____________________________________
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.c
Loading...