ITK/Examples/ImageProcessing/AbsImageFilter: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
(CreateImage must be static to avoid duplicate symbols in test driver.) |
(Use QuickView) |
||
Line 6: | Line 6: | ||
#include "itkAbsImageFilter.h" | #include "itkAbsImageFilter.h" | ||
#include "QuickView.h" | |||
#include " | |||
typedef itk::Image<unsigned char, 2> UnsignedCharImageType; | typedef itk::Image<unsigned char, 2> UnsignedCharImageType; | ||
Line 25: | Line 17: | ||
FloatImageType::Pointer image = FloatImageType::New(); | FloatImageType::Pointer image = FloatImageType::New(); | ||
CreateImage(image); | CreateImage(image); | ||
// Take the absolute value of the image | // Take the absolute value of the image | ||
typedef itk::AbsImageFilter <FloatImageType, | typedef itk::AbsImageFilter <FloatImageType, FloatImageType> | ||
AbsImageFilterType; | AbsImageFilterType; | ||
Line 41: | Line 25: | ||
= AbsImageFilterType::New (); | = AbsImageFilterType::New (); | ||
absFilter->SetInput(image); | absFilter->SetInput(image); | ||
QuickView viewer; | |||
viewer.AddImage<FloatImageType>(image); | |||
viewer.AddImage<FloatImageType>(absFilter->GetOutput()); | |||
viewer.Visualize(); | |||
return EXIT_SUCCESS; | return EXIT_SUCCESS; |
Revision as of 00:30, 18 November 2010
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>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
PROJECT(AbsImageFilter)
include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/)
FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(AbsImageFilter AbsImageFilter.cxx) TARGET_LINK_LIBRARIES(AbsImageFilter vtkHybrid ITKBasicFilters ITKCommon ITKIO)
</source>