在下面的图片中,有一些区域非常明亮(即更白)。一些明亮的区域是宽的,有些是窄的或薄的。红色盒子盖着一个这么宽的亮点,蓝色盒子盖着一个薄薄的亮点。薄的亮点称为边缘,宽的亮点称为热点.
我想要删除所有热点从图像(即使他们黑色),但不应该删除边缘。
我的问题是如何使用OpenCV编写Python代码以删除所有热点但没有边缘?

发布于 2023-06-01 18:47:34
您能使用OpenCV尝试以下方法吗?
这背后的逻辑是:
发布于 2023-06-03 14:06:33
基于这个答案的算法我已经编写了我的代码,它正在按预期工作。
以下是编码步骤的细目:
import cv2
import numpy as np
# Load the image
image1 = cv2.imread('orange.jpg', cv2.IMREAD_GRAYSCALE)
original_image = image1
# Otsu's thresholding
_, image2 = cv2.threshold(image1, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# Erosion
kernel = np.ones((5, 5), np.uint8)
image3 = cv2.erode(image2, kernel, iterations=1)
# Define the threshold distance K
K = 2
# Create the circular mask
mask = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2 * K, 2 * K))
# Iterate over image1 pixels and generate the final image
final_image = np.copy(image1)
for y in range(image1.shape[0]):
for x in range(image1.shape[1]):
if image2[y, x] > 0:
# Check if any illuminated pixel exists within K distance in image3
neighborhood = image3[max(y - K, 0):min(y + K + 1, image3.shape[0]),
max(x - K, 0):min(x + K + 1, image3.shape[1])]
if np.sum(neighborhood) > 0:
final_image[y, x] = 0
# Display the original and final image
cv2.imshow('Original', original_image)
cv2.imshow('Final Image', final_image)
cv2.waitKey(0)
cv2.destroyAllWindows()https://datascience.stackexchange.com/questions/121793
复制相似问题