Respected Sir,<br>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.<br>
<br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#include "itkImage.h"<br><br>#include "itkImageFileReader.h"<br>// Software Guide : EndCodeSnippet<br><br>int main( int , char * argv[])<br>
{<br> <br> typedef unsigned char PixelType;<br> const unsigned int Dimension = 2;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br><br> //ImageType::Pointer image = ImageType::New();<br>
typedef itk::ImageFileReader< ImageType > ReaderType;<br><br> ReaderType::Pointer reader = ReaderType::New();<br> <br> const char * filename = argv[1];<br> reader->SetFileName( filename );<br> <br>try<br>
{<br> reader->Update();<br> }<br><br>catch (itk::ExceptionObject& e)<br> {<br> std::cerr << "Exception detected: " << e;<br> return -1;<br> }<br><br> <br> ImageType::Pointer image = reader->GetOutput();<br>
<br> ImageType::IndexType start;<br> ImageType::SizeType size;<br><br> size[0] = 100; // size along X<br> size[1] = 100; // size along Y<br> //size[2] = 200; // size along Z<br><br> start[0] = 0; // first index on X<br>
start[1] = 0; // first index on Y<br> //start[2] = 0; // first index on Z<br><br> ImageType::RegionType region;<br> region.SetSize( size );<br> region.SetIndex( start );<br> <br> image->SetRegions( region );<br>
image->Allocate();<br><br> ImageType::PixelType initialValue = 0;<br> image->FillBuffer( initialValue );<br><br> ImageType::IndexType pixelIndex;<br><br> pixelIndex[0] = 27; // x position<br> pixelIndex[1] = 29; // y position<br>
//pixelIndex[2] = 37; // z position<br> <br> ImageType::PixelType pixelValue = image->GetPixel( pixelIndex );<br><br> image->SetPixel( pixelIndex, pixelValue+1 );<br><br><br>return 0;<br>}<br><br><br>-- <br>
Warm Regards<br><br>Raghu Prasad