[Insight-users] acces 3D pixel value with iterator
Hsiang-Chi Kuo
kuoxgx at gmail.com
Mon Dec 21 23:47:06 EST 2009
Hi,
I am trying to access the maximum and minimum pixel value of a 3D image with
the following code, however, the result dose not look right (maximum 0,
minimum 1000). Can anyone give me a hint why this code dose not work?
Thanks a lot,
Howard
typedef unsigned int InputPixelType;
const unsigned int Dimension = 3;
typedef unsigned int OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
typedef itk::ImageRegionIterator< InputImageType > IteratorType;
InputImageType::Pointer image = InputImageType::New();
image = reader->GetOutput();
IteratorType it( image, image->GetLargestPossibleRegion() );
int max=0;
int min=10000;
for (it.GoToBegin();!it.IsAtEnd();++it)
{
int temp = it.Get();
if (temp>max)
max=temp;
if (temp<min)
min=temp;
}
std::cout << "min=" << min <<std::endl;
std::cout << "max=" << max <<std::endl;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091221/5c5ff62d/attachment.htm>
More information about the Insight-users
mailing list