Segmentation: A SLIC Superpixel Tutorial using Python(超级像素(像素网格分类))
Segmentation: A SLIC Superpixel Tutorial using Python(超级像素(像素网格分类))
涉及到的原文引用:
translator:aaron-clark-aic
超级像素点的介绍
像素网格化是一个很常见的机器视觉算法,比如人脸检测就是利用一个固定大小的匹配模板在图像中遍历寻找适合的像素位置。超级像素点方式可以让我们自定义图像分割尺寸,比如按照像素分组分割100/300/500份网格,分割成的网格中每个像素点都在色彩和特征上高度一致。
超级像素点的使用场景分析
我们可以假设,一个物体使用边缘检测的时候,某些情况下边缘有可能模糊或者错误。使用超级像素点可以在一定程度上去修正这种边缘的错误。也就是保证切图区域更加合理。
超级像素点的代码实现
# import the necessary packages
from skimage.segmentation import slic
from skimage.segmentation import mark_boundaries
from skimage.util import img_as_float
import matplotlib.pyplot as plt
import cv2 as cv
# load the image and convert it to a floating point data type
image = img_as_float(cv.imread(".././img/base.jpg"))
fig = plt.figure()
# loop over the number of segments
for numSegments, i in ((100, 1), (200, 2), (300, 3)):
# apply SLIC and extract (approximately) the supplied number
# of segments
segments = slic(image, n_segments = numSegments, sigma = 5)
# show the output of SLIC
ax = fig.add_subplot(3, 1, i)
ax.set_title("Superpixels -- %d segments" % (numSegments))
ax.imshow(mark_boundaries(image, segments))
plt.axis("off")
# show the plots
plt.show()