<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello Brandon,<div><br></div><div>As is frequently the case the first exception is the cause of the remainder. To understand the first error message some explanation of the how SimpleITK manages image types is needed.</div><div><br></div><div>There may be some relevant information in the SimpleITK presentation from MICCAI 2011:</div><div><a href="https://github.com/SimpleITK/SimpleITK-MICCAI-2011-Tutorial/blob/master/Presentation/SimpleITK-MICCAI-2011.pdf?raw=true">https://github.com/SimpleITK/SimpleITK-MICCAI-2011-Tutorial/blob/master/Presentation/SimpleITK-MICCAI-2011.pdf?raw=true</a></div><div><br></div><div><br></div><div>The sitk::Image class is a typeless image class which wraps numerous ITK image types. Externally the sitk::Image class presents the same interface for all images, wether it is a scalar itk::Image, a multicomponent itk::VectorImage, or even a run-line compressed itk::LabelMap. And then each of these ITK image types are templated over the dimension and the pixel type. So SimpleITK presents dozens of itk images types through a single sitk::Image object.&nbsp;</div><div><br></div><div>So SimpelITK is not strongly typed on these individual image types, but it is type aware.</div><div><br></div><div>ITK &nbsp;filters are also templated on the input, and output image types. But SimpleITK again type not expose the details of all the templated types, and instead just exposes a generic interface to the image filter, and internally is instantiates the image filter with all the plausible input image types, and the sensible corresponding output image types.&nbsp;</div><div><br></div><div>There are a few methods which can be used to interrogate the image after it's loaded:</div><div><br></div><div>First there is the ToString member function which just dumps out &nbsp;bunch of information about the internal ITK object:</div><div><br></div><div>&gt;cat( Image_ToString( myimage ) )</div><div><br></div><div>And more specific methods:</div><div><br></div><div>&gt; Image_GetDimension( myimage )</div><div><div>&gt; Image_GetPixelIDTypeAsString( myimage )</div><div>&gt; Image_GetPixelIDValue( myimage )</div><div><br></div></div><div>So lets look at what happens with the image you have chosen to run this script with</div><div><br></div><div><div><div>On Jan 1, 2012, at 9:03 AM, Brandon Whitcher wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Brad,<br><br>I have attempted to run SimpleGaussian.R in an interactive R session by executing<br><br></blockquote><blockquote type="cite">
<br>using the "spine1.png" image (attached, along with load.R).<br></blockquote><div><br></div><div>The data used for the tests can be found in the {SIMPLEITK_SOURCE}/Testing/Data.</div><br><blockquote type="cite"><br>The code fails to produce a smoothed image, here is the output<br><br><span style="font-family:courier new,monospace">&gt; source("load.R") # library(SimpleITK)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; args &lt;- c("spine1.png", 5, "spine1_smooth.png") # commandArgs(TRUE)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; myreader &lt;- ImageFileReader()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; myreader &lt;- ImageFileReader_SetFileName(myreader, args[[1]])</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; myimage &lt;- ImageFileReader_Execute(myreader)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; </span><br style="font-family:courier new,monospace"></blockquote><div><br></div><div><div>if you run:</div><div><div>&gt;cat( Image_ToString( myimage ) )</div><div><br></div><div>You should see the following line:</div><div><br></div><div>RTTI typeinfo: &nbsp; itk::VectorImage&lt; unsigned char, 2u&gt;</div><div><br></div><div>Or if you run:</div><div><br></div><div>&gt; Image_GetPixelIDTypeAsString( myimage )</div><div>[1] "vector of 8-bit unsigned integer"</div><div><br></div><div>So with either of these methods you see that this file is not a black and white image that it first appears, but actually a RGB image loaded into an Itk::VectorImage</div></div></div><br><blockquote type="cite"><span style="font-family:courier new,monospace">&gt; pixeltype &lt;- Image_GetPixelIDValue(myimage)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; myfilter &lt;- SmoothingRecursiveGaussianImageFilter()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; myfilter &lt;- SmoothingRecursiveGaussianImageFilter_SetSigma(myfilter, as.double(args[2]))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; smoothedimage &lt;- SmoothingRecursiveGaussianImageFilter_Execute(myfilter, myimage)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Warning message:</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">In f(...) :</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&nbsp; Exception thrown in SimpleITK SmoothingRecursiveGaussianImageFilter_Execute: /srv/SimpleITK/Code/Common/include/sitkMemberFunctionFactory.txx:173:</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 2D byN3itk6simple37SmoothingRecursiveGaussianImageFilterE</span><br style="font-family:courier new,monospace"></blockquote><div><br></div><div>While this error message could use improvement &nbsp;( and will be improved ). It basically says that this filter doesn't work with this particular image type &nbsp;( it should also list the types of images it does work with ). This particular filter currently only works with scalar image type. So this image with sitkVectorUInt8 pixels is not going to work.&nbsp;</div><div><br></div><div><br></div><br><blockquote type="cite">
<span style="font-family:courier new,monospace">&gt; </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; mycaster &lt;- CastImageFilter()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; mycaster &lt;- CastImageFilter_SetOutputPixelType(mycaster, pixeltype)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; castedimage &lt;- CastImageFilter_Execute(mycaster, soothedimage)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Error in CastImageFilter_Execute(mycaster, soothedimage) : </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&nbsp; object 'soothedimage' not found</span><br style="font-family:courier new,monospace"></blockquote><div><br></div><div>There appears to be a typeo "soothedimage" should be "smoothedimage". However, I think the same error message should be generated because the smoothedimage was not assigned due to the previous exception.</div><br><blockquote type="cite">
<span style="font-family:courier new,monospace">&gt; </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; mywriter &lt;- ImageFileWriter()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">&gt; mywriter &lt;- ImageFileWriter_SetFileName(mywriter, args[[3]])</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&gt; mywriter &lt;- ImageFileWriter_Execute(mywriter, castedimage)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Error in ImageFileWriter_Execute(mywriter, castedimage) : </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">&nbsp; object 'castedimage' not found</span><br>
<br>I am not sure what to make of the warnings or errors (sorry).&nbsp; Any advice or modifications would be helpful.&nbsp; I am using spine1.png since I cannot locate STAPLE1.png in either the ITK or SimpleITK directories.<br><br></blockquote><div><br></div><div>Using the functional interface the following may be simpler:</div><div><br></div><div>img &lt;- ReadImage( "/src/SimpleITK/Testing/Data/Input/cthead1.png" )</div><div>pid &lt;- Image_GetPixelIDValue( img )</div><div>simg &lt;- SmoothingRecursiveGaussian( img, 4 )</div><div>cimg &lt;- Cast( simg, pid )</div><div>WriteImage( cimg, "out.png" )</div><div><br></div><div>Good luck,</div><div>Brad</div><br><blockquote type="cite">
thanks,<br><br>Brandon<br><br><br><div class="gmail_quote">On 31 December 2011 18:34, Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
<div style="word-wrap:break-word">Hello again,<div><br></div><div>I was not able to get the R packaging to work as described in the link provided. I did find a manual way to load the SimpleITK R library.</div><div><br></div>
<div>Copy the SimpleITK.R file and the libSimpleITK.so ( renamed to SimpleITK.so ) into your current path, such as with the following commands:</div><div><br></div><div><div>cp SimpleITK/SimpleITK-build/Wrapping/SimpleITK.R</div>
<div>cp SimpleITK/SimpleITK-build/Wrapping/SimpleITK.R ./</div></div><div><br></div><div><br></div><div>The fire up R and type:</div><div><br></div><div><div>$ R</div><div><br></div><div>R version 2.14.0 (2011-10-31)</div>
<div>...</div><div><br></div><div>&gt; dyn.load( paste("SimpleITK", .Platform$dynlib.ext, sep="" ))</div><div>&gt; source ( "SimpleITK.R" )</div><div>Creating a generic function for ‘print’ from package ‘base’ in the global environment</div>
<div>&gt; cacheMetaData( 1 )</div></div><div><br></div><div>Here is an example that was working at one point:</div><div><br></div><div><a href="http://www.itk.org/SimpleITKDoxygen/html/SimpleGaussian_8R-example.html" target="_blank">http://www.itk.org/SimpleITKDoxygen/html/SimpleGaussian_8R-example.html</a></div>
<div><br></div><div>However the "library( SimpleITK )" call is used for when SimpleITK is installed as a package not the adhoc approach used above.</div><div><br></div><div>Good Luck,</div><div>Brad</div><div><div class="h5">
<div><br><div><div>On Dec 31, 2011, at 1:11 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] wrote:</div><br><blockquote type="cite"><div style="word-wrap:break-word">Hello Brandon,<div><br></div><div>The particular files you looking for are in the SimpleITK source directory not the build. You will need both the DESCRIPTION and the zzz.R files from the {SIMPLEITK_SOURCE}/Wrapping/R_Package directory.</div>
<div><br></div><div>We have been calling R a Tier 2 or Tier 3 language in SimpleITK because is not as well supported as the other wrapped languages such as Python, Java, CSharp or even Ruby, or TCL. The primary reason for this is that we have not gotten the automatic testing working for R, so that it will show up on the nightly dashboard. Additionally, we also are hoping for contribution from the community to get the R language specific features polished and up to the expected R standard conventions.</div>
<div><br></div><div>I hope this helps you with getting SimpleITK working R,</div><div><br></div><div>Brad</div><div><br><div>
<div style="word-wrap:break-word;font-size:12px"><div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font style="font:normal normal normal 12px/normal Helvetica" face="Helvetica" size="3">========================================================</font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font style="font:normal normal normal 12px/normal Helvetica" face="Helvetica" size="3">Bradley Lowekamp<span>&nbsp;</span><span>&nbsp;</span></font></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font style="font:normal normal normal 12px/normal Helvetica" face="Helvetica" size="3">Medical Science and Computing for</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font style="font:normal normal normal 12px/normal Helvetica" face="Helvetica" size="3">Office of High Performance Computing and Communications</font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font style="font:normal normal normal 12px/normal Helvetica" face="Helvetica" size="3">National Library of Medicine<span>&nbsp;</span></font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<font style="font:normal normal normal 12px/normal Helvetica" face="Helvetica" size="3"><a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a></font></div></div></div>
</div>
<br><div><div>On Dec 31, 2011, at 9:28 AM, Brandon Whitcher wrote:</div><br><blockquote type="cite">Dear ITK/SimpleITK experts,<br><br>I have installed SimpleITK by turning off all wrapping facilities except WRAP_R.&nbsp; I am now following the instructions in<br>
<br><div style="margin-left:40px"><a href="http://www.itk.org/SimpleITKDoxygen/html/Wrapping.html" target="_blank">http://www.itk.org/SimpleITKDoxygen/html/Wrapping.html</a><br>
</div><br>Specifically, <br><br><ul><li>6) Copy the file</li></ul>
<div><pre>       SimpleITK/Wrapping/R_Package/DESCRIPTION
</pre></div><p> into the current</p>
<div><pre>       SimpleITK/DESCRIPTION
</pre></div>...but I cannot find the file Wrapping/R_package/DESCRIPTION in my SimpleITK-binary installation.&nbsp; Where is this file?<br><br>thank-you,<br><br>Brandon<br><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.html" target="_blank">http://www.kitware.com/products/protraining.html</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><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.html" target="_blank">http://www.kitware.com/products/protraining.html</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><br></div></div></div></div></blockquote></div><br>
<span>&lt;spine1.png&gt;</span><span>&lt;load.R&gt;</span></blockquote></div><br></div></body></html>