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

Hsiang-Chi Kuo kuoxgx at gmail.com
Tue Dec 22 23:01:57 EST 2009


Hi Lassi,

I add

 try
    {
    reader->Update();
    }
  catch (itk::ExceptionObject & e)
    {
    std::cerr << "exception in file reader " << std::endl;
    std::cerr << e << std::endl;
    return EXIT_FAILURE;
    }

after
reader->SetFileName( argv[1] );

Now the results look reasonable.

Thanks for your help.

Howard

On Tue, Dec 22, 2009 at 6:15 AM, Lassi Paavolainen <lassi.paavolainen at jyu.fi
> wrote:

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091222/75eca8bd/attachment.htm>


More information about the Insight-users mailing list