[Insight-users] problem reading dicom files
h h
hossein9876 at gmail.com
Sat Apr 5 19:47:11 EDT 2008
Hi,
I want to read a dicom file and copy the image data to a buffer using
iterators. This is the function i used:
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkGDCMImageIO.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"
void readdicomimage(char * input_file,unsigned short *imagedata)
{
typedef unsigned short InputPixelType;
const unsigned int InputDimension = 2;
typedef itk::Image< InputPixelType, InputDimension >
InputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(input_file);
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO(gdcmImageIO);
reader->Update();
typedef itk::ImageRegionConstIterator< InputImageType
> ConstIteratorType;
typedef itk::ImageRegionIterator< InputImageType>
IteratorType;
InputImageType::RegionType inputRegion;
InputImageType::RegionType::IndexType inputStart;
InputImageType::RegionType::SizeType size;
inputStart[0] = 0;
inputStart[1] = 0;
size[0] = 512;
size[1] = 512;
inputRegion.SetSize( size );
inputRegion.SetIndex( inputStart );
ConstIteratorType inputIt(reader->GetOutput(), inputRegion);
for ( inputIt.GoToBegin();
!inputIt.IsAtEnd();++inputIt,++imagedata)
{
*imagedata = inputIt.Get();
}
}
The above function takes 2 arguments, first is the input file and
second is a pointer to the buffer i want to copy the image data to.
Now the problem:
All the pixel data which the iterator returns are numbers which have
the following pattern :
0xFCnn eg. 0xFB45, 0xFBEA, 0XFB5C. As you can see the most significant
byte is constant (FC) and its value dosn't change.
What is wrong here?
p.s. Im using itk 3.2. Changing the input pixel type to signed short
dosn't help either.
here is a url to the image i am trying to read:
http://myfreefilehosting.com/f/b97bbaf518_0.27MB
the file name is "img57"
regards
hossein
More information about the Insight-users
mailing list