Hello,<br><br>Now I have used iterators in order to normalize an image, which I load from a file using a reader. I have created an <i>out </i>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?<br>
<br>Thanks in advance for your help.<br><br>typedef itk::ImageRegionIterator<InputImageType> ImageIteratorType;<br>typedef InputImageType::RegionType RegionType;<br>typedef InputImageType::PixelType PixelType;<br>
<br> ReaderType::Pointer reader = ReaderType::New();<br> reader->SetFileName( fileName.toStdString() );<br> reader->Update();<br><br> InputImageType::RegionType inputRegion =<br> reader->GetOutput()->GetLargestPossibleRegion();<br>
<br> InputImageType::Pointer image = reader->GetOutput();<br><br>// Get image region<br>RegionType region = image->GetLargestPossibleRegion();<br><br>// Create iterator<br>ImageIteratorType it( image, region );<br>it.GoToBegin();<br>
<br>ImageIteratorType out( image, region );<br>out.GoToBegin();<br><br>// Initialization of max_value<br>int max_value=0;<br>int min_value=0;<br><br>// Loop<br>while(!it.IsAtEnd())<br>{<br> // Pixel value<br> PixelType pixel = it.Get();<br>
<br> // Is it bigger than the max?<br> if (pixel>max_value)<br> max_value = pixel;<br><br> if (pixel<min_value)<br> min_value = pixel;<br> // Increment iterator<br> ++it;<br>}<br> ui->label_22->setText(QString("maximum_value_raw:%1").arg(max_value));<br>
ui->label_23->setText(QString("minimum_value_raw:%1").arg(min_value));<br><br>// Loop<br>if (max_value>255){<br> while(!it.IsAtEnd())<br> {<br> // Pixel value<br> PixelType pixel = it.Get();<br>
<br> // Is it bigger than the max?<br> out.Set(255*((pixel-min_value)/(max_value-min_value)));<br> // Increment iterator<br> ++it;<br> ++out;<br> }<br>}<br>