File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
src/Filtering/Convolution/ConvolveImageWithKernel Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ import itk
2
+ import numpy as np
3
+ import argparse
4
+
5
+ parser = argparse .ArgumentParser (description = "Convolve Image With Kernel" )
6
+ parser .add_argument ("input_image" )
7
+ parser .add_argument ("width" , type = int )
8
+ args = parser .parse_args ()
9
+
10
+ PixelType = itk .F
11
+
12
+ # Read Image in float data type
13
+ inputImage = itk .imread (args .input_image , PixelType )
14
+
15
+ width = 9
16
+ if args .width :
17
+ width = args .width
18
+
19
+ def CreateSmoothKernel (width ):
20
+ return np .ones ([width , width ], 'float32' )
21
+
22
+ kernel = CreateSmoothKernel (width )
23
+ kernel_image = itk .image_from_array (kernel )
24
+
25
+ # Convolve image with kernel.
26
+ filteredImage = itk .convolution_image_filter (inputImage , kernel_image = kernel_image )
27
+
28
+ # Visualize the result using matplotlib
29
+ import matplotlib .pyplot as plt
30
+ plt .imshow (filteredImage )
31
+ plt .show ()
You can’t perform that action at this time.
0 commit comments