[Insight-users] Pixel Extraction

Dan Mueller dan.muel at gmail.com
Tue Jan 13 02:14:23 EST 2009


Hi Raghu,

What do you mean by "extract pixels"? Do you mean access pixel values
at a specific index location? Or do you mean access *all* pixel values
in some order? Or do you mean obtain a C-like array containing the
pixel values? I suspect you mean access the pixels for the entire
image in a specific order... If this is the case, then you will want
to use an image iterator.

Please provide more details as to what exactly you are trying to
achieve. In the meantime, perhaps some of the ITK
documentation/examples would be helpful.

Please read chapter 4 (images) and 11 (iterators) of the ITK Software Guide:
    http://www.itk.org/ItkSoftwareGuide.pdf

The following examples may also be of interest:
    Examples/IO/ImageReadWrite.cxx
    Examples/Iterators/ImageRegionIterator.cxx

Hope this helps.

Regards, Dan

2009/1/13 RAGHU PRASAD <raghuprasad.m.s at gmail.com>:
> 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
> _______________________________________________
> 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