Skip to content

Commit

Permalink
ENH: Revive ExtractContoursFromImage as SimpleContourExtractor
Browse files Browse the repository at this point in the history
The example was commented out since the initial import commit:

ENH: Adding media wiki examples to sphinx examples
a82f59e
  • Loading branch information
dzenanz committed Nov 11, 2024
1 parent e8f8369 commit 77eb9d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/Filtering/ImageFeature/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ add_example(ApplyAFilterOnlyToASpecifiedImageRegion)

add_example(ApplyAFilterToASpecifiedRegionOfAnImage)

add_example(SimpleContourExtractor)

add_example(ZeroCrossingBasedEdgeDecor)
compare_to_baseline(EXAMPLE_NAME ZeroCrossingBasedEdgeDecor
BASELINE_PREFIX ZeroCrossingBasedEdgeDecor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16.3)

project(ExtractContoursFromImage)
project(SimpleContourExtractor)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
Expand All @@ -15,11 +15,11 @@ install(TARGETS ${PROJECT_NAME}
)

install(FILES Code.cxx CMakeLists.txt
DESTINATION share/ITKSphinxExamples/Code/Filtering/ImageFeature/ExtractContoursFromImage/
DESTINATION share/ITKSphinxExamples/Code/Filtering/ImageFeature/SimpleContourExtractor/
COMPONENT Code
)


enable_testing()
add_test(NAME ExtractContoursFromImageTest
add_test(NAME SimpleContourExtractorTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME})
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@
* limitations under the License.
*
*=========================================================================*/
/*

#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkSimpleContourExtractorImageFilter.h"
#include "itkImageRegionIterator.h"

using UnsignedCharImageType = itk::Image<unsigned char, 2>;

static void CreateImage(UnsignedCharImageType::Pointer image);
static void
CreateImage(UnsignedCharImageType::Pointer image);

int main()
int
main()
{
auto image = UnsignedCharImageType::New();
CreateImage(image);

using SimpleContourExtractorImageFilterType = itk::SimpleContourExtractorImageFilter <UnsignedCharImageType, UnsignedCharImageType>;
SimpleContourExtractorImageFilterType::Pointer contourFilter
= SimpleContourExtractorImageFilterType::New();
using SimpleContourExtractorImageFilterType =
itk::SimpleContourExtractorImageFilter<UnsignedCharImageType, UnsignedCharImageType>;
SimpleContourExtractorImageFilterType::Pointer contourFilter = SimpleContourExtractorImageFilterType::New();
contourFilter->SetInput(image);
contourFilter->Update();

using WriterType = itk::ImageFileWriter< UnsignedCharImageType >;
using WriterType = itk::ImageFileWriter<UnsignedCharImageType>;
auto writer = WriterType::New();
writer->SetFileName("output.png");
writer->SetInput(contourFilter->GetOutput());
Expand All @@ -45,38 +47,39 @@ int main()
return EXIT_SUCCESS;
}

void CreateImage(UnsignedCharImageType::Pointer image)
void
CreateImage(UnsignedCharImageType::Pointer image)
{
// Create an image
itk::Index<2> start{};

itk::Size<2> size;
size.Fill(100);

itk::ImageRegion<2> region(start,size);
itk::ImageRegion<2> region(start, size);

image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);

// Create a line pixels
for(unsigned int i = 40; i < 60; ++i)
{
for (unsigned int i = 40; i < 60; ++i)
{
itk::Index<2> pixel;
pixel.Fill(i);
image->SetPixel(pixel, 255);
}
}

// Create another line of pixels
for(unsigned int i = 10; i < 20; ++i)
{
for (unsigned int i = 10; i < 20; ++i)
{
itk::Index<2> pixel;
pixel[0] = 10;
pixel[1] = i;
image->SetPixel(pixel, 255);
}
}

using WriterType = itk::ImageFileWriter< UnsignedCharImageType >;
using WriterType = itk::ImageFileWriter<UnsignedCharImageType>;
auto writer = WriterType::New();
writer->SetFileName("input.png");
writer->SetInput(image);
Expand Down

0 comments on commit 77eb9d8

Please sign in to comment.