①自己学的C++版本的OpenCV有关滤波(模糊)的操作讲解8--OpenCV:图像基本操作之 模糊 操作__Brooke_的博客-CSDN博客_模糊操作https://blog.csdn.net/zjjaibc/article/details/126554275
②python cv2有关滤波的详细解析(很全,包含导向滤波等。。。)(三)OpenCV-Python学习—图像平滑 - silence_cho - 博客园 (cnblogs.com)https://www.cnblogs.com/silence-cho/p/11027218.html
- def first_filter(img):
- #均值滤波
- img_Blur=cv2.blur(img,(5,5))
- '''
- #高斯滤波
- img_GaussianBlur=cv2.GaussianBlur(img,(7,7),0)
- #高斯双边滤波
- img_bilateralFilter=cv2.bilateralFilter(img,40,75,75)
- '''
- return img, img_Blur
- #四周全黑
- def black(img):
- rows,cols=img.shape
- for i in range(rows):
- img[i][0]=0
- img[i][cols-1]=0
- for j in range(cols):
- img[0][j]=0
- img[rows-1][j]=0
- return img
- def neighbours(x, y, image):
- img = image
- x_1, y_1, x1, y1 = x - 1, y - 1, x + 1, y + 1
- return [img[x_1][y], img[x_1][y1], img[x][y1], img[x1][y1], # P2,P3,P4,P5
- img[x1][y], img[x1][y_1], img[x][y_1], img[x_1][y_1]] # P6,P7,P8,P9
-
- def findBurr(img,i,j,q):
- if q.full():
- while(not q.empty()):
- index=q.get()
- img[index[0]][index[1]]=1
- # print(q.empty())
- return img
- else:
- n = neighbours(i, j, img)
- if sum(n) > 1:
- return img
- else:
- if sum(n) == 0:
- img[i][j] = 0
- return img
- else:
- q.put([i, j])
- img[i][j] = 0
- for x in range(i - 1, i + 2):
- for y in range(j - 1, j + 2):
- if img[x][y] == 1:
- i = x
- j = y
- img=findBurr(img,i,j,q)
- return img
- #细化的毛刺去除
- def removeBurr(img):
- rows,cols=img.shape
- # print(rows,cols)
- thresh=25
- q = Queue(thresh)
- for i in range(1,rows-1):
- for j in range(1,cols-1):
- # print(img[i][j])
- # print(i,j)
- if img[i][j]==1:
- img=findBurr(img,i,j,q)
- while (not (q.empty())):
- q.get()
- img = black(img)
- return img