[Insight-users] Fwd: reading jpg files

Jie Zhu zhujie1979 at gmail.com
Wed Sep 15 17:34:48 EDT 2004


Hi All,
I am new to itk, and I need to use it with JPEG files. I wrote a
simple program putting the jpeg file in  image and tested to see if
image.GetPixel() returns the correct value of the pixels. But the
result I get looks like:
205
205
205
205
...
Although the input image have a variety of pixel values, the pixel
values GetPixel() return are all 205 or "=" if I dont convert it to
(int). Can somebody please help me and tell me what I'm doing wrong.
Thank you.
Jie

Below is the code
-------------------------------------------------------------------------------------------------------------
 typedef itk::Image<unsigned char,2>            ImageType;

 typedef itk::ImageFileReader< ImageType >  ReaderType;

 ReaderType::Pointer reader = ReaderType::New();

 const char * inputFilename  = argv[1];
 const char * outputFilename = argv[2];

 reader->SetFileName( inputFilename  );
 writer->SetFileName( outputFilename );

 ImageType::Pointer image = reader->GetOutput();

 //set regions in input image
 ImageType::RegionType region;
 ImageType::RegionType::SizeType size;
 ImageType::RegionType::IndexType index;;
 index[ 0 ] = 0;
 index[ 1 ] = 0;
 size[ 0 ] = 255;
 size[ 1 ] = 255;

 region.SetSize( size );
 region.SetIndex( index );

 image->SetRegions( region );
 image->Allocate();

 //creat linear iterators
 //typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;

 typedef itk::ImageLinearConstIteratorWithIndex< ImageType >
ConstIteratorType;
 ConstIteratorType inputIt( image, image->GetRequestedRegion() );
 inputIt.SetDirection(0);

  //iteration
 for ( inputIt.GoToBegin(); ! inputIt.IsAtEnd();
        inputIt.NextLine())
   {
   inputIt.GoToBeginOfLine();
   while ( ! inputIt.IsAtEndOfLine() )
     {
     ImageType::PixelType   pixelValue = image->GetPixel( indx );
     std::cout<<(int)pixelValue<<" "<<std::endl;
      ++inputIt;

     }
   }

--
Jie Zhu
Cornell University




-- 
Jie Zhu
Cornell University


More information about the Insight-users mailing list