[Insight-users] using iterators to normalize image

john smith mkitkinsightuser at gmail.com
Tue Jun 7 11:36:00 EDT 2011


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;
        }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110607/2db038c7/attachment.htm>


More information about the Insight-users mailing list