File: module2module.py

package info (click to toggle)
insighttoolkit4 4.13.3withdata-dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 489,260 kB
  • sloc: cpp: 557,342; ansic: 146,850; fortran: 34,788; python: 16,572; sh: 2,187; lisp: 2,070; tcl: 993; java: 362; perl: 200; makefile: 129; csh: 81; pascal: 69; xml: 19; ruby: 10
file content (135 lines) | stat: -rw-r--r-- 4,464 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#==========================================================================
#
#   Copyright Insight Software Consortium
#
#   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.
#
#==========================================================================*/

from __future__ import print_function

import itk
import sys

from itk import ITKCommon
from itk import ITKBinaryMathematicalMorphology
from itk import ITKImageStatistics
from itk import ITKSmoothing
from itk import ITKDistanceMap
from itk import ITKImageIntensity
from itk import ITKThresholding
from itk import ITKImageGrid

inputImage = sys.argv[1]
radiusValue = int(sys.argv[2])

PixelType = itk.UC
Dimension = 2
ImageType = itk.Image[PixelType, Dimension]

StructuringElementType = itk.FlatStructuringElement[Dimension]
radius = (radiusValue, radiusValue)
structuringElement = StructuringElementType.Ball(radius)

# create the reader
reader = itk.ImageFileReader[ImageType].New(FileName=inputImage)

sources = []
image = ITKCommon.Image[PixelType, Dimension].New()
region = itk.ImageRegion.x2()
region.SetSize((10, 10))
image.SetRegions(region)
image.Allocate()

sources.append(("ITKCommon", image))

sources.append(("ITKIOImageBase", reader.GetOutput()))

OtsuType = ITKThresholding.OtsuThresholdImageFilter[ImageType, ImageType]
otsu = OtsuType.New(reader)
sources.append(("ITKThresholding", otsu.GetOutput()))

flip = ITKImageGrid.FlipImageFilter[ImageType].New(reader)
sources.append(("ITKImageGrid", flip.GetOutput()))

absFilter = ITKImageIntensity.AbsImageFilter[ImageType, ImageType].New(reader)
sources.append(("ITKImageIntensity", absFilter.GetOutput()))
absFilter.InPlaceOff()

BinaryDilateType = ITKBinaryMathematicalMorphology.BinaryDilateImageFilter[
    ImageType, ImageType, StructuringElementType]
binaryDilateFilter = BinaryDilateType.New()
binaryDilateFilter.SetInput(reader.GetOutput())
binaryDilateFilter.SetKernel(structuringElement)

output = binaryDilateFilter.GetOutput()
sources.append(("ITKBinaryMathematicalMorphology", output))

minmax = ITKImageStatistics.MinimumMaximumImageFilter[ImageType].New(reader)
sources.append(("ITKImageStatistics", minmax.GetOutput()))

median = ITKSmoothing.MedianImageFilter[ImageType, ImageType].New(reader)
sources.append(("ITKSmoothing", median.GetOutput()))

distance = ITKDistanceMap.DanielssonDistanceMapImageFilter[
    ImageType, ImageType].New(reader)
sources.append(("ITKDistanceMap", distance.GetOutput()))


dests = []

dotsu = OtsuType.New()
dests.append(("ITKThresholding", dotsu))

dflip = ITKImageGrid.FlipImageFilter[ImageType].New()
dests.append(("ITKImageGrid", dflip))

dabs = ITKImageIntensity.AbsImageFilter[ImageType, ImageType].New()
dests.append(("ITKImageIntensity", dabs))

dbinaryDilateFilter = BinaryDilateType.New()
dbinaryDilateFilter.SetKernel(structuringElement)
dests.append(("ITKBinaryMathematicalMorphology", dbinaryDilateFilter))

dminmax = ITKImageStatistics.MinimumMaximumImageFilter[ImageType].New()
dests.append(("ITKImageStatistics", dminmax))

dmedian = ITKSmoothing.MedianImageFilter[ImageType, ImageType].New()
dests.append(("ITKSmoothing", dmedian))

DistanceMapType = ITKDistanceMap.DanielssonDistanceMapImageFilter[ImageType,
                                                                  ImageType]
ddistance = DistanceMapType.New()
dests.append(("ITKDistanceMap", ddistance))


nb = 0
failList = []
for sourceName, source in sources:
    for destinationName, destination in dests:
        nb += 1
        destination.SetInput(source)
        try:
            destination.UpdateLargestPossibleRegion()
            print("%s -> %s pass" % (sourceName, destinationName))
        except RuntimeError as e:
            print("%s -> %s fail" % (sourceName, destinationName))
            print(e)
            failList.append((sourceName, destinationName))


print()
print("%i tests succeed" % (nb - len(failList)))
print("%i tests failed" % len(failList))

sys.exit(len(failList))