|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| This example creates a black image of a 3x3 square. It then uses a flood fill iterator to visit the pixels in this white region (specified by a seed point) and marks them with increasing brightnesses to convey the visit order. | | This is a duplicate of this: |
| | | http://www.itk.org/Wiki/ITK/Examples/WishList/Iterators/FloodFilledImageFunctionConditionalIterator |
| ==FloodFillIterator.cxx==
| |
| <source lang="cpp">
| |
| #include "itkImage.h"
| |
| #include "itkImageFileWriter.h"
| |
| #include "itkFloodFilledImageFunctionConditionalIterator.h"
| |
| #include "itkBinaryThresholdImageFunction.h"
| |
| #include "itkImageFileWriter.h"
| |
| | |
| #include "QuickView.h"
| |
| | |
| typedef itk::Image< unsigned char, 2 > ImageType;
| |
| | |
| void CreateImage(ImageType::Pointer image);
| |
| | |
| int main( int argc, char *argv[])
| |
| {
| |
| ImageType::Pointer image = ImageType::New();
| |
| CreateImage(image);
| |
| | |
| typedef itk::BinaryThresholdImageFunction< ImageType, double > FunctionType;
| |
| FunctionType::Pointer function = FunctionType::New();
| |
| function->SetInputImage(image);
| |
| function->ThresholdAbove(100); // we are looking to capture 255
| |
|
| |
| typedef itk::FloodFilledImageFunctionConditionalIterator< ImageType, FunctionType > IteratorType;
| |
| | |
| itk::Index<2> seed;
| |
| seed[0] = 5;
| |
| seed[1] = 5;
| |
|
| |
| std::vector<itk::Index<2> > seeds;
| |
| seeds.push_back(seed);
| |
|
| |
| IteratorType it (image, function, seeds);
| |
| it.GoToBegin();
| |
|
| |
| unsigned int counter = 0;
| |
| while ( !it.IsAtEnd() )
| |
| {
| |
| it.Set(static_cast<float>(counter) * 25.);
| |
| ++it;
| |
| counter++;
| |
| }
| |
|
| |
| typedef itk::ImageFileWriter< ImageType > WriterType;
| |
| WriterType::Pointer writer = WriterType::New();
| |
| writer->SetFileName("output.png");
| |
| writer->SetInput(image);
| |
| writer->Update();
| |
|
| |
| | |
| ImageType::Pointer originalImage = ImageType::New();
| |
| CreateImage(originalImage);
| |
|
| |
| QuickView viewer;
| |
| viewer.AddImage(originalImage.GetPointer());
| |
| viewer.AddImage(image.GetPointer());
| |
| viewer.Visualize();
| |
| | |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| void CreateImage(ImageType::Pointer image)
| |
| {
| |
| itk::Index<2> start;
| |
| start.Fill(0);
| |
| | |
| itk::Size<2> size;
| |
| size.Fill(10);
| |
| | |
| itk::ImageRegion<2> region(start,size);
| |
| image->SetRegions(region);
| |
| image->Allocate();
| |
| image->FillBuffer(0);
| |
| | |
| // Make a square
| |
| for(unsigned int r = 3; r < 6; r++)
| |
| {
| |
| for(unsigned int c = 3; c < 6; c++)
| |
| {
| |
| itk::Index<2> pixelIndex;
| |
| pixelIndex[0] = r;
| |
| pixelIndex[1] = c;
| |
| | |
| image->SetPixel(pixelIndex, 255);
| |
| }
| |
| }
| |
| }
| |
| </source>
| |
| | |
| ==CMakeLists.txt==
| |
| <source lang="cmake">
| |
| cmake_minimum_required(VERSION 2.6)
| |
| | |
| PROJECT(FloodFilledImageFunctionConditionalIterator)
| |
| | |
| include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue)
| |
| | |
| FIND_PACKAGE(VTK REQUIRED)
| |
| INCLUDE(${VTK_USE_FILE})
| |
| | |
| FIND_PACKAGE(ITK REQUIRED)
| |
| INCLUDE(${ITK_USE_FILE})
| |
| | |
| ADD_EXECUTABLE(FloodFilledImageFunctionConditionalIterator FloodFilledImageFunctionConditionalIterator.cxx /home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx)
| |
| TARGET_LINK_LIBRARIES(FloodFilledImageFunctionConditionalIterator
| |
| vtkHybrid
| |
| ITKIO ITKBasicFilters ITKCommon
| |
| )
| |
| | |
| </source>
| |