Opencv学习笔记 超像素分割

    科技2022-07-12  131

            在计算机视觉领域,图像分割(Segmentation)指的是将数字图像细分为多个图像子区域(像素的集合)(也被称作超像素)的过程。超像素由一系列位置相邻且颜色、亮度、纹理等特征相似的像素点组成的小区域。这些小区域大多保留了进一步进行图像分割的有效信息,且一般不会破坏图像中物体的边界信息。 图像分割的结果是图像上子区域的集合(这些子区域的全体覆盖了整个图像),或是从图像中提取的轮廓线的集合(例如边缘检测)。一个子区域中的每个像素在某种特性的度量下或是由计算得出的特性都是相似的,例如颜色、亮度、纹理。邻接区域在某种特性的度量下有很大的不同。

            超像素分割有什么用处?超像素可以用来做跟踪;可以做标签分类;视频前景分割,因为相比像素,超像素处理速度会快几十倍、几百倍甚至更高;超像素还可以用于骨架提取、人体姿态估计、医学图像分割等方面。

            Python参考代码如下:

    # import the necessary packages from skimage.segmentation import slic from skimage.segmentation import mark_boundaries from skimage.util import img_as_float from skimage import io import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt import argparse # construct the argument parser and parse the arguments # ap = argparse.ArgumentParser() # ap.add_argument("-i", "--image", required = True, help = "Path to the image") # args = vars(ap.parse_args()) # load the image and convert it to a floating point data type image = img_as_float(io.imread("C:/Users/zyh/Desktop/QQ图片20200922073254.png")) # loop over the number of segments for numSegments in (100, 200, 300): # apply SLIC and extract (approximately) the supplied number # of segments segments = slic(image, n_segments = numSegments, sigma = 5) # show the output of SLIC fig = plt.figure("Superpixels -- %d segments" % (numSegments)) ax = fig.add_subplot(1, 1, 1) ax.imshow(mark_boundaries(image, segments)) plt.axis("off") # show the plots plt.show()

     

    原图

            OpenCv的超像素分割算法:https://blog.csdn.net/zhangyonggang886/article/details/52854219 

    Processed: 0.011, SQL: 8