[Insight-users] (no subject)
john smith
mkitkinsightuser at gmail.com
Wed Feb 16 12:50:49 EST 2011
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;
}
---------------------------------------------CMakeLists.txt-------------------------
------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.6)
PROJECT(project)
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(project project.cxx)
TARGET_LINK_LIBRARIES(project ITKCommon )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110216/18b3e9ac/attachment.htm>
More information about the Insight-users
mailing list