<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>&nbsp;</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>&nbsp;</div><div>&nbsp;</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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Traceback (most recent call last)<br>C:\Users\Student3\Desktop\MRI images\&lt;ipython-input-165-9a6139d5ca18&gt; in &lt;module&gt;()<br>
----&gt; 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>&nbsp;&nbsp; 3597 def Cast(*args, **kwargs):<br>&nbsp;&nbsp; 3598&nbsp;&nbsp; """Cast(Image image, PixelIDValueType pixelID) -&gt; Image"""<br>
-&gt; 3599&nbsp;&nbsp; return _SimpleITK.Cast(*args, **kwargs)<br>&nbsp;&nbsp; 3600 class Version(_object):<br>&nbsp;&nbsp; 3601&nbsp;&nbsp;&nbsp;&nbsp; """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">&lt;<a href="mailto:bilgincc@gmail.com" target="_blank">bilgincc@gmail.com</a>&gt;</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&nbsp;</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">&lt;<a href="mailto:ing.arturo.vargas@gmail.com" target="_blank">ing.arturo.vargas@gmail.com</a>&gt;</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>&nbsp;</div><div class="gmail_quote">On Thu, May 10, 2012 at 2:31 PM, Cagatay Bilgin <span dir="ltr">&lt;<a href="mailto:bilgincc@gmail.com" target="_blank">bilgincc@gmail.com</a>&gt;</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&nbsp;<div>you feed to the smoother. That should do it&nbsp;</div>


<div>I guess.&nbsp;</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">&lt;<a href="mailto:ing.arturo.vargas@gmail.com" target="_blank">ing.arturo.vargas@gmail.com</a>&gt;</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>&nbsp;</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>&nbsp;</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>&nbsp;</div><div>&nbsp;</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>&nbsp;</div><div><font color="#000066" size="4">Guys, do you have any ideas? </font></div><div><font color="#000066" size="4"></font>&nbsp;</div><div>---------------------------------------------------------------------------<br>




RuntimeError&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Traceback (most recent call last)<br>C:\Users\Student3\Desktop\MRI images\test8.py in &lt;module&gt;()<br>&nbsp;&nbsp;&nbsp;&nbsp; 22 blurFilter.SetNumberOfIterations( 5 )<br>&nbsp;&nbsp;&nbsp;&nbsp; 23 blurFilter.SetTimeStep( 0.125 )<br>




---&gt; 24 image = blurFilter.Execute( image )<br>&nbsp;&nbsp;&nbsp;&nbsp; 25 #</div><div>&nbsp;&nbsp;&nbsp;&nbsp; 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>




&nbsp;&nbsp; 8050 <br>&nbsp;&nbsp; 8051&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; """<br>-&gt; 8052&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _SimpleITK.CurvatureFlowImageFilter_Execute(self, *args)<br>&nbsp;&nbsp; 8053 <br>&nbsp;&nbsp; 8054&nbsp;&nbsp;&nbsp;&nbsp; __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><a href="http://www.kitware.com/products/protraining.php">http://www.kitware.com/products/protraining.php</a><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><br><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">========================================================</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Bradley Lowekamp<span class="Apple-converted-space">&nbsp;</span><span class="Apple-converted-space">&nbsp;</span></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Medical Science and Computing for</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Office of High Performance Computing and Communications</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">National Library of Medicine<span class="Apple-converted-space">&nbsp;</span></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; "><a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></p></div></div></span></span>
</div>
<br></body></html>