<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Bookman Old Style">hi,</FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV><FONT face="Bookman Old Style">You should call reader->Update() before
filter->SetOutputOrigin(reader->GetOutput()->GetOrigin());<BR></FONT></DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV><FONT face="Bookman Old Style"></FONT> </DIV>
<DIV>Hello,<BR> <BR> I am having problem in resampling an
image. The code is given below and appreciate if somebody help me
out:<BR> <BR> #if defined(_MSC_VER)<BR>#pragma warning (
disable : 4786 )<BR>#endif<BR> #include "itkImage.h"<BR>#include
"itkImageFileReader.h"<BR>#include "itkImageFileWriter.h"<BR>#include
"itkResampleImageFilter.h"<BR>#include "itkAffineTransform.h"<BR>#include
"itkNearestNeighborInterpolateImageFunction.h"<BR> <BR>int main( int argc,
char * argv[] )<BR>{<BR> if( argc < 3 )<BR>
{<BR> std::cerr << "Usage: " <<
std::endl;<BR> std::cerr << argv[0] << "
inputImageFile outputImageFile";<BR> std::cerr <<
std::endl;<BR> return EXIT_FAILURE;<BR>
}<BR> const unsigned int
Dimension = 3;<BR> typedef unsigned char
InputPixelType;<BR> typedef unsigned char
OutputPixelType;<BR> <BR> typedef itk::Image<
InputPixelType, Dimension > InputImageType;<BR>
typedef itk::Image< OutputPixelType, Dimension >
OutputImageType;<BR> <BR> typedef
itk::ImageFileReader< InputImageType > ReaderType;<BR>
typedef itk::ImageFileWriter< OutputImageType >
WriterType;<BR> <BR> ReaderType::Pointer reader =
ReaderType::New();<BR> WriterType::Pointer writer =
WriterType::New();<BR> <BR>
reader->SetFileName( argv[1] );<BR> writer->SetFileName( argv[2]
);<BR> <BR> typedef
itk::ResampleImageFilter<<BR>
InputImageType, OutputImageType > FilterType;<BR>
FilterType::Pointer filter = FilterType::New();<BR> <BR> typedef
itk::AffineTransform< double, Dimension > TransformType;<BR>
TransformType::Pointer transform = TransformType::New();<BR>
transform->SetIdentity();<BR> filter->SetTransform( transform
);<BR> <BR> typedef itk::NearestNeighborInterpolateImageFunction<
<BR>
InputImageType, double > InterpolatorType;<BR>
InterpolatorType::Pointer interpolator =
InterpolatorType::New();<BR> filter->SetInterpolator(
interpolator );<BR> <BR>
filter->SetOutputOrigin(reader->GetOutput()->GetOrigin());<BR> <BR>
double spacing[ Dimension ];<BR> spacing[0] = 0.5; // pixel spacing in
millimeters along X<BR> spacing[1] = 0.5; // pixel spacing in millimeters
along Y<BR> spacing[2] = 0.5; // pixel spacing in millimeters along
Z<BR> filter->SetOutputSpacing( spacing );<BR>
<BR> InputImageType::SizeType size;<BR>
size[0] = 80; // number of pixels along X<BR> size[1] = 128;
// number of pixels along Y<BR> size[2] = 128; // number of pixels
along Z<BR> filter->SetSize( size );<BR>
<BR> filter->SetInput( reader->GetOutput() );<BR>
writer->SetInput( filter->GetOutput() );<BR>
<BR> filter->SetDefaultPixelValue( 0 );<BR>
<BR> try <BR> { <BR>
writer->Update();<BR> } <BR> <BR> catch(
itk::ExceptionObject & err ) <BR> { <BR> std::cout
<< "ExceptionObject caught !" << std::endl; <BR>
std::cout << err << std::endl; <BR>
system("pause");<BR> return EXIT_FAILURE;<BR> }<BR>
<BR> return EXIT_SUCCESS;<BR>}<BR> <BR>
Thanks<BR>Shahab<BR></DIV></BODY></HTML>