~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Examples/Segmentation/ConnectedThresholdImageFilter.cxx

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 *
 
3
 *  Copyright Insight Software Consortium
 
4
 *
 
5
 *  Licensed under the Apache License, Version 2.0 (the "License");
 
6
 *  you may not use this file except in compliance with the License.
 
7
 *  You may obtain a copy of the License at
 
8
 *
 
9
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
 *
 
11
 *  Unless required by applicable law or agreed to in writing, software
 
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing permissions and
 
15
 *  limitations under the License.
 
16
 *
 
17
 *=========================================================================*/
 
18
#if defined(_MSC_VER)
 
19
#pragma warning ( disable : 4786 )
 
20
#endif
 
21
 
 
22
 
 
23
#include "sitkImage.h"
 
24
#include "sitkCurvatureFlowImageFilter.h"
 
25
#include "sitkConnectedThresholdImageFilter.h"
 
26
#include "sitkImageFileReader.h"
 
27
#include "sitkImageFileWriter.h"
 
28
 
 
29
#include <stdlib.h>
 
30
#include <iostream>
 
31
 
 
32
namespace sitk = itk::simple;
 
33
 
 
34
int main( int argc, char *argv[])
 
35
{
 
36
 
 
37
  //
 
38
  // Check command line parameters
 
39
  //
 
40
  if( argc < 7 )
 
41
    {
 
42
    std::cerr << "Missing Parameters " << std::endl;
 
43
    std::cerr << "Usage: " << argv[0];
 
44
    std::cerr << " inputImage outputImage lowerThreshold upperThreshold seedX seedY [seed2X seed2Y ... ]" << std::endl;
 
45
    return 1;
 
46
    }
 
47
 
 
48
 
 
49
  //
 
50
  // Read the image
 
51
  //
 
52
 
 
53
  sitk::ImageFileReader reader;
 
54
  reader.SetFileName( std::string( argv[1] ) );
 
55
  sitk::Image image = reader.Execute();
 
56
 
 
57
 
 
58
  //
 
59
  // Blur using CurvatureFlowImageFilter
 
60
  //
 
61
  sitk::CurvatureFlowImageFilter blurFilter;
 
62
  blurFilter.SetNumberOfIterations( 5 );
 
63
  blurFilter.SetTimeStep( 0.125 );
 
64
  image = blurFilter.Execute( image );
 
65
 
 
66
 
 
67
  //
 
68
  // Set up ConnectedThresholdImageFilter for segmentation
 
69
  //
 
70
  sitk::ConnectedThresholdImageFilter segmentationFilter;
 
71
  segmentationFilter.SetLower( atof( argv[3] ) );
 
72
  segmentationFilter.SetUpper( atof( argv[4] ) );
 
73
  segmentationFilter.SetReplaceValue( 255 );
 
74
 
 
75
  for (int i = 5; i+1 < argc; i+=2)
 
76
    {
 
77
    std::vector<unsigned int> seed;
 
78
    seed.push_back(atoi(argv[i]));
 
79
    seed.push_back(atoi(argv[i+1]));
 
80
    segmentationFilter.AddSeed(seed);
 
81
    std::cout << "Adding a seed at: ";
 
82
    for( unsigned int j = 0; j < seed.size(); ++j )
 
83
      {
 
84
      std::cout << seed[j] << " ";
 
85
      }
 
86
    std::cout << std::endl;
 
87
    }
 
88
 
 
89
  sitk::Image outImage = segmentationFilter.Execute(image);
 
90
 
 
91
 
 
92
  //
 
93
  // Write out the resulting file
 
94
  //
 
95
  sitk::ImageFileWriter writer;
 
96
  writer.SetFileName( std::string( argv[2] ) );
 
97
  writer.Execute(outImage);
 
98
 
 
99
  return 0;
 
100
}