[Insight-users] (no subject)

marcellus walace marcelluswalace at hotmail . com
Wed, 20 Aug 2003 13:13:59 +0200


HI itkusers

I've just copied a code from itk userslist which calculate axial view from a 
stack of coronal dicom files.
There was an error. but that's not the problem. The problem is that I can't 
run it with my dicom files
.I can read them using an ordianry Metaimage header file  but when I try to 
write the "output.hdr"
the program seem to enter an infinte loop and never stops. Is it normal?
It's the writer which is the problem. When I remove the instruction 
"writer->Update();" all is right.
Can someone tells me what's wrong?

The code is:


typedef unsigned short InputPixelType;
typedef short OutputPixelType;
const unsigned int Dimension = 3;

typedef itk::Image<InputPixelType, Dimension> InputImageType;
typedef itk::Image<OutputPixelType, Dimension> OutputImageType;

typedef itk::ImageFileReader<InputImageType>  ReaderType;
typedef itk::ImageFileWriter<OutputImageType> WriterType;

typedef itk::BSplineInterpolateImageFunction<InputImageType, double>
  InterpolatorType;

typedef itk::AffineTransform<double, Dimension> TransformType;

typedef itk::ResampleImageFilter<InputImageType, OutputImageType>
FilterType;

// Initialize objects
ReaderType      ::Pointer reader       = ReaderType  ::New();
WriterType      ::Pointer writer       = WriterType  ::New();
InterpolatorType::Pointer interpolator = InterpolatorType ::New();
TransformType   ::Pointer transform    = TransformType ::New();
FilterType      ::Pointer filter       = FilterType  ::New();

// Set up interpolator
interpolator->SetSplineOrder(1);

// Set up rotation matrix for transform
TransformType::MatrixType matrix;
matrix[0][0] = 1; matrix[0][1] =  0; matrix[0][2] =  0;
matrix[1][0] = 0; matrix[1][1] =  0; matrix[1][2] = -1;
matrix[2][0] = 0; matrix[2][1] =  1; matrix[2][2] =  0;
transform->SetMatrix(matrix);

// Set output image size
OutputImageType::SizeType size;
size[0] = 256;
size[1] = 256;
size[2] = 256;

// Set output voxel size
double spacing[3];
spacing[0] = 1.0;
spacing[1] = 1.0;
spacing[2] = 1.0;

// Set new origin
double origin[3];
origin[0] = -38.7;
origin[1] = -25.9;
origin[2] = -50.1;

// Set up resample filter
filter->SetTransform(transform);
filter->SetInterpolator(interpolator);
filter->SetSize(size);
filter->SetOutputSpacing(spacing);
filter->SetOutputOrigin(origin);

reader->SetFileName("volume.mhd");

try {
reader->Update();
} catch( itk::ExceptionObject & exception )
    {
    std::cout << "Problems reading file format" << std::endl;
    std::cout << exception << std::endl;
    }
writer->SetFileName("output.hdr");

// Put it all together
filter->SetInput(reader->GetOutput());
writer->SetInput(filter->GetOutput());


try {
   writer->Update();
}
catch (itk::ExceptionObject& err) {
   cout << "Exception caught!" << endl;
   cout << err << endl;
   return -1;
}

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic . mcafee . com/clinic/ibuy/campaign . asp?cid=3963