Python 在分水岭分割中设置标签优先级
我正在尝试使用分水岭分割来分割植物的叶子Python 在分水岭分割中设置标签优先级,python,opencv,Python,Opencv,我正在尝试使用分水岭分割来分割植物的叶子 path = '../Plant_Phenotyping_Datasets/Plant/Ara2013-Canon/ara2013_plant001_rgb.png' img = cv.imread(path) gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) thresh = cv.threshold(gray, 65, 255, cv.THRESH_BINARY)[1] thresh = cv.medianBlu
path = '../Plant_Phenotyping_Datasets/Plant/Ara2013-Canon/ara2013_plant001_rgb.png'
img = cv.imread(path)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
thresh = cv.threshold(gray, 65, 255, cv.THRESH_BINARY)[1]
thresh = cv.medianBlur(thresh, 5)
kernel = np.ones((3, 3), np.uint8)
sure_bg = cv.dilate(thresh, kernel, iterations=3)
dist_transform = cv.distanceTransform(thresh, cv.DIST_L2, 5)
sure_fg = cv.threshold(dist_transform, 0.5*dist_transform.max(), 255, 0)[1]
sure_fg = np.uint8(sure_fg)
unknown = cv.subtract(sure_bg, sure_fg)
markers = cv.connectedComponents(sure_fg)[1]
markers = markers+1
markers[unknown == 255] = 0
cv.watershed(img, markers)
img[markers == -1] = [255, 0, 0]
根据以下示例调整代码:。
目的是让opencv基于“标记”在未知区域进行标记,它将每个确定的前地面区域(其中必须是叶子区域)设置为标签,背景为1,未知区域(前地面和背景之间的区域)设置为0
原始图像和标记:
但是,分割后的结果如下:
这可能是因为电厂的蒸汽区域被标记为背景区域标签,这是为了让背景标签在流域过程中具有最低优先级?
多谢各位