[Insight-users] using iterators to normalize image

Neil Panjwani paniwani at gmail.com
Tue Jun 7 11:58:44 EDT 2011


Most of your questions are clearly addressed in the ITK Software guide:

www.itk.org/ItkSoftwareGuide.pdf

See Ch.7: Reading and Writing Images

On Tue, Jun 7, 2011 at 11:36 AM, john smith <mkitkinsightuser at gmail.com>wrote:

> Hello,
>
> Now I have used iterators in order to normalize an image, which I load
> from a file using a reader. I have created an *out *iterator in order to
> set the new values of my image. I want to ask how could I write the image
> with the changed values into a .png file?
>
> Thanks in advance for your help.
>
> typedef itk::ImageRegionIterator<InputImageType> ImageIteratorType;
> typedef InputImageType::RegionType               RegionType;
> typedef InputImageType::PixelType                PixelType;
>
>  ReaderType::Pointer reader = ReaderType::New();
>      reader->SetFileName( fileName.toStdString()  );
>      reader->Update();
>
>       InputImageType::RegionType inputRegion =
>            reader->GetOutput()->GetLargestPossibleRegion();
>
>  InputImageType::Pointer image = reader->GetOutput();
>
> // Get image region
> RegionType region = image->GetLargestPossibleRegion();
>
> // Create iterator
> ImageIteratorType it( image, region );
> it.GoToBegin();
>
> ImageIteratorType out( image, region );
> out.GoToBegin();
>
> // Initialization of max_value
> int max_value=0;
> int min_value=0;
>
> // Loop
> while(!it.IsAtEnd())
> {
>  // Pixel value
>  PixelType pixel = it.Get();
>
>  // Is it bigger than the max?
>  if (pixel>max_value)
>    max_value = pixel;
>
>   if (pixel<min_value)
>    min_value = pixel;
>  // Increment iterator
>  ++it;
> }
>  ui->label_22->setText(QString("maximum_value_raw:%1").arg(max_value));
>  ui->label_23->setText(QString("minimum_value_raw:%1").arg(min_value));
>
> // Loop
> if (max_value>255){
>         while(!it.IsAtEnd())
>         {
>          // Pixel value
>          PixelType pixel = it.Get();
>
>          // Is it bigger than the max?
>          out.Set(255*((pixel-min_value)/(max_value-min_value)));
>          // Increment iterator
>          ++it;
>          ++out;
>         }
> }
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110607/de00d74f/attachment.htm>


More information about the Insight-users mailing list