[Insight-users] problem reading dicom files
Luis Ibanez
luis.ibanez at kitware.com
Sun Apr 6 17:29:48 EDT 2008
Hi h h,
Please try the following:
a) just after calling reader->Update(), add the following lines:
InputImageType::ConstPointer inputImage = reader->GetOutput();
inputImage->Print( std::cout );
and post to the list the output with the details of the image.
b) instead of building the region by yourself, get the region
from the image itself, like:
InputImageType::RegionType inputRegion =
inputImage->GetBufferedRegion();
ConstIteratorType inputIt(reader->GetOutput(), inputRegion);
Regards,
Luis
-------------
h h wrote:
> 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
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list