基于物体形状的无监督图像分割

Unsupervised Image Segmentation based on object shape

是否有任何无监督方法(即不需要训练数据集)根据形状分离下图中的对象?

我想要这样的东西 橙色线将细长物体与“圆形”物体分开

这对我有用。

import cv2
import numpy as np
from copy import deepcopy

path = "Image.png"

image = cv2.imread(path, 0)
image_copy = deepcopy(image)
rad = 18
shape_type = cv2.MORPH_RECT
element = cv2.getStructuringElement(shape_type, (2 * rad + 1, 2 * rad + 1), (rad, rad))
image = cv2.dilate(image, element)
image_show = ~cv2.erode(image, element)


backtorgb = cv2.cvtColor(image_copy, cv2.COLOR_GRAY2RGB)


contour, hier = cv2.findContours(image_show, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
for cnt in contour:
    area = cv2.contourArea(cnt)
    perimeter = cv2.arcLength(cnt,True)
    if (area > 12000) & (area / perimeter**2 * 4 * 3.14 > 0.3):
        blue = 0
        green = 0
        red = 255
    else:
        red = 0
        green = 0
        blue = 0
    cv2.drawContours(backtorgb, [cnt], 0, (blue, green, red), -1)


imS = cv2.resize(backtorgb, (960, 540))

cv2.imshow("image2", imS)
cv2.imwrite("output.png", backtorgb)
cv2.waitKey(0)

输出: