From df23dbb67faf7fa4d04232df773313755d7d3eee Mon Sep 17 00:00:00 2001 From: pyhqos7bg Date: Thu, 30 May 2024 15:03:47 +0800 Subject: [PATCH] ADD file via upload --- 腐蚀图像.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 腐蚀图像.py diff --git a/腐蚀图像.py b/腐蚀图像.py new file mode 100644 index 0000000..bdd69c5 --- /dev/null +++ b/腐蚀图像.py @@ -0,0 +1,17 @@ +import numpy as np +import cv2 +import matplotlib.pyplot as plt +img = cv2.imread('./images/pill_002.png') +gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) + +ret,thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) +plt.subplot(221),plt.imshow(thresh,cmap='gray'),plt.title('thresh') + +# noise removal +kernel = np.ones((3,3),np.uint8) +opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel,iterations=2) +sure_bg = cv2.dilate(opening,kernel,iterations=1) +plt.subplot(222),plt.imshow(sure_bg,cmap='gray'),plt.title('sure_bg') + + +plt.show()