[Insight-users] Fwd: reading jpg files
Joshua Cates
cates at sci.utah.edu
Wed Sep 15 17:49:50 EDT 2004
Hello Jie,
In this code you are never calling Update on the
image file reader so you are iterating through
an uninitialized image (of arbitrary values). See
Section 4.1.2 of the ITK Software Guide
(www.itk.org/ItkSoftwareGuide.pdf) for more detailed
information on file readers.
hope this helps,
Josh.
----------------
Josh Cates
Scientific Computing and Imaging Institute
University of Utah
http://www.sci.utah.edu/~cates
On Wed, 15 Sep 2004, Jie Zhu wrote:
> 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
> _______________________________________________
> 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