<div>Hello John</div>You are almost there.<div><br></div><div><br></div><div>First you have created a FileReader, but you don't have actually read the image. You have to call the Update method in the file reader so that the filter starts doint its job.</div>
<div>Once the file is read, you use the image at the output of the filter, and read it's contents. Notice that you don't need to create a new image, you need to use the output image from the filter.</div><div><br>
</div><div>Your code should look like this, modifications shown in bold font (there may be errors in this code as I didnt compiled it):</div><div><br></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">#include "itkImage.h"<br>
#include "itkImageFileReader.h"<br><br>#include "itkIndex.h"<br> <br>int main(int argc, char *argv[])<br>{<br> if( argc < 2 )<br> {<br> std::cerr << "Usage: " << std::endl;<br>
std::cerr << argv[0] << " inputImageFile" << std::endl;<br> return EXIT_FAILURE;<br> }<br> <br> typedef itk::Image< unsigned short, 2 > ImageType;<br> typedef itk::ImageFileReader<ImageType> ReaderType;<br>
<br> ReaderType::Pointer reader= ReaderType::New();<br> reader->SetFileName(argv[1]);<br> </span></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><b> reader->Update() // a try... catch block needed here</b><br>
<br> //////////////////<br><br> // image object can be created<br><b> // ImageType::Pointer image = ImageType::New(); // no doing this, you read from another image</b></span></div><div><span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><b><span class="Apple-style-span" style="font-weight: normal; "><b> ImageType::Pointer image = reader->GetOutput();</b></span><br>
</b><br><br> ImageType::IndexType pixelIndex;<br> <br> pixelIndex[0] = 17; // x position<br> pixelIndex[1] = 19; // y position<br><br><br> ImageType::PixelType pixelValue = image->GetPixel( pixelIndex );<br><br>
<br> std::cout << image->GetPixel(pixelIndex);<br><br>///////////////////////<br><br> return EXIT_SUCCESS;<br>}</span></div><div><div><br><br><div class="gmail_quote">On Thu, Feb 17, 2011 at 11:05 AM, john smith <span dir="ltr"><<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br><br>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?<br>
<br>Thanks<br>-----------------------code------------------------------<br>--------------------------------------------------------<br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br><br>#include "itkIndex.h"<br>
<br>int main(int argc, char *argv[])<br>{<br> if( argc < 2 )<br> {<br> std::cerr << "Usage: " << std::endl;<br> std::cerr << argv[0] << " inputImageFile" << std::endl;<br>
return EXIT_FAILURE;<br> }<br> <br> typedef itk::Image< unsigned short, 2 > ImageType;<br> typedef itk::ImageFileReader<ImageType> ReaderType;<br> <br> ReaderType::Pointer reader= ReaderType::New();<br>
reader->SetFileName(argv[1]);<br> <br> <br> //////////////////<br><br> // image object can be created<br> ImageType::Pointer image = ImageType::New();<br><br><br> ImageType::IndexType pixelIndex;<br> <br> pixelIndex[0] = 17; // x position<br>
pixelIndex[1] = 19; // y position<br><br><br> ImageType::PixelType pixelValue = image->GetPixel( pixelIndex );<br><br><br> std::cout << image->GetPixel(pixelIndex);<br><br>///////////////////////<br><br>
return EXIT_SUCCESS;<br>}<br><br><br>------------------CMakeLists.txt------------------<br>-------------------------------------------------------<br>cmake_minimum_required(VERSION 2.6)<br> <br>PROJECT(ImageFileReader)<br>
<br>FIND_PACKAGE(ITK REQUIRED)<br>INCLUDE(${ITK_USE_FILE})<br> <br> <br>ADD_EXECUTABLE(myproject myproject.cxx)<br>TARGET_LINK_LIBRARIES(myproject ITKIO ITKCommon)<br>
<br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. (+34) 932 380 592<br> <a href="http://www.alma3d.com">www.alma3d.com</a><br>
</div></div>