python:超像素SLIC算法使用

代码

skimage作为图像处理库,包括多种图像分割算法。其中超像素slic目前表现较好,该部分代码如下。

from skimage.segmentation import slic,mark_boundaries
from skimage import io
import matplotlib.pyplot as plt
# import numpy as np
#
# np.set_printoptions(threshold=np.inf)

img = io.imread("Lenna.png")


segments = slic(img, n_segments=60, compactness=10)
out=mark_boundaries(img,segments)
# print(segments)
plt.subplot(121)
plt.title("n_segments=60")
plt.imshow(out)

segments2 = slic(img, n_segments=300, compactness=10)
out2=mark_boundaries(img,segments2)
plt.subplot(122)
plt.title("n_segments=300")
plt.imshow(out2)

plt.show()

实现效果

实现效果如下。
这里写图片描述
这里写图片描述

原图:

猜你喜欢

转载自blog.csdn.net/nima1994/article/details/80695114
今日推荐