使用 Scikit-image 从图像中提取属性
Extracting attributes from images using Scikit-image
我一直在使用 scikit-image to classify road features with some success. See below: 。我在下一步进行功能分类时遇到了麻烦。例如,假设这些特征位于方框 (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)
objective 是有一个 table 如下形式:
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 将图像分解成不同的组件,我知道每个组件的位置。然后我可以将每个组件传递给分类器,分类器将识别每个组件是什么)谢谢!
这是我第一次尝试那个包..
我尝试使用更简单的图像,或多或少得到了正确的结果:
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。
我还在文档中看到了关于紧凑性的信息:"This parameter depends strongly on image contrast and on the shapes of objects in the image."。所以你想要的可能很难实现。
如果您在上面显示的图像上绘制六张图片,为什么在绘制图片时不获取这些坐标,而不是对最终结果应用分割?
我一直在使用 scikit-image to classify road features with some success. See below:
我用来提取信息的代码是:
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)
objective 是有一个 table 如下形式:
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 将图像分解成不同的组件,我知道每个组件的位置。然后我可以将每个组件传递给分类器,分类器将识别每个组件是什么)谢谢!
这是我第一次尝试那个包.. 我尝试使用更简单的图像,或多或少得到了正确的结果:
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。
我还在文档中看到了关于紧凑性的信息:"This parameter depends strongly on image contrast and on the shapes of objects in the image."。所以你想要的可能很难实现。
如果您在上面显示的图像上绘制六张图片,为什么在绘制图片时不获取这些坐标,而不是对最终结果应用分割?