|
a |
|
b/gaussian.py |
|
|
1 |
import sys |
|
|
2 |
import cv2 as cv |
|
|
3 |
import numpy as np |
|
|
4 |
from matplotlib import pyplot as plt |
|
|
5 |
|
|
|
6 |
ddepth = cv.CV_16S |
|
|
7 |
kernel_size = 3 |
|
|
8 |
# [variables] |
|
|
9 |
# [load] |
|
|
10 |
src = cv.imread(r'C://Users/Shubhi/Desktop/Projects/Kidney-Stone-Detection-IP/images/image2.jpg', cv.IMREAD_COLOR) # Load an image |
|
|
11 |
# Check if image is loaded fine |
|
|
12 |
# [load] |
|
|
13 |
# [reduce_noise] |
|
|
14 |
# Remove noise by blurring with a Gaussian filter |
|
|
15 |
src = cv.GaussianBlur(src, (3, 3), 0) |
|
|
16 |
# [reduce_noise] |
|
|
17 |
# [convert_to_gray] |
|
|
18 |
# Convert the image to grayscale |
|
|
19 |
src_gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY) |
|
|
20 |
# [convert_to_gray] |
|
|
21 |
# Create Window |
|
|
22 |
# [laplacian] |
|
|
23 |
# Apply Laplace function |
|
|
24 |
dst = cv.Laplacian(src_gray, ddepth, kernel_size) |
|
|
25 |
# [laplacian] |
|
|
26 |
# [convert] |
|
|
27 |
# converting back to uint8 |
|
|
28 |
abs_dst = cv.convertScaleAbs(dst) |
|
|
29 |
# [convert] |
|
|
30 |
# [display] |
|
|
31 |
plt.subplot(121),plt.imshow(src, cmap = 'gray') |
|
|
32 |
plt.title('Input Image'), plt.xticks([]), plt.yticks([]) |
|
|
33 |
plt.subplot(122),plt.imshow(abs_dst, cmap = 'gray') |
|
|
34 |
plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([]) |
|
|
35 |
plt.show() |