【发布时间】:2019-12-16 16:48:04
【问题描述】:
我正在尝试获取专辑封面的轮廓,而边缘检测器(Canny、Laplace)检测到的噪音过多。我不完全了解图像遮罩的工作原理,并想在图像上放置一个白色遮罩,因此我只能看到黑色像素
我已应用 GaussianBlur 5x5 并将图像转换为 hsv 值。我有一系列黑色的值,我已经过滤掉了这些值。
# imported image and processing (shorthand here)
image = cv2.imread(args["image"])
blur = cv2.GaussianBlur(image, (5,5), 0)
blur_hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
# set regions of color
boundaries = [
# black
([0,0,0],[180, 255, 40])
#pink
#([151, 80, 50], [174, 255, 255])
]
# loop over the boundaries
for (lower, upper) in boundaries:
# create NumPy arrays from the boundaries
lower = np.array(lower, dtype = "uint8")
upper = np.array(upper, dtype = "uint8")
# find the colors within the specified boundaries and apply
mask = cv2.inRange(blur_hsv, lower, upper)
output = cv2.bitwise_and(image, image, mask = mask)
# show the images
cv2.imshow("images", np.hstack([image, output]))
我希望在最终输出中有所区别,但窗口只是黑色的。如何创建不同颜色的蒙版?
编辑:
不是确切的图像,而是一个示例 LEFT:原始;右:已处理
【问题讨论】:
-
你能添加你的输入图像和预期的输出图像吗?
-
帖子已更新为示例图像输出
-
我不完全明白你想要做什么。你想创建一个高亮所有黑色像素的遮罩(这样遮罩上的任何黑色像素都会变成白色)吗?
-
@nathancy -- 正好相反。蒙版当前是黑色的,因此它将所有不是“黑色”的像素变成黑色,我看不到它检测到哪些像素为“黑色”。我想要在这些像素上使用白色蒙版
-
所以你想创建一个所有非黑色像素都是白色的蒙版。当掩码是按位和原始图像时,您只想要一个只显示颜色的结果图像?