[Insight-users] How to cast one image type to another?

Luis Ibanez luis . ibanez at kitware . com
Fri, 16 Aug 2002 09:45:43 -0400


Hi Zhao,

Please use the itkCastImageFilter:

http://www.itk.org/Insight/Doxygen/html/classitk_1_1CastImageFilter.html

Something like:

typedef itk::Image< float, 3 > ImageType1;
typedef itk::Image< unsigned long, 3 > ImageType2;

typedef itk::CastImageFilter< ImageType1, ImageType2 > FilterType;


Note that this filter does just C-Style casting !
It doesn't make any effort for rescaling the dynamic range of the
data.

If your Float image has negative values they will be badly
truncated (rewinded).

If you want to readjust the dynamic range of the pixels the
"RescaleIntensityImageFilter"  could be a better choice:

http://www.itk.org/Insight/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html

This filter will adjust the dynamic range (min,max) of the
input image to fit in a range specified by the user with the
methods:  SetOutputMinimum(), SetOutputMaximum().

Please let us know if you find any problem,

Thanks

Luis

====================================================

zhao wrote:
> Hi all,
> 
> 	Under MSVC6, I use output of a filter(CurvatureAnisotropicDiffusionImageFilter) as input of a image file writer:
> 	writer->SetInput(diffusion->GetOutput());
> 
> 	There is a compiling error:  	
> 	 error C2664: 'SetInput' : cannot convert parameter 1 from 'class itk::Image<float,2> *' to 'const class itk::Image<unsigned long,2> *
> 
>  	My question is how to convert one image type to another? Thanks!
> 
> Zhao
> 
> Zhao ChenGuang
> P.O.Box:010,
> Dept. BME,
> Shanghai Jiao Tong University,
> 1954# Hua Shan Road,
> Shanghai,P.R.China,
> 200030
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 
>