[Insight-users] (no subject)

David Doria daviddoria at gmail.com
Wed Feb 16 13:03:18 EST 2011


On Wed, Feb 16, 2011 at 12:50 PM, john smith <mkitkinsightuser at gmail.com>wrote:

> Hello,
>
> I am beginner in using itk and I am trying to get the pixel value of a 2D
> image. As a first step, I am trying to create my own image object, to
> initialize and allocate the image region, and finally using the itkIndex to
> get and set a pixel value (knowing that is not the fastest method). I have
> written the following code, which is correctly built using VisualStudio2010
> and Cmake. But when I run the .exe file with the Command Prompt window, I
> don't get any result on my screen. Could somebody tell me what to do to get
> some results?
> In the second step, I would like to set the filename of the image myself,
> using the Command Prompt window. Could somebody tell me what to change in my
> code, not only in the .cxx file but also in thr CMakeLists.txt?
>
> Thanks in advance
>
> ---------------------------------code-----------------------
> ------------------------------------------------------------
>
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
>
> #include "itkImage.h"
> #include "itkIndex.h"
>
> int main(int, char *[])
> {
>   // First the image type should be declared
>   typedef itk::Image< unsigned short, 2 > ImageType;
>
>   // Then the image object can be created
>   ImageType::Pointer image = ImageType::New();
>
>   // The image region should be initialized
>   ImageType::IndexType start;
>   ImageType::SizeType  size;
>
>   size[0]  = 200;  // size along X
>   size[1]  = 200;  // 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 );
>
>   // Pixel data is allocated
>   image->SetRegions( region );
>   image->Allocate();
>
>   // The image buffer is initialized to a particular value
>   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;
>
> }
>
>
That all looks fine. Are you looking to display the image on the screen?
This capability is not built into ITK. There are ways to interface with ITK,
but maybe you should start by using ImageFileWriter to write the result to a
file and inspect it elsewhere.

You could view the value of the pixel you have set by doing:

std::cout << image->GetPixel(pixelIndex);

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110216/60bc8f70/attachment.htm>


More information about the Insight-users mailing list