其他分享
首页 > 其他分享> > Seeds超像素分割

Seeds超像素分割

作者:互联网

#%% SEED超像素分割
import cv2
import numpy as np
import imageio
# print(dir(cv2.ximgproc))

img = imageio.imread(r'E:\Vaihingen\data\orginalimages\top_mosaic_09cm_area31.tif')[:,:,::-1]
converted_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# print(type(img_feature))

#seed参数
height,width,channels = converted_img.shape

num_iterations = 15
prior = 3
double_step = True
num_superpixels = 30000
num_levels = 6
num_histogram_bins = 10

# seed
seeds = cv2.ximgproc.createSuperpixelSEEDS(width, height, channels, num_superpixels, num_levels, prior, num_histogram_bins)
seeds.iterate(converted_img,num_iterations)  #输入图像大小必须与初始化形状相同,迭代次数为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)
imageio.imsave('img_seeds.png',img_seeds[:,::,::-1])

结果:
在这里插入图片描述

标签:分割,num,img,mask,cv2,像素,seeds,Seeds,import
来源: https://blog.csdn.net/qq_28368377/article/details/114133973