Add 6
This commit is contained in:
1 parent
e65363405b
commit
560e271fd2
6 files changed
+108
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import cv2 as cv
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
|
||||
img = cv.imread(r"img\wirebond-mask.tif", cv.IMREAD_GRAYSCALE)
|
||||
_, img_binary = cv.threshold(img, 128, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
|
||||
plt.figure()
|
||||
plt.subplot(141)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_binary, cmap="gray")
|
||||
plt.title("原图像")
|
||||
i = 1
|
||||
for kernelSize in [11, 15, 45]:
|
||||
kernel = cv.getStructuringElement(cv.MORPH_RECT, (kernelSize, kernelSize))
|
||||
img_result = cv.erode(img_binary, kernel, iterations=1)
|
||||
i += 1
|
||||
plt.subplot(140 + i)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_result, cmap="gray")
|
||||
plt.title(f"{kernelSize}×{kernelSize}")
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,26 @@
|
||||
import cv2 as cv
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
|
||||
img = cv.imread(r"6\2.png", cv.IMREAD_GRAYSCALE)
|
||||
_, img_binary = cv.threshold(img, 128, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
|
||||
kernelSize = 40
|
||||
kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (kernelSize, kernelSize))
|
||||
img_open = cv.morphologyEx(img_binary, cv.MORPH_OPEN, kernel)
|
||||
img_close = cv.morphologyEx(img_binary, cv.MORPH_CLOSE, kernel)
|
||||
plt.figure()
|
||||
plt.subplot(131)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_binary, cmap="gray")
|
||||
plt.title("待处理的原图像")
|
||||
plt.subplot(132)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_open, cmap="gray")
|
||||
plt.title("开运算的结果")
|
||||
plt.subplot(133)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_close, cmap="gray")
|
||||
plt.title("闭运算的结果")
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,36 @@
|
||||
import cv2 as cv
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
|
||||
img = cv.imread(r"6\3.png", cv.IMREAD_GRAYSCALE)
|
||||
_, img_binary = cv.threshold(img, 128, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
|
||||
kernelSize = 130
|
||||
kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (kernelSize, kernelSize))
|
||||
img_dilate = cv.dilate(img_binary, kernel, iterations=1)
|
||||
img_erode = cv.erode(img_binary, kernel, iterations=1)
|
||||
img_open = cv.morphologyEx(img_binary, cv.MORPH_OPEN, kernel)
|
||||
img_close = cv.morphologyEx(img_binary, cv.MORPH_CLOSE, kernel)
|
||||
plt.figure()
|
||||
plt.subplot(151)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_binary, cmap="gray")
|
||||
plt.title("二值图像")
|
||||
plt.subplot(152)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_dilate, cmap="gray")
|
||||
plt.title("膨胀运算结果")
|
||||
plt.subplot(153)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_erode, cmap="gray")
|
||||
plt.title("腐蚀运算结果")
|
||||
plt.subplot(154)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_open, cmap="gray")
|
||||
plt.title("开运算结果")
|
||||
plt.subplot(155)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_close, cmap="gray")
|
||||
plt.title("闭运算结果")
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,23 @@
|
||||
import cv2 as cv
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimSun"]
|
||||
|
||||
img = cv.imread(r"img\mapleleaf.tif", cv.IMREAD_GRAYSCALE)
|
||||
_, img_binary = cv.threshold(img, 128, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
|
||||
plt.figure()
|
||||
plt.subplot(141)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_binary, cmap="gray")
|
||||
plt.title("原图像")
|
||||
i = 1
|
||||
for kernelSize in [3, 9, 15]:
|
||||
kernel = cv.getStructuringElement(cv.MORPH_RECT, (kernelSize, kernelSize))
|
||||
img_result = cv.morphologyEx(img_binary, cv.MORPH_GRADIENT, kernel)
|
||||
i += 1
|
||||
plt.subplot(140 + i)
|
||||
plt.axis("off")
|
||||
plt.imshow(img_result, cmap="gray")
|
||||
plt.title(f"{kernelSize}×{kernelSize}")
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
Reference in new issue
Block a user