1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: itkMapMaskedRankImageFilterTest.cxx,v $
6
Date: $Date: 2008-08-08 11:41:11 $
7
Version: $Revision: 1.2 $
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
#pragma warning ( disable : 4786 )
22
#include "itkMaskedRankImageFilter.h"
23
#include "itkImageFileReader.h"
24
#include "itkImageFileWriter.h"
25
#include "itkTextOutput.h"
26
#include "itkNumericTraits.h"
27
#include "itkFilterWatcher.h"
29
int itkMapMaskedRankImageFilterTest(int ac, char* av[] )
31
// Comment the following if you want to use the itk text output window
32
itk::OutputWindow::SetInstance(itk::TextOutput::New());
36
std::cerr << "Usage: " << av[0] << " InputImage maskImage BaselineImage radius" << std::endl;
40
typedef itk::Image<unsigned short, 2> ImageType;
42
typedef itk::ImageFileReader<ImageType> ReaderType;
43
ReaderType::Pointer input = ReaderType::New();
44
input->SetFileName(av[1]);
46
ReaderType::Pointer input2 = ReaderType::New();
47
input2->SetFileName(av[2]);
50
typedef itk::FlatStructuringElement<2> SEType;
51
typedef itk::MaskedRankImageFilter<ImageType,ImageType,ImageType,SEType> FilterType;
52
FilterType::Pointer filter = FilterType::New();
53
FilterWatcher filterWatch(filter);
55
typedef FilterType::RadiusType RadiusType;
57
// test default values
60
if ( filter->GetRadius() != r1 )
62
std::cerr << "Wrong default Radius." << std::endl;
65
if ( filter->GetRank() != 0.5 )
67
std::cerr << "Wrong default Rank." << std::endl;
70
if ( filter->GetMaskValue() != 65535 )
72
std::cerr << "Wrong default mask value." << std::endl;
75
if ( filter->GetFillValue() != 0 )
77
std::cerr << "Wrong default fill value." << std::endl;
80
if ( filter->GetBackgroundMaskValue() != 0 )
82
std::cerr << "Wrong default background mask value." << std::endl;
86
// set radius with a radius type
89
filter->SetRadius( r5 );
90
if ( filter->GetRadius() != r5 )
92
std::cerr << "Radius value is not the expected one:�r5." << std::endl;
96
// set radius with an integer
97
filter->SetRadius( 1 );
98
if ( filter->GetRadius() != r1 )
100
std::cerr << "Radius value is not the expected one:�r1." << std::endl;
104
filter->SetRank( 0.25 );
105
if ( filter->GetRank() != 0.25 )
107
std::cerr << "Rank value is not the expected one: " << filter->GetRank() << std::endl;
111
filter->SetMaskValue( 1 );
112
if ( filter->GetMaskValue() != 1 )
114
std::cerr << "Mask value value is not the expected one: " << filter->GetMaskValue() << std::endl;
118
filter->SetFillValue( 1 );
119
if ( filter->GetFillValue() != 1 )
121
std::cerr << "Fill value value is not the expected one: " << filter->GetFillValue() << std::endl;
125
filter->SetBackgroundMaskValue( 1 );
126
if ( filter->GetBackgroundMaskValue() != 1 )
128
std::cerr << "Background mask value value is not the expected one: " << filter->GetBackgroundMaskValue() << std::endl;
134
int r = atoi( av[4] );
135
filter->SetInput(input->GetOutput());
136
filter->SetMaskImage(input2->GetOutput());
137
filter->SetRadius( r );
138
filter->SetRank( 0.5 );
139
filter->SetMaskValue( 255 );
140
filter->SetFillValue( 1 );
141
filter->SetBackgroundMaskValue( 0 );
144
catch (itk::ExceptionObject& e)
146
std::cerr << "Exception detected: " << e.GetDescription();
150
// Generate test image
151
typedef itk::ImageFileWriter<ImageType> WriterType;
152
WriterType::Pointer writer = WriterType::New();
153
writer->SetInput( filter->GetOutput() );
154
writer->SetFileName( av[3] );