转换使用slic分割的图像以在抓取中使用

时间:2019-03-04 14:30:00

标签: python image opencv image-segmentation

我已经使用skimage的slic将图像分割成超像素。现在,我想在超像素上使用抓取。我该怎么做?

from skimage.segmentation import slic
from skimage.util import img_as_float
from skimage import io
import matplotlib.pyplot as plt
import argparse
import cv2
import numpy as np

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())

image = img_as_float(io.imread(args["image"]))

for numSegments in (100, 500):

    segments = slic(image, n_segments = numSegments, sigma = 5)

    bgdModel = np.zeros((1,65),np.float64)
    fgdModel = np.zeros((1,65),np.float64)

    cv2.grabCut(segments, bgdModel, fgdModel, 5)
    plt.imshow(segments)

0 个答案:

没有答案