物联网 网站开发,小学课程建设网站目标,济南做手机网站,公司制作网站需要这里写目录标题本节的目标背景灰度变换和空间滤波基础本节的目标
了解空间域图像处理的意义#xff0c;以及它与变换域图像处理的区别熟悉灰度变换所有的主要技术了解直方图的意义以及如何操作直方图来增强图像了解空间滤波的原理
import sys
import numpy as np
import cv2…
这里写目录标题本节的目标背景灰度变换和空间滤波基础本节的目标
了解空间域图像处理的意义以及它与变换域图像处理的区别熟悉灰度变换所有的主要技术了解直方图的意义以及如何操作直方图来增强图像了解空间滤波的原理
import sys
import numpy as np
import cv2
import matplotlib
import matplotlib.pyplot as plt
import PIL
from PIL import Imageprint(fPython version: {sys.version})
print(fNumpy version: {np.__version__})
print(fOpencv version: {cv2.__version__})
print(fMatplotlib version: {matplotlib.__version__})
print(fPillow version: {PIL.__version__})Python version: 3.6.12 |Anaconda, Inc.| (default, Sep 9 2020, 00:29:25) [MSC v.1916 64 bit (AMD64)]
Numpy version: 1.16.6
Opencv version: 3.4.1
Matplotlib version: 3.3.2
Pillow version: 8.0.1def normalize(mask):return (mask - mask.min()) / (mask.max() - mask.min() 1e-5)背景
灰度变换和空间滤波基础
g(x,y)T[f(x,y)](3.1)g(x, y) T[f(x, y)] \tag{3.1} g(x,y)T[f(x,y)](3.1)
式中f(x,y)f(x, y)f(x,y)是输入图像 g(x,y)g(x, y)g(x,y)是输出图像TTT是在点(x,y)(x, y)(x,y)的一个邻域上定义的针对f的算子。
最小的邻域大小为1×11\times 11×1 则式(3.1)中的TTT称为灰度也称灰度级或映射变换函数简写为如下 sT(r)(3.2)sT(r) \tag{3.2}sT(r)(3.2)
对比度拉伸
通过将kkk以下的灰度级变暗并将高于kkk的灰度级变亮产生比原图像对比度更高的一幅图像
阈值处理函数
小于kkk的处理为0大于kkk的设置为1产生一幅二级二值图像
# 显示一个图像的3x3邻域
height, width 18, 18
img_ori np.ones([height, width], dtypenp.float)# 图像3x39个像素赋了不同的值以便更好的显示
kernel_h, kernel_w 3, 3
img_kernel np.zeros([kernel_h, kernel_w], dtypenp.float)
for i in range(img_kernel.shape[0]):for j in range(img_kernel.shape[1]):img_kernel[i, j] 0.3 0.1 * i 0.1 * j
img_kernel[kernel_h//2, kernel_w//2] 0.9img_ori[5:5kernel_h, 12:12kernel_w] img_kernelfig plt.figure(figsize(7, 7), numa)
plt.matshow(img_ori, fignuma, cmapgray, vmin0, vmax1)
plt.show()为什么会把Sigmoid函数写在这里
从Sigmoid函数的图像曲线来看与分段线性函数的曲线类似所以在一定程度上可以用来代替对比度拉伸这样就不需要输入太多的参数。当然有时可能也得不到想要的结果需要自己多做实验。
sigmoid函数也是神经网络用得比较多的一个激活函数。
def sigmoid(x, scale):simgoid fuction, return ndarray value [0, 1]param: input x: array like param: input scale: scale of the sigmoid fuction, if 1, then is original sigmoid fuction, if 1, then the values between 0, 1will be less, if scale very low, then become a binary fuction; if 1, then the values between 0, 1 will be more, if scalevery high then become a y xy 1 / (1 np.exp(-x / scale))return y# sigmoid fuction plot
x np.linspace(0, 10, 100)
x1 x - x.max() / 2 # Here shift the 0 to the x center, here is 5, so x1 [-5, 5]
t_stretch sigmoid(x1, 1)
t_binary sigmoid(x1, 0.001)plt.figure(figsize(10, 5))
plt.subplot(121), plt.plot(x, t_stretch), plt.title(sT(r)), plt.ylabel($s_0 T(r_0)$, rotation0)
plt.xlabel(r), plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.plot(x, t_binary), plt.title(sT(r)), plt.ylabel($s_0 T(r_0)$, rotation0)
plt.xlabel(r), plt.xticks([]), plt.yticks([])
plt.tight_layout
plt.show()