[Insight-users] Example of ITK

Bradley Lowekamp blowekamp at mail.nih.gov
Thu May 10 15:50:54 EDT 2012


Hello Arturo,

You can use the print function in Python to print the ITK information about the image. This will tell you that the image is being loaded as an itk::VectorImage, most likely of three components.

There is no obvious way to convert a VectorImage to a scalar image of float as you requested, which is why you are getting this error message. Additionally, as already noted the CurvatureFlow image filter expects a floating point image as input which is why are doing this cast.

So, why is the image getting loaded into a VectorImage, and not a scalar. That is because the ITK ImageIO is reporting the image has having multi-components. Even if the image looks grayscale it may have been saved as an RGB image.

I hope that helps explain what is going on. While SimpleITK is pixel type less, it is type aware and so there needs to be a certain level of understanding of the pixel types that are loaded, and some times casts need to be made.

Brad



On May 10, 2012, at 3:28 PM, Ing. Arturo Vargas Olivares wrote:

> Hello again.
>  
> I tried the command but I still have problems, it says it is not supported (see below).
>  
>  
> image = sitk.Cast( image, sitk.sitkFloat32 )
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (7489, 0))
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call last)
> C:\Users\Student3\Desktop\MRI images\<ipython-input-165-9a6139d5ca18> in <module>()
> ----> 1 image = sitk.Cast( image, sitk.sitkFloat32 )
> C:\Python27\lib\site-packages\simpleitk-0.4.0-py2.7-win-amd64.egg\SimpleITK.pyc in Cast(*args, **kwargs)
>    3597 def Cast(*args, **kwargs):
>    3598   """Cast(Image image, PixelIDValueType pixelID) -> Image"""
> -> 3599   return _SimpleITK.Cast(*args, **kwargs)
>    3600 class Version(_object):
>    3601     """Proxy of C++ itk::simple::Version class"""
> RuntimeError: Exception thrown in SimpleITK Cast: C:\Users\Bradley Lowekamp\Documents\Source\SimpleITK\Code\BasicFilters\src\sitkCastImageFilter.cxx:75:
> sitk::ERROR: Filter does not support casting from casting vector of 8-bit unsigned integer to 32-bit float
> 
> On Thu, May 10, 2012 at 3:13 PM, Cagatay Bilgin <bilgincc at gmail.com> wrote:
> Hi Arturo, 
> 
> 
> the following line should cast the image to float 
> image = sitk.Cast( image, sitk.sitkFloat32 )
> 
> Let us know how it goes 
> 
> Cagatay
> 
> On Thu, May 10, 2012 at 11:36 AM, Ing. Arturo Vargas Olivares <ing.arturo.vargas at gmail.com> wrote:
> I'm new in this...
> how do I cast my image to float?
> 
> 
>  
> On Thu, May 10, 2012 at 2:31 PM, Cagatay Bilgin <bilgincc at gmail.com> wrote:
> Try casting your image to float type before 
> you feed to the smoother. That should do it 
> I guess. 
> 
> Cagatay
> 
> On Thu, May 10, 2012 at 11:27 AM, Ing. Arturo Vargas Olivares <ing.arturo.vargas at gmail.com> wrote:
> Hello to all !!
>  
> I have implemented this code in order to test an example from the ITK software guide.
>  
> import numpy as np
> import scipy.io as ios
> import matplotlib.pyplot as mplot
> import matplotlib.cm as cm
> import SimpleITK as sitk
> import sys
> #
> # Read the image
> #
> reader = sitk.ImageFileReader()
> reader.SetFileName( 'BrainProtonDensitySlice.png' )
> image = reader.Execute();
> #
> # Set up the writer
> #
> writer = sitk.ImageFileWriter()
> writer.SetFileName( 'BrainProtonDensitySlice_out.png' )
> #
> # Blur using CurvatureFlowImageFilter
> #
> blurFilter = sitk.CurvatureFlowImageFilter()
> blurFilter.SetNumberOfIterations( 5 )
> blurFilter.SetTimeStep( 0.125 )
> image = blurFilter.Execute( image )
> #
> # Set up ConnectedImageFilter for segmentation
> #
> segmentationFilter = sitk.ConnectedThresholdImageFilter()
> segmentationFilter.SetLower(150)
> segmentationFilter.SetUpper(180)
> segmentationFilter.SetReplaceValue(255)
> segmentationFilter.SetSeed((60,116))
> image = segmentationFilter.Execute( image )
> writer.Execute( image )
>  
>  
> It seems that everything is OK except the execution of my filters (see below). It says that the Pixel Type is the problem but I don't know how to fix this.
>  
> Guys, do you have any ideas?
>  
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call last)
> C:\Users\Student3\Desktop\MRI images\test8.py in <module>()
>      22 blurFilter.SetNumberOfIterations( 5 )
>      23 blurFilter.SetTimeStep( 0.125 )
> ---> 24 image = blurFilter.Execute( image )
>      25 #
>      26 # Set up ConnectedImageFilter for segmentation
> 
> C:\Python27\lib\site-packages\simpleitk-0.4.0-py2.7-win-amd64.egg\SimpleITK.pyc in Execute(self, *args)
>    8050 
>    8051         """
> -> 8052         return _SimpleITK.CurvatureFlowImageFilter_Execute(self, *args)
>    8053 
>    8054     __swig_destroy__ = _SimpleITK.delete_CurvatureFlowImageFilter
> RuntimeError: Exception thrown in SimpleITK CurvatureFlowImageFilter_Execute: c:\users\bradley lowekamp\documents\source\simpleitk\code\common\include\sitkMemberFunctionFactory.txx:174:
> sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 2D byclass itk::simple::CurvatureFlowImageFilter
> 
> _____________________________________
> 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://www.itk.org/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://www.itk.org/mailman/listinfo/insight-users



========================================================
Bradley Lowekamp  
Medical Science and Computing for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120510/c55b6234/attachment-0001.htm>


More information about the Insight-users mailing list