1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkHardConnectedComponentImageFilterTest.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkHardConnectedComponentImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkFilterWatcher.h"
const int HEIGHT = 20;
const int WIDTH = 20;
int itkHardConnectedComponentImageFilterTest(int, char* [] )
{
typedef itk::Image<bool,2> InputImageType;
typedef itk::Image<unsigned short,2> OutputImageType;
typedef InputImageType::IndexType IndexType;
itk::HardConnectedComponentImageFilter<InputImageType, OutputImageType>::Pointer
filter = itk::HardConnectedComponentImageFilter<InputImageType, OutputImageType>::New();
InputImageType::Pointer inputimg = InputImageType::New();
IndexType index;
index.Fill(0);
InputImageType::RegionType region;
itk::Size<2> sz;
sz[0] = WIDTH;
sz[1] = HEIGHT;
region.SetSize(sz);
region.SetIndex(index);
inputimg->SetLargestPossibleRegion( region );
inputimg->SetBufferedRegion( region );
inputimg->SetRequestedRegion( region );
inputimg->Allocate();
int row, col;
IndexType myIndex;
for(row = 0;row<20;row++)
{
for(col = 0;col < 20;col++)
{
myIndex[1] = row;
myIndex[0] = col;
inputimg->SetPixel(myIndex,false);
}
}
for(row = 0;row<15;row++)
{
for(col = 0;col<20;col++)
{
myIndex[1] = row;
myIndex[0] = col;
inputimg->SetPixel(myIndex,true);
}
}
for(row = 0;row<10;row++)
{
for(col = 5;col<15;col++)
{
myIndex[1] = row;
myIndex[0] = col;
inputimg->SetPixel(myIndex,false);
}
}
for(row = 0;row<7;row++)
{
for(col = 7;col<12;col++)
{
myIndex[1] = row;
myIndex[0] = col;
inputimg->SetPixel(myIndex,true);
}
}
//InputImageType::IndexType Seed = {10,2};
FilterWatcher watcher(filter);
filter->SetInput(inputimg);
//filter->SetObjectSeed(Seed);
filter->Update();
typedef itk::ImageRegionIterator<InputImageType> inputIterator;
inputIterator it = inputIterator(inputimg, region);
std::cout << "Input Image" << std::endl;
it.GoToBegin();
for(int i = 0;i < HEIGHT*WIDTH; i++)
{
if((i%WIDTH) == 0)
{
std::cout<<std::endl;
}
std::cout << ( it.Get() ? 1 : 0 );
++it;
}
std::cout<<std::endl;
typedef itk::ImageRegionIterator<OutputImageType> outputIterator;
outputIterator ot = outputIterator(filter->GetOutput(), region);
std::cout << std::endl << "Output Image" << std::endl;
ot.GoToBegin();
for(int i = 0;i < HEIGHT*WIDTH; i++)
{
if((i%WIDTH) == 0)
{
std::cout<<std::endl;
}
std::cout<<ot.Get();
++ot;
}
std::cout<<std::endl;
return EXIT_SUCCESS;
}
|