【问题标题】:Extracting attributes from images using Scikit-image使用 Scikit-image 从图像中提取属性
【发布时间】:2016-06-26 14:39:42
【问题描述】:

我一直在使用scikit-image 对道路特征进行分类并取得了一些成功。见下文:。我在进行下一步对特征进行分类时遇到了麻烦。例如,假设这些特征位于框 (600, 800) 和 (1400, 600) 中。

我用来提取信息的代码是:

from skimage import io, segmentation as seg
color_image = io.imread(img)  
plt.rcParams['image.cmap'] = 'spectral'
labels = seg.slic(color_image, n_segments=6, compactness=4)

目标是有一个如下形式的表格:

Image, feature_type, starting_pixel, ending_pixel
001    a             (600, 600),     (1300, 700) 
002    b             (600, 600),     (1100, 700)
002    undefined     (700, 700),     (900, 800)

feature_type 将基于颜色,理想情况下肩膀是一种颜色,树木和刷子是另一种颜色,等等。

如何提取我需要的数据? (即:让 scikit 将图像分解为不同的组件,我知道每个组件的位置。然后我可以将每个组件传递给一个分类器,该分类器将识别每个组件是什么)谢谢!

【问题讨论】:

  • 您的问题似乎含糊不清。你想找到每个特征区域的边界框吗?如果是,您希望它们重叠还是不重叠?您想将特征图映射到下采样的常规网格上吗?你能澄清一下吗?
  • @fireant 无论是在整个图像上还是在小边界框上执行此操作,最终目标都是根据“颜色”识别特征。所以道路将是 (1)、路肩 (2)、沟渠 3)、树木 (4) 等等..
  • 但是你为什么不直接切片图像或分类呢? Scikit Image 可与 ndarray 一起使用,您可以执行“color_image[600:800,1400:1600,:]”。我是不是理解错了?

标签: python machine-learning computer-vision scikit-learn scikit-image


【解决方案1】:

这是我第一次尝试这个包.. 我尝试使用更简单的图像,但我或多或少得到了正确的结果:

from skimage import io, segmentation as seg
import matplotlib as plt
import numpy as np
color_image = io.imread('smallimg.jpg')
labels = seg.slic(color_image, n_segments=4, compactness=4)
for section in np.unique(labels):
    rows, cols = np.where(labels == section)
    print("Image="+str(section))
    print("Top-Left pixel = {},{}".format(min(rows), min(cols)))
    print("Bottom-Right pixel = {},{}".format(max(rows), max(cols)))
    print("---")

输出:

Image=0
Top-Left pixel = 3,1
Bottom-Right pixel = 15,18
---
Image=1
Top-Left pixel = 26,1
Bottom-Right pixel = 34,18
---
Image=2
Top-Left pixel = 43,1
Bottom-Right pixel = 52,16
---
Image=3
Top-Left pixel = 0,0
Bottom-Right pixel = 59,19
---

请注意,由于渐变,最右边的像素并不是我的意思。最后一段是白色背景。

我尝试使用您的图像,但我认为您必须正确分割。如果你想获得 6 张图片 + 背景,我会使用 n_segments=7 。

我还在有关紧凑性的文档中看到:“此参数在很大程度上取决于图像对比度和图像中对象的形状。”。所以你想要的可能很难实现。

如果您在上面显示的图像上绘制六张图片,为什么在绘制图片时不获取这些坐标而不是对最终结果应用分割?

【讨论】:

    猜你喜欢
    • 2016-12-27
    • 2015-06-25
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2017-08-12
    • 1970-01-01
    • 2011-05-31
    相关资源
    最近更新 更多