[Insight-users] Pixel Extraction

Bill Lorensen bill.lorensen at gmail.com
Sun Jan 11 12:36:19 EST 2009


Raghu,

When using ITK, you should always surround each Update() with a
try/catch block. The resulting exception description should provide
more useful error information.

For example, in for your first Update(), do something like the following:

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


Bill

On Sun, Jan 11, 2009 at 7:03 AM, RAGHU PRASAD <raghuprasad.m.s at gmail.com> wrote:
> 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
> _______________________________________________
> 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