[Insight-users] Pixel Extraction

RAGHU PRASAD raghuprasad.m.s at gmail.com
Sun Jan 11 07:03:01 EST 2009


Respected Sir,


I have a gray scale image of png format.Iam trying extract Pixel information
but my program crashes satting unhandled exception.Iam posting the code
.Please rectify the error.Awaiting your response.

#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;

typedef itk::ImageFileReader< ImageType > ReaderType;

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

const char * filename = argv[1];

reader->SetFileName( filename );

reader->Update();

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

ImageType::IndexType start;

ImageType::SizeType size;

size[0] = 100; // size along X

size[1] = 100; // size along Y

start[0] = 0; // first index on X

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

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

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/20090111/60c5bc09/attachment.htm>


More information about the Insight-users mailing list