import
numpy as np
from
scipy
import
signal
from
skimage
import
data,img_as_float,color
from
matplotlib
import
pyplot as plt
plt.rcParams[
'font.sans-serif'
]
=
[
'SimHei'
]
def
correl2d(img,window):
s
=
signal.correlate2d(img,window,mode
=
'same'
,boundary
=
'fill'
)
return
s
img1
=
data.astronaut()
img
=
img_as_float(color.rgb2gray(img1))
window
=
np.ones((
5
,
5
))
/
(
5
*
*
2
)
img_blur
=
correl2d(img,window)
img_edge
=
img
-
img_blur
c
=
1
img_enhance
=
img
+
c
*
img_edge
plt.subplot(
221
),plt.title(
'原图'
),plt.imshow(img,cmap
=
'gray'
)
plt.subplot(
222
),plt.title(
'模糊图像'
),plt.imshow(img_blur,cmap
=
'gray'
)
plt.subplot(
223
),plt.title(
'差值图像'
),plt.imshow(img_edge,cmap
=
'gray'
)
plt.subplot(
224
),plt.title(
'锐化增强图像'
),plt.imshow(img_enhance,vmin
=
0
,vmax
=
1
,cmap
=
'gray'
)
plt.show()