[Insight-users] Get pixel Data

john smith mkitkinsightuser at gmail.com
Thu Feb 17 05:05:21 EST 2011


Hello,

I use visualstudio2010 and cmake.I am trying to read an image with the
Command  Prompt window (for example a .png image) and then get the data
value of a pixel using the get()  method. Finally, I want to take the value
of the pixel on the Command Prompt window. So, I have created an imageReader
object and an IndexType object as it is shown in the following code. As
structures separately, the two objects seem to be correct, but I don't know
how to connect them together to get my data value. Could someone help me
with this problem?

Thanks
-----------------------code------------------------------
--------------------------------------------------------
#include "itkImage.h"
#include "itkImageFileReader.h"

#include "itkIndex.h"

int main(int argc, char *argv[])
{
  if( argc < 2 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile" << std::endl;
    return EXIT_FAILURE;
    }

  typedef itk::Image<  unsigned short, 2 >         ImageType;
  typedef itk::ImageFileReader<ImageType> ReaderType;

  ReaderType::Pointer reader= ReaderType::New();
  reader->SetFileName(argv[1]);


  //////////////////

  //  image object can be created
  ImageType::Pointer image = ImageType::New();


  ImageType::IndexType pixelIndex;

  pixelIndex[0] = 17;   // x position
  pixelIndex[1] = 19;   // y position


  ImageType::PixelType   pixelValue = image->GetPixel( pixelIndex );


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

///////////////////////

  return EXIT_SUCCESS;
}


------------------CMakeLists.txt------------------
-------------------------------------------------------
cmake_minimum_required(VERSION 2.6)

PROJECT(ImageFileReader)

FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})


ADD_EXECUTABLE(myproject myproject.cxx)
TARGET_LINK_LIBRARIES(myproject ITKIO ITKCommon)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110217/8f9ab83a/attachment.htm>


More information about the Insight-users mailing list