我是一名 Python 程序员,但是图像处理的初学者 :) 抱歉,如果这不是论坛的合适问题,很高兴重写或移动。
我想创建一个有监督的分类器来区分这张专辑中的两个图像(或者更一般地说,有更多的训练数据,这个场景包含一些可用停车的人行道,而这个场景不包含人行道)。
我的问题是关于如何使用 Pillow 或 scikit-image 提取适合分类的特征。
现在,我有一个 SVM 分类器的骨架代码:
data = []
classes = []
for imagefile in glob.glob('./img/training/*/*.bmp'):
data.append(extract_features(imagefile))
if 'nospace' in imagefile:
classes.append('nospace')
else:
classes.append('space')
clf = svm.SVC(gamma=0.001, C=100.)
clf.fit(data, classes)
我有一个非常简单的特征提取方法,它只返回图像的颜色直方图:
def extract_features(imagefile):
im = Image.open(imagefile)
width, height = im.size
im = im.crop((0, int(height * 0.4), width, int(height * 0.8)))
# Improve on just returning a colour histogram?
return im.histogram()
问题是这并不能产生很好的效果——特别是如果汽车的颜色与停机坪几乎相同,就像我的示例专辑一样。
我看了边缘检测。使用 Pillow 似乎很容易做到这一点:
im.filter(ImageFilter.FIND_EDGES)
但是仅仅将它传递给分类器也不会产生很好的结果——我猜是因为我应该把它从像素矩阵变成更有意义的东西?
谁能提出一个为这个问题提取特征的好方法?我认为理想情况下我想检测“斑点”,即汽车。