[Insight-users] using DICOM image orientation information
Jolinda Smith
jolinda at darkwing . uoregon . edu
Mon, 12 May 2003 10:34:05 -0700
Hi Christof,
Recently I had some coronally-acquired images I wanted to view with the
same orientation & pixel spacing as some axially-acquired images. I
wrote a metaimage header for each volume I wanted to rotate & realign,
and ran following code. It worked quite well.
I left out some io details -- I actually wrote a file containing
filenames, output spacing, image size, and origin information for
several volumes, and put the relevant stuff in a loop. This was fine as
long as all my output images were the same size (that's the subject of
another post).
This example is for reslicing coronally-acquired images along the "z"
(axial) direction. For reslicing images taken with arbitrary
orientations, replace the first two rows of the rotation matrix with the
information in the "Image Orientation Patient" tag. You can calculate
the third row from the first two.
You have to make sure the "position" tag in the metaimage header is
correct. You can start with the "Image Position Patient" tag for your
first slice, but you need to rotate it into the correct frame. In this
example, that meant an IPP = -68/-42/85 was entered into the metaimage
header as a position of -68 -85 -42.
I hope this is enough to get you started.
Jolinda Smith
Lewis Center for NeuroImaging
University of Oregon
jolinda@uoregon.edu
#include <iostream>
#include <itkResampleImageFilter.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkAffineTransform.h>
#include <itkBSplineInterpolateImageFunction.h>
using namespace std;
int main(int argc, char* argv[])
{
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);
// Put it all together
filter->SetInput(reader->GetOutput());
writer->SetInput(filter->GetOutput());
reader->SetFileName("input.mhd");
writer->SetFileName("output.hdr");
try {
writer->Update();
}
catch (itk::ExceptionObject& err) {
cout << "Exception caught!" << endl;
cout << err << endl;
return -1;
}
return 0;
}
----- Original Message -----
From: "karmonik" <karmonik@bcm.tmc.edu>
To: <insight-users@public.kitware.com>
Sent: Friday, May 09, 2003 8:41 AM
Subject: [Insight-users] using DICOM image orientation information
> Hi,
>
> as far as I understand, the DICOM image format provides information
regarding
> image orientation (axial, sagittal, coronal, oblique, image
coordinates, image
> angle, ...).
>
> Quite frequently we acquire MR DICOM image sets (i.e. volumes) in one
session
> that each have different orientations.
>
> Is there a way using ITK, VTK, ... (?) to display these volumes on top
of each
> other correctly using the DICOM information regarding image
orientation?
> If not, wouldn't it be a good feature to have?
>
> Thanks !
>
> Christof
>
> Christof Karmonik, PhD
> Baylor College of Medicine/The Methodist Hospital
> Mailstation M214
> 6565 Fannin
> Houston, TX 77030
> Pager: (713) 708-2232
> Fax: (713) 790-6474
> Phone: (713) 394-6563
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>