Skip to content

Commit c33ac8b

Browse files
Ben Wilsonhjmjohnson
authored andcommitted
ENH: Add AdditiveGaussianNoiseImageFilter example
Add AdditiveGaussianNoiseImageFilter example.
1 parent be1ec47 commit c33ac8b

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/Filtering/ImageFeature/AdditiveGaussianNoiseImageFilter/Code.cxx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*=========================================================================
22
*
3-
* Copyright Insight Software Consortium
3+
* Copyright NumFOCUS
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -15,14 +15,15 @@
1515
* limitations under the License.
1616
*
1717
*=========================================================================*/
18+
1819
#include "itkImage.h"
1920
#include "itkImageFileReader.h"
2021
#include "itkImageFileWriter.h"
2122
#include "itkAdditiveGaussianNoiseImageFilter.h"
2223

2324
int main( int argc, char* argv[] )
2425
{
25-
// Check for proper arguments, if not, explain usage.
26+
// Check for proper arguments; if not, explain usage.
2627
if( argc != 5 )
2728
{
2829
std::cerr << "Usage: "<< std::endl;
@@ -31,19 +32,21 @@ int main( int argc, char* argv[] )
3132
std::cerr << std::endl;
3233
return EXIT_FAILURE;
3334
}
34-
// Initialize and assign user provided variables
35-
const std::string * inputImage = argv[1];
36-
const std::string * outputImage = argv[2];
37-
// get floating point numbers for the Mean and Standard Deviation to perform the algorithm
35+
36+
// Initialize and assign user provided variables
37+
const char * inputImage = argv[1];
38+
const char * outputImage = argv[2];
39+
40+
// Get floating point numbers for the mean and std dev to perform the algorithm
3841
const double mean = std::stod(argv[3]);
3942
const double deviation = std::stod(argv[4]);
4043

4144
constexpr unsigned int Dimension = 2;
42-
// Use unsigned char so file will save to .png
45+
// Use unsigned char to save to PNG format
4346
using PixelType = unsigned char;
4447
using ImageType = itk::Image< PixelType, Dimension >;
4548

46-
// read the old file to be converted
49+
// Read the file to be converted
4750
using ReaderType = itk::ImageFileReader< ImageType >;
4851
ReaderType::Pointer reader = ReaderType::New();
4952
reader->SetFileName( inputImage );
@@ -54,7 +57,7 @@ int main( int argc, char* argv[] )
5457
using FilterType = itk::AdditiveGaussianNoiseImageFilter< ImageType, ImageType >;
5558
FilterType::Pointer filter = FilterType::New();
5659
filter->SetInput( reader->GetOutput() );
57-
filter->SetMean( mean ); // set the mean
60+
filter->SetMean( mean ); // Set the mean
5861
filter->SetStandardDeviation( deviation ); // Set the standard deviation
5962

6063
// Set the writer to save file
@@ -63,7 +66,7 @@ int main( int argc, char* argv[] )
6366
writer->SetFileName( outputImage );
6467
writer->SetInput( filter->GetOutput() );
6568

66-
//Write the output image
69+
// Write the output image
6770
try
6871
{
6972
writer->Update();

src/Filtering/ImageFeature/AdditiveGaussianNoiseImageFilter/Code.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#!/usr/bin/env python
2-
import itk
2+
3+
# Copyright NumFOCUS
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+
317
import sys
18+
import itk
419

520
if len(sys.argv) != 5:
621
print("Usage: " + sys.argv[0] + "< Input Image > < Output Image > [Mean] [Standard Deviation]")
@@ -11,7 +26,7 @@
1126
mean = float(sys.argv[3])
1227
deviation = float(sys.argv[4])
1328

14-
# Unsigned Char for png usage
29+
# Use unsigned char to save to PNG format
1530
InputPixelType = itk.UC
1631
OutputPixelType = itk.UC
1732
Dimension = 2
@@ -29,8 +44,6 @@
2944
AdditiveFilter.SetMean(mean)
3045
AdditiveFilter.SetStandardDeviation(deviation)
3146

32-
33-
3447
WriterType = itk.ImageFileWriter[OutputImageType]
3548
writer = WriterType.New()
3649
writer.SetFileName(outputImage)

0 commit comments

Comments
 (0)