Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 基于目标形状的无监督图像分割_Image Processing_Cluster Analysis_Image Segmentation_Unsupervised Learning - Fatal编程技术网

Image processing 基于目标形状的无监督图像分割

Image processing 基于目标形状的无监督图像分割,image-processing,cluster-analysis,image-segmentation,unsupervised-learning,Image Processing,Cluster Analysis,Image Segmentation,Unsupervised Learning,是否有任何无监督的方法(即不需要训练数据集)根据形状分离下图中的对象 我想买那样的东西 橙色线条将细长物体与“圆形”物体分开,这对我很有用 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

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

我想买那样的东西 橙色线条将细长物体与“圆形”物体分开,这对我很有用

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)

输出:

您可以首先将线与对象分开(可能可以进行打开操作),然后根据体积、直径等对对象进行分类。