1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: itkValuedRegionalMinimaImageFilterTest.cxx,v $
6
Date: $Date: 2007-01-23 22:25:27 $
7
Version: $Revision: 1.4 $
9
Copyright (c) Insight Software Consortium. All rights reserved.
10
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12
This software is distributed WITHOUT ANY WARRANTY; without even
13
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
PURPOSE. See the above copyright notices for more information.
16
=========================================================================*/
18
// a test routine for regional extrema using flooding
19
#include "itkValuedRegionalMinimaImageFilter.h"
20
#include "itkMaximumImageFilter.h"
21
#include "itkHConcaveImageFilter.h"
22
#include "itkInvertIntensityImageFilter.h"
23
#include "itkImageFileReader.h"
24
#include "itkImageFileWriter.h"
25
#include "itkCommand.h"
26
#include "itkRescaleIntensityImageFilter.h"
27
#include "itkAndImageFilter.h"
28
#include "itkCommand.h"
29
#include "itkSimpleFilterWatcher.h"
31
int itkValuedRegionalMinimaImageFilterTest(int argc, char * argv[])
37
std::cerr << "Missing Parameters " << std::endl;
38
std::cerr << "Usage: " << argv[0];
39
std::cerr << " InputImage OutputImageFile1 OutputImageFile2 "
40
<< "OutputImageFile3" << std::endl;
44
typedef unsigned char PixelType;
45
typedef itk::Image< PixelType, dim > ImageType;
47
typedef itk::ImageFileReader< ImageType > ReaderType;
48
ReaderType::Pointer reader = ReaderType::New();
49
reader->SetFileName( argv[2] );
51
typedef itk::ValuedRegionalMinimaImageFilter< ImageType, ImageType >
53
FilterType::Pointer filter = FilterType::New();
54
filter->SetInput( reader->GetOutput() );
55
filter->SetFullyConnected( atoi(argv[1]) );
56
itk::SimpleFilterWatcher watcher(filter, "filter");
58
typedef itk::ImageFileWriter< ImageType > WriterType;
59
WriterType::Pointer writer = WriterType::New();
60
writer->SetInput( filter->GetOutput() );
61
writer->SetFileName( argv[3] );
64
// produce the same output with other filters
65
typedef itk::HConcaveImageFilter< ImageType, ImageType > ConcaveType;
66
ConcaveType::Pointer concave = ConcaveType::New();
67
concave->SetInput( reader->GetOutput() );
68
concave->SetFullyConnected( atoi(argv[1]) );
69
concave->SetHeight( 1 );
71
// concave gives minima with value=1 and others with value=0
72
// rescale the image so we have minima=255 other=0
73
typedef itk::RescaleIntensityImageFilter< ImageType, ImageType > RescaleType;
74
RescaleType::Pointer rescale = RescaleType::New();
75
rescale->SetInput( concave->GetOutput() );
76
rescale->SetOutputMaximum( 255 );
77
rescale->SetOutputMinimum( 0 );
79
// in the input image, select the values of the pixel at the minima
80
typedef itk::AndImageFilter< ImageType, ImageType, ImageType > AndType;
81
AndType::Pointer a = AndType::New();
82
a->SetInput(0, rescale->GetOutput() );
83
a->SetInput(1, reader->GetOutput() );
85
// all pixel which are not minima must have value=255.
86
// get the non minima pixel by inverting the rescaled image
87
// we will have minima value=0 and non minima value=255
88
typedef itk::InvertIntensityImageFilter< ImageType, ImageType > InvertType;
89
InvertType::Pointer invert = InvertType::New();
90
invert->SetInput( rescale->GetOutput() );
92
// get the highest value from "a" and from invert. The minima have
93
// value>=0 in "a" image and the non minima have a value=0. In invert,
94
// the non minima have a value=255 and the minima a value=0
95
typedef itk::MaximumImageFilter< ImageType, ImageType, ImageType > MaxType;
96
MaxType::Pointer max = MaxType::New();
97
max->SetInput(0, invert->GetOutput() );
98
max->SetInput(1, a->GetOutput() );
100
WriterType::Pointer writer2 = WriterType::New();
101
writer2->SetInput( max->GetOutput() );
102
writer2->SetFileName( argv[4] );