[Insight-users] GetPixel problem
Roberto Laurita
roberto.laurita at gmail.com
Mon Feb 14 17:53:42 EST 2011
Hi all,
I tried to read a pixel value from dicom file.
It seems good. I made a txt file with the values and I imported in matlab.
The new image seems to be good but, paying attention to the values, I
discovered that the pixel value are different from value I can read directly
in matlab.
I verified also using a dicom viewer. The right values are the matlab ones.
Could you suggest the right way to read the Pixel? Thanks
Roberto
Here my code:
// MAIN FILE
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkGDCMImageIO.h"
#include "itkIndex.h"
#include <list>
#include <fstream>
#include <iostream>
int main( int argc, char* argv[] )
{
// Verify the number of parameters in the command line
if( argc < 2 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " OutputDicomImage ";
std::cerr << " OutputImage\n";
return EXIT_FAILURE;
}
//PixelType and InputDimension declarations
typedef signed short InputPixelType;
const unsigned int InputDimension = 2;
typedef itk::Image< InputPixelType, InputDimension > InputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
//reader creation and settings
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO( gdcmImageIO );
//reading process invocation
try
{
reader->Update();
}
catch (itk::ExceptionObject & e)
{
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
InputImageType::IndexType pixelIndex;
int i,j;
pixelIndex[0]=0;
pixelIndex[1]=0;
InputImageType::PixelType pixelValue, maxval;
maxval = 0;
//row and col numbers search
int rowN = 0;
int colN = 0;
std::string value;
std::string labelId;
std::string tagkey = "0028|0010";
//typedef itk::GDCMImageIO ImageIOType;
//ImageIOType::Pointer dicomIO = ImageIOType::New();
gdcmImageIO->SetMaxSizeLoadEntry(0xffff);
if( itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId ) )
{
std::cout << labelId << " (" << tagkey << "): ";
if( gdcmImageIO->GetValueFromTag(tagkey, value) )
{
std::cout << value;
rowN = atoi(value.c_str());
}
else
{
std::cout << "(No Value Found in File)";
}
std::cout << std::endl;
}
else
{
std::cerr << "Trying to access inexistant DICOM tag." << std::endl;
}
tagkey = "0028|0011";
if( itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId ) )
{
std::cout << labelId << " (" << tagkey << "): ";
if( gdcmImageIO->GetValueFromTag(tagkey, value) )
{
std::cout << value;
colN = atoi(value.c_str());
}
else
{
std::cout << "(No Value Found in File)";
}
std::cout << std::endl;
}
else
{
std::cerr << "Trying to access inexistant DICOM tag." << std::endl;
}
//output preparing
//std::cout << reader->GetOutput()->GetNameOfClass() << std::endl;
std::cout << "row -- col -- value" << std::endl;
for(i=0; i<rowN; i++){
pixelIndex[0]=i;
for(j=0; j<colN; j++){
pixelIndex[1]=j;
pixelValue = reader->GetOutput()->GetPixel(pixelIndex);
std::cout << i << " -- " << j << " -- " << pixelValue << std::endl;
if (pixelValue>maxval)
maxval = pixelValue;
}
}
std::cout << "Max Pixel Value: " << maxval << std::endl;
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110214/6adba3ba/attachment.htm>
More information about the Insight-users
mailing list