I have a .png image file in the source directory and I want to get the data of one pixel of the image and see the results on the Command Window (if it is possible) or on another file (such as a .txt file) . Firstly, I am wondering if it is necessary to read the hole Image by using a ImageFileReader, or I can get the data I want just with the using of itkIndex.<br>
<br><div class="gmail_quote">2011/2/16 David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote">On Wed, Feb 16, 2011 at 12:50 PM, john smith <span dir="ltr"><<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br><br>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? <br>
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?<br><br>
Thanks in advance<br><br>---------------------------------code-----------------------<br>------------------------------------------------------------<br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>
#endif<br>
<br><br>#include "itkImage.h"<br>#include "itkIndex.h"<br><br>int main(int, char *[])<br>{<br> // First the image type should be declared<br> typedef itk::Image< unsigned short, 2 > ImageType;<br>
<br> // Then the image object can be created<br> ImageType::Pointer image = ImageType::New();<br><br> // The image region should be initialized<br> ImageType::IndexType start;<br> ImageType::SizeType size;<br><br> size[0] = 200; // size along X<br>
size[1] = 200; // size along Y<br> <br><br> start[0] = 0; // first index on X<br> start[1] = 0; // first index on Y<br> <br><br> ImageType::RegionType region;<br> region.SetSize( size );<br> region.SetIndex( start );<br>
<br> // Pixel data is allocated<br> image->SetRegions( region );<br> image->Allocate();<br><br> // The image buffer is initialized to a particular value<br> ImageType::PixelType initialValue = 0;<br> image->FillBuffer( initialValue );<br>
<br><br> ImageType::IndexType pixelIndex;<br> <br> pixelIndex[0] = 27; // x position<br> pixelIndex[1] = 29; // y position<br><br><br><br> ImageType::PixelType pixelValue = image->GetPixel( pixelIndex );<br>
<br>
<br><br> image->SetPixel( pixelIndex, pixelValue+1 );<br><br><br><br> return 0;<br><br>}<br><br></blockquote><div><br></div><div>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.</div>
</div><div><br></div>You could view the value of the pixel you have set by doing:<div><br><div>std::cout << image->GetPixel(pixelIndex);</div></div>
<div><br></div><font color="#888888"><div>David</div>
</font></blockquote></div><br><div style="visibility: hidden; left: -5000px; position: absolute; z-index: 9999; padding: 0px; margin-left: 0px; margin-top: 0px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 130%;" id="avg_ls_inline_popup">
</div>