-
Notifications
You must be signed in to change notification settings - Fork 69
ENH: Migrate example itkGrayscaleFunctionDilateImageFilter #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jadh4v
wants to merge
4
commits into
InsightSoftwareConsortium:master
Choose a base branch
from
jadh4v:ENH-add-example-itkGrayscaleFunctionDilateImageFilter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
25c20d3
ENH: Migrate example itkGrayscaleFunctionDilateImageFilter
jadh4v 275fede
ENH: Add python code to documentation
jadh4v 5067bf1
COMP: fix documentation build warnings
jadh4v 7de73b9
ENH: Use CID links for external data files instead of SHA512 hashes
dzenanz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Filtering/MathematicalMorphology/DilateUsingFunctionalGrayscale/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
cmake_minimum_required(VERSION 3.16.3) | ||
|
||
project( DilateUsingFunctionalGrayscale ) | ||
|
||
find_package( ITK REQUIRED | ||
COMPONENTS | ||
ITKCommon | ||
ITKIOImageBase | ||
ITKMathematicalMorphology | ||
ITKIOPNG | ||
) | ||
include( ${ITK_USE_FILE} ) | ||
|
||
add_executable( DilateUsingFunctionalGrayscale Code.cxx ) | ||
target_link_libraries( DilateUsingFunctionalGrayscale ${ITK_LIBRARIES} ) | ||
|
||
install( TARGETS DilateUsingFunctionalGrayscale | ||
DESTINATION bin/ITKSphinxExamples/Filtering/MathematicalMorphology | ||
COMPONENT Runtime | ||
) | ||
|
||
install( FILES Code.cxx CMakeLists.txt | ||
DESTINATION share/ITKSphinxExamples/Code/Filtering/MathematicalMorphology/DilateUsingFunctionalGrayscale | ||
COMPONENT Code | ||
) | ||
|
||
enable_testing() | ||
add_test( NAME DilateUsingFunctionalGrayscaleTest | ||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/DilateUsingFunctionalGrayscale | ||
${CMAKE_CURRENT_BINARY_DIR}/cthead1.png | ||
Output.png | ||
5 | ||
) | ||
|
||
if( ITK_WRAP_PYTHON ) | ||
add_test( NAME DilateUsingFunctionalGrayscaleTestPython | ||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py | ||
${CMAKE_CURRENT_BINARY_DIR}/cthead1.png | ||
OutputPython.png | ||
5 | ||
) | ||
endif() |
79 changes: 79 additions & 0 deletions
79
src/Filtering/MathematicalMorphology/DilateUsingFunctionalGrayscale/Code.cxx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*========================================================================= | ||
* | ||
* Copyright NumFOCUS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*=========================================================================*/ | ||
|
||
#include "itkFlatStructuringElement.h" | ||
#include "itkGrayscaleFunctionDilateImageFilter.h" | ||
#include "itkImage.h" | ||
#include "itkImageFileReader.h" | ||
#include "itkImageFileWriter.h" | ||
|
||
int | ||
main(int argc, char * argv[]) | ||
{ | ||
if (argc < 4) | ||
{ | ||
std::cerr << "Usage: " << std::endl; | ||
std::cerr << argv[0] << " <inputImage> <outputImage> <radius>"; | ||
std::cerr << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
constexpr unsigned int Dimension = 2; | ||
using PixelType = unsigned char; | ||
|
||
using ImageType = itk::Image<PixelType, Dimension>; | ||
|
||
using ReaderType = itk::ImageFileReader<ImageType>; | ||
using WriterType = itk::ImageFileWriter<ImageType>; | ||
|
||
auto reader = ReaderType::New(); | ||
auto writer = WriterType::New(); | ||
|
||
const char * inputImage = argv[1]; | ||
const char * outputImage = argv[2]; | ||
const unsigned int radiusValue = std::stoi(argv[3]); | ||
|
||
reader->SetFileName(inputImage); | ||
writer->SetFileName(outputImage); | ||
|
||
using StructuringElementType = itk::FlatStructuringElement<Dimension>; | ||
StructuringElementType::RadiusType radius; | ||
radius.Fill(radiusValue); | ||
StructuringElementType structuringElement = StructuringElementType::Ball(radius); | ||
|
||
using FilterType = itk::GrayscaleFunctionDilateImageFilter<ImageType, ImageType, StructuringElementType>; | ||
|
||
auto filter = FilterType::New(); | ||
|
||
filter->SetKernel(structuringElement); | ||
|
||
filter->SetInput(reader->GetOutput()); | ||
writer->SetInput(filter->GetOutput()); | ||
|
||
try | ||
{ | ||
writer->Update(); | ||
} | ||
catch (const itk::ExceptionObject & excp) | ||
{ | ||
std::cerr << excp << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Filtering/MathematicalMorphology/DilateUsingFunctionalGrayscale/Code.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright NumFOCUS | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import itk | ||
import argparse | ||
|
||
itk.auto_progress(2) | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Dilate an image using functional grayscale morphology." | ||
) | ||
parser.add_argument("input_image") | ||
parser.add_argument("output_image") | ||
parser.add_argument("radius", type=int) | ||
args = parser.parse_args() | ||
|
||
PixelType = itk.UC | ||
Dimension = 2 | ||
|
||
ImageType = itk.Image[PixelType, Dimension] | ||
|
||
reader = itk.ImageFileReader[ImageType].New() | ||
reader.SetFileName(args.input_image) | ||
|
||
StructuringElementType = itk.FlatStructuringElement[Dimension] | ||
structuringElement = StructuringElementType.Ball(args.radius) | ||
|
||
grayscaleFilter = itk.GrayscaleFunctionDilateImageFilter[ | ||
ImageType, ImageType, structuringElement | ||
].New() | ||
grayscaleFilter.SetInput(reader.GetOutput()) | ||
grayscaleFilter.SetKernel(structuringElement) | ||
|
||
writer = itk.ImageFileWriter[ImageType].New() | ||
writer.SetFileName(args.output_image) | ||
writer.SetInput(grayscaleFilter.GetOutput()) | ||
|
||
writer.Update() |
60 changes: 60 additions & 0 deletions
60
...ltering/MathematicalMorphology/DilateUsingFunctionalGrayscale/Documentation.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
:name: DilateUsingFunctionalGrayscale | ||
|
||
Dilate a grayscale image using a functional kernel | ||
=================================================== | ||
|
||
.. index:: | ||
single: BinaryBallStructuringElement | ||
single: GrayscaleFunctionDilateImageFilter | ||
pair: mathematical morphology; dilation | ||
|
||
.. seealso:: dilation; erosion | ||
|
||
|
||
Synopsis | ||
-------- | ||
|
||
Dilate an image using functional grayscale morphology. | ||
Function dilation takes the maximum of all the pixels identified by the structuring element plus the structuring element value. | ||
In this example, the white regions are enlarged. | ||
|
||
|
||
|
||
Results | ||
------- | ||
|
||
.. figure:: cthead1.png | ||
:scale: 50% | ||
:alt: Input ct head image. | ||
|
||
Input grayscale image. | ||
|
||
.. figure:: OutputBaseline.png | ||
:scale: 50% | ||
:alt: Dilated output. | ||
|
||
Dilated output. | ||
|
||
|
||
Code | ||
---- | ||
|
||
Python | ||
...... | ||
|
||
.. literalinclude:: Code.py | ||
:language: python | ||
:lines: 1, 16- | ||
|
||
|
||
C++ | ||
... | ||
|
||
.. literalinclude:: Code.cxx | ||
:lines: 18- | ||
|
||
|
||
Classes demonstrated | ||
-------------------- | ||
|
||
.. breathelink:: itk::GrayscaleFunctionDilateImageFilter itk::BinaryBallStructuringElement |
1 change: 1 addition & 0 deletions
1
src/Filtering/MathematicalMorphology/DilateUsingFunctionalGrayscale/OutputBaseline.png.cid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bafkreiaqbnt5phaiaiohrwjfis2bwmqinj5eu4jgnumpfsmviy27nsduoe |
1 change: 1 addition & 0 deletions
1
src/Filtering/MathematicalMorphology/DilateUsingFunctionalGrayscale/cthead1.png.cid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bafkreieilrgrns7xcna5yle2yw3q2wxkl3wn7lp22k4d4pwjhlhwc3ed4u |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.