-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Adding python sample for ConvolveImageWithKernel
- Loading branch information
1 parent
18a99c7
commit 94a3211
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,41 @@ | ||
import itk | ||
import numpy as np | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Convolve Image With Kernel") | ||
parser.add_argument("input_image") | ||
parser.add_argument("width", type=int) | ||
args = parser.parse_args() | ||
|
||
PixelType = itk.F | ||
|
||
# Read Image in float data type | ||
inputImage = itk.imread(args.input_image, PixelType) | ||
|
||
width = 10 | ||
if args.width: | ||
width = args.width | ||
|
||
|
||
def CreateSmoothKernel(width): | ||
return np.ones([width, width], "float32") / (width * width) | ||
|
||
|
||
kernel = CreateSmoothKernel(width) | ||
kernel_image = itk.image_from_array(kernel) | ||
|
||
# Convolve image with kernel. | ||
filteredImage = itk.convolution_image_filter(inputImage, kernel_image=kernel_image) | ||
|
||
# Write the output Image | ||
itk.imwrite("ConvolveImageWithKernelPython.png", filteredImage) | ||
|
||
# Visualize the result using matplotlib | ||
import matplotlib.pyplot as plt | ||
|
||
plot_image = np.concatenate((inputImage, filteredImage), axis=1) | ||
plt.imshow(plot_image) | ||
plt.title("Visualize using Matplotlib, Kernel width = " + str(width)) | ||
plt.show(block=False) | ||
plt.pause(3) | ||
plt.close() |
This file contains 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
1 change: 1 addition & 0 deletions
1
src/Filtering/Convolution/ConvolveImageWithKernel/MatplotlibVisualizeConvolution.png.sha512
This file contains 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 @@ | ||
082d1d49439879f93946e39675c62a6732fbb1d17aeb7ecbc63c6ca7e350b34416d3764c355e4c1c00583fd8231eb79f01cc6c618d5cda7eee8a267df64db7a3 |