[Insight-users] Bug in CastImageFIlter?

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Thu Feb 8 17:38:01 EST 2007


Hi,

Doing nothing doesn't require a specialization, just to add the method

   void ThreadedGenerateData(const typename  
Superclass::OutputImageRegionType& outputRegionForThread,
                             int threadId )
     {
     if( this->GetInPlace() && this->CanRunInPlace() )
       {
       // nothing to do, so avoid iterating over all the pixels
       // for nothing !
       return;
       }
     Superclass::ThreadedGenerateData( outputRegionForThread, threadId );
     }

in the protected section of the CastImageFilter class.
Return the input pointer is not enough if InPlace is set to false and the  
input and output types are the same, the CastImageFilter must copy the  
image.

Gaetan


Le Thu, 08 Feb 2007 22:35:20 +0100, Matthias Schabel  
<mschabel at ucair.med.utah.edu> a écrit:

> Taking a quick look at the code, it appears that there is not a do-
> nothing specialization for
> CastImageFilter in the case that the input and output image types are
> degenerate; this means
> that a bunch of unnecessary work gets done if you call
> CastImageFilter<short,short>, for
> example. Why, you ask, would you do something like that? Consider a
> generic class for
> reading in DICOM data and, possibly converting it to another type via
> casting:
>
> template<std::size_t R,typename T = short>
> class DicomData :
> 	public itk::Image<T,R>
> {
> 	public:
> 		DicomData(const std::vector<std::string>& filenames);
> };
>
> template<std::size_t R,typename T>
> DicomData<R,T>::DicomData(const std::vector<std::string>& filenames)
> {
> 	// use ImageSeriesReader to read DICOM data
>
> 	itk::Image<short,R>::Pointer	input_image_ptr = reader->GetOutput();
>
> 	typedef itk::CastImageFilter<itk::Image<short,R>,itk::Image<T,R> >	
> cast_image_filter_type;
> 	typedef typename cast_image_filter_type::Pointer				
> cast_image_filter_pointer_type;
> 	
> 	cast_image_filter_pointer_type	caster = cast_image_filter_type::New();
>
> 	caster->SetInput(input_image_ptr);
> 	
> 	try
> 	{
> 		// if T == short, this should do nothing, but it doesn't (do nothing)
> 		caster->Update();
> 	}
> 	catch (itk::ExceptionObject& e)
> 	{
> 		std::cerr << "exception in image series reader " << std::endl;
> 		std::cerr << e << std::endl;
> 		
> 		throw;
> 	}
> 	
> 	image_pointer_type::operator=(caster->GetOutput());
> }
>
> Really, all that is needed is a template specialization in
> CastImageFilter like this:
>
> template<class TImage>
> class CastImageFilter<TImage,TImage>
> {
> 	// don't do anything, just return the input pointer...
> }
>
> Is there some reason why this isn't done? Maybe I'm missing some
> subtlety that precludes this...
>
> Matthias



-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr


More information about the Insight-users mailing list