[Insight-users] Pixel Extraction

RAGHU PRASAD raghuprasad.m.s at gmail.com
Tue Jan 13 00:46:25 EST 2009


Respected Sir,
I want to extract pixels from a 2d image .My code is not meeting desired
objective.Please tell me how to extraxt pixels in a given image and after
the pixel values are extracted how can I view the extracted pixel data.Iam
Posting mycode .Pl help.


#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include "itkImage.h"

#include "itkImageFileReader.h"
// Software Guide : EndCodeSnippet

int main( int , char * argv[])
{

  typedef unsigned char          PixelType;
  const unsigned int             Dimension = 2;
  typedef itk::Image< PixelType, Dimension >   ImageType;

      //ImageType::Pointer image = ImageType::New();
  typedef itk::ImageFileReader< ImageType >  ReaderType;

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

  const char * filename = argv[1];
  reader->SetFileName( filename );

try
   {
  reader->Update();
   }

catch (itk::ExceptionObject& e)
   {
   std::cerr << "Exception detected: "  << e;
   return -1;
   }


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

  ImageType::IndexType start;
  ImageType::SizeType  size;

  size[0]  = 100;  // size along X
  size[1]  = 100;  // size along Y
  //size[2]  = 200;  // size along Z

  start[0] =   0;  // first index on X
  start[1] =   0;  // first index on Y
  //start[2] =   0;  // first index on Z

  ImageType::RegionType region;
  region.SetSize( size );
  region.SetIndex( start );

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

  ImageType::PixelType  initialValue = 0;
  image->FillBuffer( initialValue );

  ImageType::IndexType pixelIndex;

  pixelIndex[0] = 27;   // x position
  pixelIndex[1] = 29;   // y position
  //pixelIndex[2] = 37;   // z position

  ImageType::PixelType   pixelValue = image->GetPixel( pixelIndex );

  image->SetPixel(   pixelIndex,   pixelValue+1  );


return 0;
}


-- 
Warm Regards

Raghu Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090113/22e59356/attachment.htm>


More information about the Insight-users mailing list