【发布时间】:2022-01-05 19:08:52
【问题描述】:
在 Python 中,我使用背景去除工具和 scikit 的 Felzenszwalb 算法来分割我的图像
from rembg.bg import remove
import numpy as np
import io
from PIL import Image
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
input_path = 'in.jpg'
output_path = 'out.png'
f = np.fromfile(input_path)
result = remove(f)
img = Image.open(io.BytesIO(result)).convert("RGBA")
#importing needed libraries
import skimage.segmentation
from matplotlib import pyplot as plt
#performing segmentation
res1 = skimage.segmentation.felzenszwalb(img, scale=500)
##uncomment to print results if desired
#fig = plt.figure(figsize=(12, 5))
#ax1 = fig.add_subplot(121)
#ax1.imshow(res1); ax1.set_xlabel("k=500")
#fig.suptitle("Graph based image segmentation")
#plt.tight_layout()
这为我提供了几种不同颜色的分段图像图。输出 res1 是一个 ndarray “指示段标签的整数掩码”(来自 scikit 网站)。我现在想对这些区域中的每一个进行一些颜色分析。我将如何使用res1 依次访问每个蒙版(具有均匀或透明背景)并执行我的颜色分析?
【问题讨论】:
标签: python scikit-learn image-segmentation