当前位置:网站首页>Opencv 图像超像素分割(SLIC、SEEDS、LSC)
Opencv 图像超像素分割(SLIC、SEEDS、LSC)
2022-08-10 15:03:00 【为为为什么】
超像素是把一张图片中具有相似特征的像素进行聚类,形成一个更具有代表性的大“像素”。 本文记录Opencv 实现方法。
简介
- 超像素是把一张图片中具有相似特征的像素进行聚类,形成一个更具有代表性的大“像素”。这个新的像素可以作为其他图像处理算法的基本单位,可以减低图像的维度和异常像素点。目前常用的超像素分割算法有SLIC、SEEDS和LSC。下面来说说这些算法基于Opencv的Python实现。
- 测试图像:
SLIC
- 算法具体原理可参考博客:SuperPixel 超像素分割 SLIC 算法
- 利用opencv中ximgproc类下的子类SuperpixelSLIC实现。
- python调用方法:
retval = cv2.ximgproc.createSuperpixelSLIC(image[, algorithm[, region_size[, ruler]]] )- 其中各个参数意义如下:
- 代码示例
import cv2
import numpy as np
import mtutils as mt
img = mt.cv_rgb_imread("test.jpg")
#初始化slic项,超像素平均尺寸20(默认为10),平滑因子20
slic = cv2.ximgproc.createSuperpixelSLIC(img,region_size=20,ruler = 20.0)
slic.iterate(10) #迭代次数,越大效果越好
mask_slic = slic.getLabelContourMask() #获取Mask,超像素边缘Mask==1
label_slic = slic.getLabels() #获取超像素标签
number_slic = slic.getNumberOfSuperpixels() #获取超像素数目
mask_inv_slic = cv2.bitwise_not(mask_slic)
img_slic = cv2.bitwise_and(img,img,mask = mask_inv_slic) #在原图上绘制超像素边界
mt.PIS(img_slic)
passSEEDS
- 利用opencv中ximgproc类下的子类 createSuperpixelSEEDS()实现。
- python调用方法:
retval = cv.ximgproc.createSuperpixelSEEDS( image_width, image_height, image_channels, num_superpixels, num_levels[, prior[, histogram_bins[, double_step]]] )- 其中各个参数意义如下:
- python具体实现如下:
import cv2
import numpy as np
import mtutils as mt
img = mt.cv_rgb_imread("test.jpg")
#初始化seeds项,注意图片长宽的顺序
seeds = cv2.ximgproc.createSuperpixelSEEDS(img.shape[1],img.shape[0],img.shape[2],2000,15,3,5,True)
seeds.iterate(img,10) #输入图像大小必须与初始化形状相同,迭代次数为10
mask_seeds = seeds.getLabelContourMask()
label_seeds = seeds.getLabels()
number_seeds = seeds.getNumberOfSuperpixels()
mask_inv_seeds = cv2.bitwise_not(mask_seeds)
img_seeds = cv2.bitwise_and(img,img,mask = mask_inv_seeds)
mt.PIS(img_seeds)
passLSC
- 利用opencv中ximgproc类下的子类 createSuperpixelLSC() 实现。
- python调用方法:
retval = cv.ximgproc.createSuperpixelLSC( image[, region_size[, ratio]] )- 其中各个参数意义如下:
- python具体实现相似,如下所示:
import cv2
import numpy as np
import mtutils as mt
img = mt.cv_rgb_imread("test.jpg")
lsc = cv2.ximgproc.createSuperpixelLSC(img)
lsc.iterate(10)
mask_lsc = lsc.getLabelContourMask()
label_lsc = lsc.getLabels()
number_lsc = lsc.getNumberOfSuperpixels()
mask_inv_lsc = cv2.bitwise_not(mask_lsc)
img_lsc = cv2.bitwise_and(img,img,mask = mask_inv_lsc)
mt.PIS(img_lsc)
pass参考资料
边栏推荐
- Introduction to program debugging and its use
- 匿名函数和全部内置函数详细认识(下篇)
- QOS功能介绍
- Based on Azuki Series: NFT Valuation Analysis Framework "DRIC"
- Systemui status bar to add a new icon
- 使用 ABAP 正则表达式解析 uuid 的值
- Digital Collection Platform System Development Practice
- 【语义分割】DeepLab系列
- Azure IoT 合作伙伴技术赋能工作坊:IoT Dev Hack
- 程序员=加班??——掌握时间才能掌握人生
猜你喜欢
随机推荐
MySQL batch update and batch update method of different values of multiple records
Systemui status bar to add a new icon
JS入门到精通完整版
SYM32——RTC实时时钟程序讲解
“蔚来杯“2022牛客暑期多校训练营7
MySQL批量更新与批量更新多条记录的不同值实现方法
systemui屏蔽通知栏
第壹章模块大全之《re模块》
MySQL命令行导出导入数据库
APP automation testing with Uiautomator2
SWIG教程《一》
WSL 提示音关闭
Go Context基本使用
基于inotify实现落盘文件的跨进程实时读写交互
奢侈品鉴定机构小程序开发制作功能介绍
Digital Collection Platform System Development Practice
学习MySQL 临时表
紫金示例
systemui状态栏添加新图标
自定义picker滚动选择器样式









