[Insight-users] Pixel Extraction
RAGHU PRASAD
raghuprasad.m.s at gmail.com
Sat Jan 10 05:28:30 EST 2009
Respected Sir,
I want to extract(access pixel data) froam a gray scale image,but my
program crashes with the followinf error message
First-chance exception at 0x7c81eb33 in Image.exe: Microsoft C++ exception:
itk::ImageFileReaderException at memory location 0x0131fb54..
Unhandled exception at 0x7c81eb33 in Image.exe: Microsoft C++ exception:
itk::ImageFileReaderException at memory location 0x0131fb54..
Iam posting the code.Please rectify the error.
#if
defined(_MSC_VER)
#pragma
warning ( disable : 4786 )
#endif
#include"itkImage.h"
#include"itkImageFileReader.h"
int main( int , char * argv[])
{
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
ImageType::Pointer image = ImageType::New();
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] = 200; // size along X
size[1] = 200; // 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;
pixelIndex[1] = 29;
pixelIndex[2] = 37;
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/20090110/5e5e4bf8/attachment-0001.htm>
More information about the Insight-users
mailing list