<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello Arturo,<div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Brad</div><div><br></div><div><br></div><div><br><div><div>On May 10, 2012, at 3:28 PM, Ing. Arturo Vargas Olivares wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><font color="#000066" size="4">Hello again.</font></div><div><font color="#000066" size="4"></font> </div><div><font color="#000066" size="4">I tried the command but I still have problems, it says it is not supported (see below).</font></div>
<div> </div><div> </div><div>image = sitk.Cast( image, sitk.sitkFloat32 )<br>ERROR: An unexpected error occurred while tokenizing input<br>The following traceback may be corrupted or invalid<br>The error message is: ('EOF in multi-line statement', (7489, 0))<br>
---------------------------------------------------------------------------<br>RuntimeError Traceback (most recent call last)<br>C:\Users\Student3\Desktop\MRI images\<ipython-input-165-9a6139d5ca18> in <module>()<br>
----> 1 image = sitk.Cast( image, sitk.sitkFloat32 )</div><div>C:\Python27\lib\site-packages\simpleitk-0.4.0-py2.7-win-amd64.egg\SimpleITK.pyc in Cast(*args, **kwargs)<br> 3597 def Cast(*args, **kwargs):<br> 3598 """Cast(Image image, PixelIDValueType pixelID) -> Image"""<br>
-> 3599 return _SimpleITK.Cast(*args, **kwargs)<br> 3600 class Version(_object):<br> 3601 """Proxy of C++ itk::simple::Version class"""</div><div>RuntimeError: Exception thrown in SimpleITK Cast: C:\Users\Bradley Lowekamp\Documents\Source\SimpleITK\Code\BasicFilters\src\sitkCastImageFilter.cxx:75:<br>
sitk::ERROR: Filter does not support casting from casting vector of 8-bit unsigned integer to 32-bit float<br><br></div><div class="gmail_quote">On Thu, May 10, 2012 at 3:13 PM, Cagatay Bilgin <span dir="ltr"><<a href="mailto:bilgincc@gmail.com" target="_blank">bilgincc@gmail.com</a>></span> wrote:<br>
<blockquote style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid; position: static; z-index: auto; " class="gmail_quote"><div><span style="line-height:15px;font-family:monospace,fixed;font-size:12px;white-space:pre-wrap;background-color:rgb(251,252,253)">Hi Arturo, </span></div>
<div><span style="line-height:15px;font-family:monospace,fixed;font-size:12px;white-space:pre-wrap;background-color:rgb(251,252,253)"><br>
</span></div><div><span style="line-height:15px;font-family:monospace,fixed;font-size:12px;white-space:pre-wrap;background-color:rgb(251,252,253)">the following line should cast the image to float </span></div>
<span style="line-height:15px;font-family:monospace,fixed;font-size:12px;white-space:pre-wrap;background-color:rgb(251,252,253)">image = sitk.Cast( image, sitk.sitkFloat32 )</span><br><div class="gmail_quote">
<br></div><div class="gmail_quote">Let us know how it goes </div><span class="HOEnZb"><font color="#888888"><div class="gmail_quote"><br></div><div class="gmail_quote">Cagatay</div></font></span><div class="HOEnZb"><div class="h5">
<div class="gmail_quote"><br></div><div class="gmail_quote">On Thu, May 10, 2012 at 11:36 AM, Ing. Arturo Vargas Olivares <span dir="ltr"><<a href="mailto:ing.arturo.vargas@gmail.com" target="_blank">ing.arturo.vargas@gmail.com</a>></span> wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote"><div>I'm new in this...</div><div>how do I cast my image to float?</div>
<div><div><div><br>
<br> </div><div class="gmail_quote">On Thu, May 10, 2012 at 2:31 PM, Cagatay Bilgin <span dir="ltr"><<a href="mailto:bilgincc@gmail.com" target="_blank">bilgincc@gmail.com</a>></span> wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">Try casting your image to float type before <div>you feed to the smoother. That should do it </div>
<div>I guess. </div><div><br></div><div>Cagatay<br><br><div class="gmail_quote"><div><div>On Thu, May 10, 2012 at 11:27 AM, Ing. Arturo Vargas Olivares <span dir="ltr"><<a href="mailto:ing.arturo.vargas@gmail.com" target="_blank">ing.arturo.vargas@gmail.com</a>></span> wrote:<br>
</div></div><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote"><div><div><div><font color="#000066" size="4">Hello to all !!</font></div>
<div><font color="#000066" size="4"></font> </div><div>
<font color="#000066" size="4">I have implemented this code in order to test an example from the ITK software guide.</font></div>
<div> </div><div>import numpy as np<br>import <a href="http://scipy.io/" target="_blank">scipy.io</a> as ios<br>import matplotlib.pyplot as mplot<br>import <a href="http://matplotlib.cm/" target="_blank">matplotlib.cm</a> as cm<br>
import SimpleITK as sitk<br>
import sys<br>#<br># Read the image<br>#<br>reader = sitk.ImageFileReader()<br>reader.SetFileName( 'BrainProtonDensitySlice.png' )<br>image = reader.Execute();<br>#<br># Set up the writer<br>#<br>writer = sitk.ImageFileWriter()<br>
writer.SetFileName( 'BrainProtonDensitySlice_out.png' )<br>#<br># Blur using CurvatureFlowImageFilter<br>#<br>blurFilter = sitk.CurvatureFlowImageFilter()<br>blurFilter.SetNumberOfIterations( 5 )<br>blurFilter.SetTimeStep( 0.125 )<br>
image = blurFilter.Execute( image )<br>#<br># Set up ConnectedImageFilter for segmentation<br>#<br>segmentationFilter = sitk.ConnectedThresholdImageFilter()<br>segmentationFilter.SetLower(150)<br>segmentationFilter.SetUpper(180)<br>
segmentationFilter.SetReplaceValue(255)<br>segmentationFilter.SetSeed((60,116))<br>image = segmentationFilter.Execute( image )<br>writer.Execute( image )<br> </div><div> </div><div><font color="#000066" size="4">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.</font></div>
<div> </div><div><font color="#000066" size="4">Guys, do you have any ideas? </font></div><div><font color="#000066" size="4"></font> </div><div>---------------------------------------------------------------------------<br>
RuntimeError Traceback (most recent call last)<br>C:\Users\Student3\Desktop\MRI images\test8.py in <module>()<br> 22 blurFilter.SetNumberOfIterations( 5 )<br> 23 blurFilter.SetTimeStep( 0.125 )<br>
---> 24 image = blurFilter.Execute( image )<br> 25 #</div><div> 26 # Set up ConnectedImageFilter for segmentation</div><div><br>C:\Python27\lib\site-packages\simpleitk-0.4.0-py2.7-win-amd64.egg\SimpleITK.pyc in Execute(self, *args)<br>
8050 <br> 8051 """<br>-> 8052 return _SimpleITK.CurvatureFlowImageFilter_Execute(self, *args)<br> 8053 <br> 8054 __swig_destroy__ = _SimpleITK.delete_CurvatureFlowImageFilter</div>
<div>RuntimeError: Exception thrown in SimpleITK CurvatureFlowImageFilter_Execute: c:\users\bradley lowekamp\documents\source\simpleitk\code\common\include\sitkMemberFunctionFactory.txx:174:<br>sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 2D byclass itk::simple::CurvatureFlowImageFilter</div>
<br></div></div>_____________________________________<br>
Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>
_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>