赞
踩
这个在MATLAB叫点乘,内积不是这个。而且内积是欧几里得空间定义的,矩阵的标准内积
121 75 78
24 204 113
154 104 235
几个取平均
算法里说了nXn的滤波一般是奇数
- img = cv2. imread('lenaNoise. png')
- cv2. imshow('img', img)
- cv2. waitKey(0)
- cv2.destroyAllWindows()
- #均值滤波
- #简单的平均卷积操作
- blur = cv2.blur(img, (3, 3))
- cv2.imshow('blur', blur)
- cv2. waitKey(0)
- cv2.destroyAllWindows()
- #方框滤波
- #基本和均值一样,可以选择归一化
- box = cv2. boxFilter(img,-1,(3,3), normalize=True)
- cv2. imshow('box', box)
- cv2. waitKey(0)
- cv2.destroyAllWindows()
- #方框滤波
- #基本和均值一样,可以选择归一化,容易越界
- #越界就是全变为255
- box = cv2. boxFilter(img,-1,(3,3), normalize=False)
- cv2. imshow('box', box)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
- #高斯滤波
- #高斯模糊的卷积核里的数值是满足高斯分布,相当于更重视中间的
- aussian = cv2. GaussianBlur(img,(5,5),1)
- #1表示权重,就是选取的那个最重要的值,离那个值越远,越不重要,所以比重就越低
- cv2. imshow('aussian', aussian)
- cv2. waitKey(0)
- cv2. destroyAllWindows
- #中值滤波
- #相当于用中值代替
- median = cv2.medianBlur(img, 5)#中值滤波
- cv2. imshow('median', median)
- cv2.waitKey(0)
- cv2. destroyAllWindows()
中值滤波除噪点确实很强,但代价是图像细节损失的最为严重
- #展示所有的
- res = np. hstack((blur. aussian. median))
- #可以换成vstack
- cv2. imshow(' meaian vs average'. res)
- cv2. waitKey(0)
- cv2. destroyAHWindows()
阈值吃力刚刚好啊bushi It is useful for removing small white noises
不同的核大小腐蚀程度不一样
- img = cv2. imreadC dige. png')
- cv2. imshowC itng'. img)
- cv2. waiiKey(O)
- cv2. destroyAllWindows ()
-
-
- kernel = np. ones ((3,3), np. uint8)
- erosion = cv2. erode(img. kernel. iterations= 2)
- cv2. imshow('erosion', erosion)
- cv2.waitKey(0)
- cv2. destroyAllWindows()
-
-
- pie = cv2. imread('pie. png')
- cv2. imshow('pie'. pie)
- cv2. waixKey(0)
- cv2. destroyA11Windows()
-
-
- #集合
- kernel = np. ones ((30,30), np. uint8)
- erosion_l = cv2. erode(pie, kernel, iterations = 1)
- erosion_2 = cv2. erode(pie, kernel, iterations = 2)
- erosion_3 = cv2. erode(pie, kernel, iterations = 3)
- res = np. hstack((erosion_l, erosion_2,erosion_3))
- cv2. imshow('res', res)
- cv2.waitKey(0)
- cv2. destroyAllWindows ()
kernel到底是什么?
- img = cv2. inread ('dige. png')
- cv2. imshow('img'. img)
- cv2.waitKey(0)
- cv2. destroyAllWindows()
-
-
-
- kernel = np. ones((3. 3),np. uint8)
- erosion = cv2. erode(img, kernel, iterations = 1)
- cv2. imshow(' erosion', erosion)
- cv2. waitKey(0)
- cv2. desrroyAllWindows()
-
-
- pie = cv2. imread (' pie. png')
- cv2. imshow('pie', pie)
- cv2. waitKey(0)
- cv2. destroyAllWindows()
-
-
- kernel = np. ones((30.30). np. uint8)
- erosion_l = cv2. erode(pie, kernel, iterations = 1)
- erosion_2 = cv2. erode(pie, kernel, iterations = 2)
- erosion_3 = cv2. erode(pie, kernel, iterations = 3)
- res = np. hstack((erosion_l, erosion_2, erosion_3))
- cv2. imshow('res', res)
- cv2.waitKey(0)
- cv2. destroyAllWindows()
kernel核矩阵越小,越近圆
把腐蚀膨胀合在一起了,用来提取前景或者提取噪音 huh?
- #开:先腐 ,再 胀
- img = cv2. imread(' dige. png')
- kernel = np. ones((5.5), np. uint8)
- opening = cv2. morphologyExCimg. cv2. MORHi.WEN. kernel)
- cv2. imshow('opening'. opening)
- cv2. waitKey(0)
- cv2. destroyAllWindows()
-
-
- #:先房底.再用蚀
- img = cv2. imread('dige. png')
- kernel = np. ones ((5.5). np. uint8)
- closing = cv2. morphologyExdmg. cv2. MORPH_CLOSE, kernel)
- cv2. imshow('closing',closing)
- cv2. waitKey(O)
- cv2. destroyAllWindows()
感觉地方感觉有点问题。膨胀减掉腐蚀的图像应该和梯度操作的结果不太一样。最后的边界的宽度差异很大。梯度 = 原图 - 腐蚀.
- #梯度=影胀-腐蚀?
- pie = cv2. imread('pie. png')
- kernel = np. ones((7,7), np. uint8)
- dilate = cv2. di late(pie, kernel, iterations = 5)
- erosion = cv2. erode(pie, kernel.iterations = 5)
-
- res = np. hstack((dilate. erosion))
-
- cv2. imshow('res', res)
- cv2.wairKey(0)
- cv2. destroyAllWindows()
-
-
- gradient = cv2. morphologyEx(pie,cv2. MORPH_GRADIENT,kernel)
-
- cv2. imshow('gradient', gradient)
- cv2. waitKey(0)
- cv2. destroyAllWindows()
剩下毛边和剩下原轮廓
- #礼帽=原始输入-开运算结果
- #黑帽=闭运算-原始输入
-
- #礼帽
- lag = cv2. imread('dige. png')
- tophar = cv2. morphologyEx(img. cv2. MORPH_TOPHAT. kernel)
- cv2. imsho,(' tophat'. tophat)
- cv2. waitKey(O)
- cv2. destroyAllWindows()
-
-
- #黑帽
- img = cv2. imread(' dige. png')
- blackhat = cv2. morphologyEx(img, cv2. MORPH_BLAG{HAT. kernel)
- cv2. imshow('blackhat '. blackhat )
- cv2.waitKey(0)
- cv2. destroyAllWindows()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。