<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>As I mentioned at the TCON, I need to get the GradientImageFilter into SimpleITK. The problem is that the output of this filter is strongly typed to be an Image of CovariantVectors and SimpleITK deal will all multi-component images as the more flexible VectorImages. Not the buffer image buffer is really exactly the same for the two type, just a bunch of floats, but the levels abstraction and C++ I don't believe really guarantees this as one is a pointer to floats for the VectorImages, while the other is an array of CovariantVector object. The reason that we can't just make the filter work with VectorImages is because how it's templated:</div><div><br></div><div><div>template&lt; class TInputImage, class TOperatorValueType = float, class TOutputValueType = float &gt;</div><div>class ITK_EXPORT GradientImageFilter:</div><div>&nbsp; public ImageToImageFilter&lt; TInputImage,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Image&lt; CovariantVector&lt; TOutputValueType,</div><div>&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;::itk::GetImageDimension&lt; TInputImage &gt;::ImageDimension &gt;,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ::itk::GetImageDimension&lt; TInputImage &gt;::ImageDimension &gt; &gt;</div></div><div><br></div><div>There is just no way to specify the output image type, I suppose I could add a 4th template parameter.</div><div><br></div><div>I am looking for other suggestions on how to adapt this class's output for SimpleITK, or other wise safely convert the output.&nbsp;</div><div><br></div><div>I was able to come up with the following efficient, and horrendous hack, but I don't think I can bare to actually commit it:</div><div><br></div><div><div><br></div><div>template&lt; typename TPixelType, unsigned int ImageDimension &gt;</div><div>typename itk::VectorImage&lt; TPixelType, ImageDimension &gt;::Pointer</div><div>GetVectorImage( itk::Image&lt; itk::CovariantVector&lt; TPixelType, ImageDimension &gt;, ImageDimension&gt; *img )</div><div>{</div><div>&nbsp; typedef itk::Image&lt; itk::CovariantVector&lt; TPixelType, ImageDimension &gt;, ImageDimension&gt; ImageType;</div><div>&nbsp; typedef itk::VectorImage&lt; TPixelType, ImageDimension &gt; VectorImageType;</div><div><br></div><div><br></div><div>&nbsp; SizeValueType numberOfElements = img-&gt;GetBufferedRegion().GetNumberOfPixels();</div><div>&nbsp; img-&gt;GetPixelContainer()-&gt;SetImportPointer( img-&gt;GetPixelContainer()-&gt;GetBufferPointer(), numberOfElements, false );</div><div><br></div><div><br></div><div>&nbsp; // It appears that the Covararient vector neither is POD nor does it</div><div>&nbsp; // have a trivial copy constructor. So this really is a hack and</div><div>&nbsp; // guaranteed to work.</div><div>&nbsp; //sitkStaticAssert( std::tr1::has_trivial_copy&lt;typename ImageType::PixelType&gt;::value, "Assumption on CovarientVector violated!" ;)</div><div>&nbsp; //sitkStaticAssert( std::tr1::is_pod&lt;typename ImageType::PixelType&gt;::value, "Assumption on CovarientVector violated!" ;)</div><div><br></div><div>&nbsp; typename VectorImageType::InternalPixelType* buffer</div><div>&nbsp; &nbsp; = reinterpret_cast&lt;typename VectorImageType::InternalPixelType*&gt;( img-&gt;GetPixelContainer()-&gt;GetBufferPointer() );</div><div><br></div><div>&nbsp; // Unlike an image of CovarientVector a VectorImage's container is a</div><div>&nbsp; // container of TPixelType, whos size is the image's number of</div><div>&nbsp; // pixels * number of pixels per component</div><div>&nbsp; numberOfElements *= ImageDimension;</div><div><br></div><div>&nbsp; typename VectorImageType::Pointer out = VectorImageType::New();</div><div><br></div><div>&nbsp; // Set the image's pixel container to import the pointer provided.</div><div>&nbsp; out-&gt;GetPixelContainer()-&gt;SetImportPointer(buffer, numberOfElements, true );</div><div>&nbsp; out-&gt;CopyInformation( img );</div><div>&nbsp; out-&gt;SetRegions( img-&gt;GetBufferedRegion() );</div><div><br></div><div>&nbsp; return out;</div><div>}</div></div><div><br></div><div>Thanks for your suggestions</div><div><br></div><div>Brad</div><div><br><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-size: 12px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; 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; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><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><br class="Apple-interchange-newline"></span></div><br class="Apple-interchange-newline">
</div>
<br></div></body></html>