[ITK] [ITK-users] SimpleITK Downsampling results in blank image

Bradley Lowekamp blowekamp at mail.nih.gov
Tue Nov 18 08:39:26 EST 2014


I have a couple comments on you example below, but over all it looks OK.

On Nov 17, 2014, at 6:20 PM, jmerkow <jmerkow at gmail.com> wrote:

> I have a strange issue when using the Resample procedural interface in
> SimpleITK.
> I have tried all the call signatures, but I can't seem to get meaningful
> output.
> I wrote a small illustrative example, where I read an image, attempt to
> downsample by 2, and get nothing out.  This is written in python, using
> SimpleITK 0.8.0.
> 
> Code:
> 
> import SimpleITK as sitk
> image = sitk.ReadImage('/path/to/img/cabg11-1.mha')
> image = sitk.Cast(sitk.RescaleIntensity(image), sitk.sitkFloat32)

You likely should convert to float before rescaling, and it would be best to explicitly specify the min and max. This will help preserve maximum fidelity of the intensity.

> scale = 2.0
> iscale = 1/scale;
> sz1,sp1,origin = image.GetSize(),image.GetSpacing(), image.GetOrigin()
> direction = image.GetDirection()
> sz2,sp2 = [int(n/scale) for n in sz1],[n*scale for n in sp1]
> print "Orig Size ", sz1, "\nNew Size ", sz2
> print "Orig Sp ", sp1, "\nNew Sp ", sp2
> print origin

BUG: you should also scale the origin.

> t = sitk.Transform(3, sitk.sitkScale)
> t.SetParameters((scale, scale, scale))
> simage =
> sitk.Resample(image,sz2,t,sitk.sitkLinear,origin,sp2,direction,0.0,sitk.sitkFloat32)

Python keyword arguments unfortunetly don't work with the overloaded Resample methods. I'd recommend using the object oriented interface here something like:

resampler = sitk.ResampleImageFilter()
resampler.SetDefaultPixelValue(0)
resampler.SetOutputSize(sz1)
resampler.SetTransform(t)
...
resampler.DebugOn()
resampler.Execute(image)

Turning Debug on will print the ITK filter before execution which may be helpful for debugging.

> print "New Image size:", simage.GetSize()
> mmap = sitk.Statistics(simage)
> for n in mmap.items():
>    print n
> print "\n",sitk.Version()
> 
> Output:
> Orig Size  (170, 170, 130) 
> New Size  [85, 85, 65]
> Orig Sp  (0.03867189958691597, 0.03867189958691597, 0.0625) 
> New Sp  [0.07734379917383194, 0.07734379917383194, 0.125]
> (-13.1871, 6.57422, -16.3125)
> New Image size: (85, 85, 65)
> ('Maximum', 0.0)
> ('Mean', 0.0)
> ('Minimum', 0.0)
> ('Sigma', 0.0)
> ('Sum', 0.0)
> ('Variance', 0.0)
> 
> SimpleITK Version: 0.8.0
> Compiled: Mar 14 2014 02:43:02
> 
> 
> 
> Am I missing a step here?

First try getting it to work with an scale = 1 so it will be an identity transform. Then increase it by just a little to see how the output image is effected. I hope it was just the origin not being correctly computed was the issue.

Brad

> 
> -Jameson
> 
> 
> 
> 
> --
> View this message in context: http://itk-users.7.n7.nabble.com/SimpleITK-Downsampling-results-in-blank-image-tp34923.html
> Sent from the ITK - Users mailing list archive at Nabble.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.com/mailman/listinfo/insight-users

_____________________________________
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


More information about the Community mailing list