<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< class TInputImage, class TOperatorValueType = float, class TOutputValueType = float ></div><div>class ITK_EXPORT GradientImageFilter:</div><div> public ImageToImageFilter< TInputImage,</div><div> Image< CovariantVector< TOutputValueType,</div><div> ::itk::GetImageDimension< TInputImage >::ImageDimension >,</div><div> ::itk::GetImageDimension< TInputImage >::ImageDimension > ></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. </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< typename TPixelType, unsigned int ImageDimension ></div><div>typename itk::VectorImage< TPixelType, ImageDimension >::Pointer</div><div>GetVectorImage( itk::Image< itk::CovariantVector< TPixelType, ImageDimension >, ImageDimension> *img )</div><div>{</div><div> typedef itk::Image< itk::CovariantVector< TPixelType, ImageDimension >, ImageDimension> ImageType;</div><div> typedef itk::VectorImage< TPixelType, ImageDimension > VectorImageType;</div><div><br></div><div><br></div><div> SizeValueType numberOfElements = img->GetBufferedRegion().GetNumberOfPixels();</div><div> img->GetPixelContainer()->SetImportPointer( img->GetPixelContainer()->GetBufferPointer(), numberOfElements, false );</div><div><br></div><div><br></div><div> // It appears that the Covararient vector neither is POD nor does it</div><div> // have a trivial copy constructor. So this really is a hack and</div><div> // guaranteed to work.</div><div> //sitkStaticAssert( std::tr1::has_trivial_copy<typename ImageType::PixelType>::value, "Assumption on CovarientVector violated!" ;)</div><div> //sitkStaticAssert( std::tr1::is_pod<typename ImageType::PixelType>::value, "Assumption on CovarientVector violated!" ;)</div><div><br></div><div> typename VectorImageType::InternalPixelType* buffer</div><div> = reinterpret_cast<typename VectorImageType::InternalPixelType*>( img->GetPixelContainer()->GetBufferPointer() );</div><div><br></div><div> // Unlike an image of CovarientVector a VectorImage's container is a</div><div> // container of TPixelType, whos size is the image's number of</div><div> // pixels * number of pixels per component</div><div> numberOfElements *= ImageDimension;</div><div><br></div><div> typename VectorImageType::Pointer out = VectorImageType::New();</div><div><br></div><div> // Set the image's pixel container to import the pointer provided.</div><div> out->GetPixelContainer()->SetImportPointer(buffer, numberOfElements, true );</div><div> out->CopyInformation( img );</div><div> out->SetRegions( img->GetBufferedRegion() );</div><div><br></div><div> 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"> </span><span class="Apple-converted-space"> </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"> </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>