zoukankan      html  css  js  c++  java
  • 超像素分割, 并获取每一个分区

    参考、学习自Greatpyimagesearch

    from skimage.segmentation import slic
    from skimage.segmentation import mark_boundaries
    from skimage.util import img_as_float
    import matplotlib.pyplot as plt
    import numpy as np
    import cv2
    
    
    # args
    args = {"image": './hand_0.png'}
    
    # load the image and apply SLIC and extract (approximately)
    # the supplied number of segments
    image = cv2.imread(args["image"])
    segments = slic(img_as_float(image), n_segments=100, sigma=5)
    
    # show the output of SLIC
    fig = plt.figure('Superpixels')
    ax = fig.add_subplot(1, 1, 1)
    ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)), segments))
    plt.axis("off")
    plt.show()
    print("segments:
    ", segments)
    print("np.unique(segments):", np.unique(segments))
    # loop over the unique segment values
    for (i, segVal) in enumerate(np.unique(segments)):
        # construct a mask for the segment
        print("[x] inspecting segment {}, for {}".format(i, segVal))
        mask = np.zeros(image.shape[:2], dtype="uint8")
        mask[segments == segVal] = 255
    
        # show the masked region
        cv2.imshow("Mask", mask)
        cv2.imshow("Applied", np.multiply(image, cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) > 0))
        cv2.waitKey(0)
    
    
  • 相关阅读:
    C语言学习笔记<九>
    C语言学习笔记<六>
    C语言学习笔记<八>
    C语言学习代码〈五〉
    C语言学习笔记<七>
    红队笔记横向移动总结
    pikachu通关
    java线程监控
    项目空负载服务器使用cpu过高
    @NotBlank注解使用不生效的解决办法
  • 原文地址:https://www.cnblogs.com/ZhengPeng7/p/8986404.html
Copyright © 2011-2022 走看看