[Insight-users] Create an image
john smith
mkitkinsightuser at gmail.com
Wed Mar 2 10:06:52 EST 2011
Hello,
I am trying to create an image 20x20. Every pixel will have the value 0.
Then, I have created an other function called OutputImage, with which I
trying to see all the pixel's value on my window command prompt. The project
is built correctly, but when I run it from the command window prompt I do
not take any value. Could anybody find the problem?
Thanks in advance
-------------------------------------------------
-------------------------------------------------------
#include "itkImage.h"
#include "itkImageFileWriter.h"
typedef itk::Image<unsigned char, 2> ImageType;
static void CreateImage(ImageType::Pointer image);
void OutputImage(ImageType::Pointer image);
int main(int, char *[])
{
// unsigned int pixelIndex;
ImageType::Pointer image = ImageType::New();
CreateImage(image);
OutputImage(image);
std::cout << "Original size: " <<
image->GetLargestPossibleRegion().GetSize() << std::endl;
// std::cout << image-> GetPixel(pixelIndex) << std::endl;
return EXIT_SUCCESS;
}
void CreateImage(ImageType::Pointer image)
{
ImageType::IndexType start;
start.Fill(0);
ImageType::SizeType size;
size.Fill(20);
ImageType::RegionType region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
}
void OutputImage(ImageType::Pointer image)
{
for(unsigned int r = 0; r < 20; r++)
{
for(unsigned int c = 0; c < 20; c++)
{
ImageType::IndexType pixelIndex;
pixelIndex[0] = r;
pixelIndex[1] = c;
std::cout << image-> GetPixel(pixelIndex) << std::endl;
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110302/3cea06c0/attachment.htm>
More information about the Insight-users
mailing list