我有图像
我正在寻找python解决方案,以打破这个图像中的形状,根据图像中的轮廓更小的部分。在
我已经在OpenCV中研究过Canny和findContours的解决方案,但它们都不适合我。在
使用的代码:
import cv2 import numpy as np
img = cv2.imread('area_of_blob_maxcontrast_white.jpg') edges = cv2.Canny(img, 100, 200)
cv2.imwrite('area_of_blob_maxcontrast_white_edges.jpg',edges)
诀窍是使你的模糊的单像素边界略粗一点。我通过将任何有两个相邻的黑色像素(上、下、左或右)的白色像素更改为黑色。(不过,我做得非常慢。我很确定肯定有一种更聪明的方法可以用OpenCV或Numpy来实现。)
这是我的代码:
输入图像:
输出图像:
这里我只给最外面轮廓(
hierarchy[i][3] == 1
)的直接后代着色。但你可以改变它来排除湖泊。在相关问题 更多 >
编程相关推荐