ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Filtering/ImageStatistics/AdaptiveHistogramEqualizationImageFilter/Code.py
1 #!/usr/bin/env python
2 
3 # ==========================================================================
4 #
5 # Copyright NumFOCUS
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License")
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # https://www.apache.org/licenses/LICENSE-2.0.txt
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 # ==========================================================================
20 
21 import itk
22 import argparse
23 
24 parser = argparse.ArgumentParser(
25  description="Adaptive Histogram Equalization Image Filter."
26 )
27 parser.add_argument("input_image")
28 parser.add_argument("output_image")
29 parser.add_argument("alpha", type=float)
30 parser.add_argument("beta", type=float)
31 parser.add_argument("radius", type=int)
32 args = parser.parse_args()
33 
34 Dimension = 2
35 
36 PixelType = itk.ctype("unsigned char")
37 ImageType = itk.Image[PixelType, Dimension]
38 
39 reader = itk.ImageFileReader[ImageType].New()
40 reader.SetFileName(args.input_image)
41 
42 histogramEqualization = itk.AdaptiveHistogramEqualizationImageFilter.New(reader)
43 histogramEqualization.SetAlpha(args.alpha)
44 histogramEqualization.SetBeta(args.beta)
45 
46 radius = itk.Size[Dimension]()
47 radius.Fill(args.radius)
48 histogramEqualization.SetRadius(radius)
49 
50 itk.imwrite(histogramEqualization, args.output_image)
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
itk::AdaptiveHistogramEqualizationImageFilter::New
static Pointer New()
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()