~ubuntu-branches/ubuntu/precise/insighttoolkit/precise

« back to all changes in this revision

Viewing changes to Testing/Code/Review/itkValuedRegionalMinimaImageFilterTest.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2008-12-19 20:16:49 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081219201649-drt97guwl2ryt0cn

* New upstream version.
  - patches/nifti-versioning.patch: Remove.  Applied upstream.
  - control:
  - rules: Update version numbers, package names.

* control: Build-depend on uuid-dev (gdcm uses it).

* copyright: Update download URL.

* rules: Adhere to parallel=N in DEB_BUILD_OPTIONS by setting MAKEFLAGS.

* compat: Set to 7.
* control: Update build-dep on debhelper to version >= 7.

* CMakeCache.txt.debian: Set CMAKE_BUILD_TYPE to "RELEASE" so that we
  build with -O3 (not -O2), necessary to optimize the templated code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: itkValuedRegionalMinimaImageFilterTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2007-01-23 22:25:27 $
 
7
  Version:   $Revision: 1.4 $
 
8
 
 
9
  Copyright (c) Insight Software Consortium. All rights reserved.
 
10
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
 
11
 
 
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.
 
15
 
 
16
=========================================================================*/
 
17
 
 
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"
 
30
 
 
31
int itkValuedRegionalMinimaImageFilterTest(int argc, char * argv[])
 
32
{
 
33
  const int dim = 2;
 
34
  
 
35
  if( argc < 5 )
 
36
    {
 
37
    std::cerr << "Missing Parameters " << std::endl;
 
38
    std::cerr << "Usage: " << argv[0];
 
39
    std::cerr << " InputImage  OutputImageFile1 OutputImageFile2  " 
 
40
              << "OutputImageFile3" << std::endl;
 
41
    return EXIT_FAILURE;
 
42
    }
 
43
 
 
44
  typedef unsigned char                 PixelType;
 
45
  typedef itk::Image< PixelType, dim >  ImageType;
 
46
 
 
47
  typedef itk::ImageFileReader< ImageType > ReaderType;
 
48
  ReaderType::Pointer reader = ReaderType::New();
 
49
  reader->SetFileName( argv[2] );
 
50
 
 
51
  typedef itk::ValuedRegionalMinimaImageFilter< ImageType, ImageType > 
 
52
                                                              FilterType;
 
53
  FilterType::Pointer filter = FilterType::New();
 
54
  filter->SetInput( reader->GetOutput() );
 
55
  filter->SetFullyConnected( atoi(argv[1]) );
 
56
  itk::SimpleFilterWatcher watcher(filter, "filter");
 
57
 
 
58
  typedef itk::ImageFileWriter< ImageType > WriterType;
 
59
  WriterType::Pointer writer = WriterType::New();
 
60
  writer->SetInput( filter->GetOutput() );
 
61
  writer->SetFileName( argv[3] );
 
62
  writer->Update();
 
63
 
 
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 );
 
70
 
 
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 );
 
78
 
 
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() );
 
84
 
 
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() );
 
91
 
 
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() );
 
99
 
 
100
  WriterType::Pointer writer2 = WriterType::New();
 
101
  writer2->SetInput( max->GetOutput() );
 
102
  writer2->SetFileName( argv[4] );
 
103
  writer2->Update();
 
104
 
 
105
  return EXIT_SUCCESS;
 
106
}