Ohhh I didn't know that... I think I need to read and test more, more and more. I don't know how to do the print and the castings, I'm lost, I need to read, test and research more.<br><br><div class="gmail_quote">
On Thu, May 10, 2012 at 3:50 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</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 style="word-wrap:break-word"><div class="im">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><div><br><div><div class="im"><div>On May 10, 2012, at 3:28 PM, Ing. Arturo Vargas Olivares wrote:</div><br></div><div><div class="h5"><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: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><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><font color="#888888"><div class="gmail_quote"><br></div><div class="gmail_quote">Cagatay</div></font></span><div><div>
<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" 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>
</blockquote></div></div></div><br></div><br><br><div>
<span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;border-collapse:separate"><span style="font:12px/normal Helvetica;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;border-collapse:separate;font-size-adjust:none;font-stretch:normal"><div style="word-wrap:break-word">
<div><p style="margin:0px"><font style="font:12px/normal Helvetica;font-size-adjust:none;font-stretch:normal" size="3" face="Helvetica">========================================================</font></p><p style="margin:0px">
<font style="font:12px/normal Helvetica;font-size-adjust:none;font-stretch:normal" size="3" face="Helvetica">Bradley Lowekamp<span> </span><span> </span></font></p><p style="margin:0px"><font style="font:12px/normal Helvetica;font-size-adjust:none;font-stretch:normal" size="3" face="Helvetica">Medical Science and Computing for</font></p>
<p style="margin:0px"><font style="font:12px/normal Helvetica;font-size-adjust:none;font-stretch:normal" size="3" face="Helvetica">Office of High Performance Computing and Communications</font></p><p style="margin:0px"><font style="font:12px/normal Helvetica;font-size-adjust:none;font-stretch:normal" size="3" face="Helvetica">National Library of Medicine<span> </span></font></p>
<p style="margin:0px"><font style="font:12px/normal Helvetica;font-size-adjust:none;font-stretch:normal" size="3" face="Helvetica"><a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a></font></p>
</div></div></span></span>
</div>
<br></div></blockquote></div><br>