[Insight-users] acces 3D pixel value with iterator

Lassi Paavolainen lassi.paavolainen at jyu.fi
Tue Dec 22 06:15:09 EST 2009


Hi Hsiang-Chi,

Maybe adding: image->Update; between these lines would work
    image = reader->GetOutput();
    IteratorType it( image, image->GetLargestPossibleRegion() );

I think you can also change
    InputImageType::Pointer image = InputImageType::New();
to
    InputImageType::Pointer image;

There is no need to create new image as you get it from reader.

Lassi

On Mon, 21 Dec 2009, Hsiang-Chi Kuo wrote:

> 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;
> 
>  
> 
> 
>

-- 
Lassi Paavolainen, M.Sc
Software Engineer, PhD Student in Computer Science
BioImageXD (http://www.bioimagexd.net)
University of Jyväskylä
lassi.paavolainen at jyu.fi


More information about the Insight-users mailing list