|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| <div class="floatcenter">[[File:ITK_Examples_Baseline_ImageProcessing_TestAbsImageFilter.png]]</div>
| | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions. |
| This example demonstrates how to compute the absolute value of each pixel in an image. The output shows the input image and the absolute value image. The input image, by necessity of this demonstration, has negative pixel values. This type of image is impossible to display directly, so it is scaled and shifted before being displayed so its values are in the range (0,255).
| | }} |
| | |
| ==AbsImageFilter.cxx==
| |
| <source lang="cpp">
| |
| #include "itkImage.h"
| |
| #include "itkImageFileWriter.h"
| |
| #include "itkRescaleIntensityImageFilter.h"
| |
| #include "itkAbsImageFilter.h"
| |
| | |
| #include "QuickView.h"
| |
| | |
| typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
| |
| typedef itk::Image<float, 2> FloatImageType;
| |
| | |
| static void CreateImage(FloatImageType::Pointer image);
| |
| | |
| int main(int, char *[])
| |
| {
| |
| FloatImageType::Pointer image = FloatImageType::New();
| |
| CreateImage(image);
| |
| | |
| // Take the absolute value of the image
| |
| typedef itk::AbsImageFilter <FloatImageType, FloatImageType>
| |
| AbsImageFilterType;
| |
| | |
| AbsImageFilterType::Pointer absFilter
| |
| = AbsImageFilterType::New ();
| |
| absFilter->SetInput(image);
| |
| | |
| QuickView viewer;
| |
| viewer.AddImage<FloatImageType>(image);
| |
| viewer.AddImage<FloatImageType>(absFilter->GetOutput());
| |
| viewer.Visualize();
| |
| | |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| void CreateImage(FloatImageType::Pointer image)
| |
| {
| |
| // Create an image with negative values
| |
| FloatImageType::RegionType region;
| |
| FloatImageType::IndexType start;
| |
| start[0] = 0;
| |
| start[1] = 0;
| |
| | |
| FloatImageType::SizeType size;
| |
| size[0] = 200;
| |
| size[1] = 300;
| |
| | |
| region.SetSize(size);
| |
| region.SetIndex(start);
| |
| | |
| image->SetRegions(region);
| |
| image->Allocate();
| |
| | |
| itk::ImageRegionIterator<FloatImageType> imageIterator(image,region); | |
| | |
| while(!imageIterator.IsAtEnd())
| |
| {
| |
| imageIterator.Set(imageIterator.GetIndex()[0] - imageIterator.GetIndex()[1]);
| |
| ++imageIterator;
| |
| }
| |
|
| |
| }
| |
| </source>
| |
| | |
| {{ITKVTKCMakeLists|AbsImageFilter|vtkHybrid}}
| |