<div>Hi all,<br></div><div><br></div><div>I tried to read a pixel value from dicom file.</div><div><br></div><div>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.</div>
<div><br></div><div>I verified also using a dicom viewer. The right values are the matlab ones.</div><div><br></div><div>Could you suggest the right way to read the Pixel? Thanks</div><div><br></div><div>Roberto</div><div>
<br></div><div>Here my code:</div><div><br></div><div>// MAIN FILE<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkRescaleIntensityImageFilter.h"<br>#include "itkGDCMImageIO.h"<br>
#include "itkIndex.h"<br>#include <list><br>#include <fstream><br>#include <iostream><br><br><br>int main( int argc, char* argv[] )<br>{<br><br> // Verify the number of parameters in the command line<br>
if( argc < 2 )<br> {<br> std::cerr << "Usage: " << std::endl;<br> std::cerr << argv[0] << " OutputDicomImage ";<br> std::cerr << " OutputImage\n";<br>
return EXIT_FAILURE;<br> }<br><br> //PixelType and InputDimension declarations<br> typedef signed short InputPixelType;<br> const unsigned int InputDimension = 2;<br> typedef itk::Image< InputPixelType, InputDimension > InputImageType;<br>
typedef itk::ImageFileReader< InputImageType > ReaderType;<br><br> //reader creation and settings<br> ReaderType::Pointer reader = ReaderType::New();<br> reader->SetFileName( argv[1] );<br> typedef itk::GDCMImageIO ImageIOType;<br>
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();<br> reader->SetImageIO( gdcmImageIO );<br><br> //reading process invocation<br> try<br> {<br> reader->Update();<br> }<br> catch (itk::ExceptionObject & e)<br>
{<br> std::cerr << "exception in file reader " << std::endl;<br> std::cerr << e << std::endl;<br> return EXIT_FAILURE;<br> }<br><br><br><br> InputImageType::IndexType pixelIndex;<br>
int i,j;<br> pixelIndex[0]=0;<br> pixelIndex[1]=0;<br> InputImageType::PixelType pixelValue, maxval;<br> maxval = 0;<br><br> //row and col numbers search<br> int rowN = 0;<br> int colN = 0;<br> std::string value;<br>
std::string labelId;<br> std::string tagkey = "0028|0010";<br><br> //typedef itk::GDCMImageIO ImageIOType;<br> //ImageIOType::Pointer dicomIO = ImageIOType::New();<br> gdcmImageIO->SetMaxSizeLoadEntry(0xffff);<br>
<br> if( itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId ) )<br> {<br>        std::cout << labelId << " (" << tagkey << "): ";<br> if( gdcmImageIO->GetValueFromTag(tagkey, value) )<br>
{<br> std::cout << value;<br> rowN = atoi(value.c_str());<br> }<br> else<br> {<br> std::cout << "(No Value Found in File)";<br> }<br> std::cout << std::endl;<br>
}<br> else<br> {<br> std::cerr << "Trying to access inexistant DICOM tag." << std::endl;<br> }<br><br> tagkey = "0028|0011";<br> if( itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId ) )<br>
{<br>         std::cout << labelId << " (" << tagkey << "): ";<br> if( gdcmImageIO->GetValueFromTag(tagkey, value) )<br> {<br> std::cout << value;<br> colN = atoi(value.c_str());<br>
}<br> else<br> {<br> std::cout << "(No Value Found in File)";<br> }<br> std::cout << std::endl;<br> }<br> else<br> {<br> std::cerr << "Trying to access inexistant DICOM tag." << std::endl;<br>
}<br><br><br> //output preparing<br> //std::cout << reader->GetOutput()->GetNameOfClass() << std::endl;<br> std::cout << "row -- col -- value" << std::endl;<br><br><br> for(i=0; i<rowN; i++){<br>
         pixelIndex[0]=i;<br>         for(j=0; j<colN; j++){<br>                 pixelIndex[1]=j;<br>                 pixelValue = reader->GetOutput()->GetPixel(pixelIndex);<br>                 std::cout << i << " -- " << j << " -- " << pixelValue << std::endl;<br>
                 if (pixelValue>maxval)<br>                         maxval = pixelValue;<br>         }<br><br> }<br> std::cout << "Max Pixel Value: " << maxval << std::endl;<br> return EXIT_SUCCESS;<br>}<br><br><br><br></div>