【发布时间】:2017-08-20 17:32:24
【问题描述】:
我正在尝试使用 KNN 方法根据人脸照片将人分类为种族。我有一个纯白色背景上的人脸数据集 [255, 255, 255]。
作为提要输入,我使用颜色直方图的值。有人告诉我应该从直方图中移除背景颜色以提高 KNN 的性能。
问题:当我从忽略背景的照片中创建蒙版时,直方图不会改变一点点。
问题:我不是很了解颜色理论,纯白色对颜色直方图的形状有影响吗?当我使用仅居中的常规掩码时(如下图所示),直方图会发生变化。
这是我根据图片构造的蒙版,忽略背景
简单的掩码测试掩码应用的正确性
直方图计数的源图像
这是我使用简单蒙版裁剪图片得到的直方图。直方图发生变化,因此我认为我计算直方图的方法是正确的。
直方图计数代码:
# loop over the image channels
for (chan, color) in zip(channels, colors):
# create a histogram for the current channel and
# concatenate the resulting histograms for each channel
hist_full = opencv.calcHist([chan], [0], mask, [bin_amount], [0, bin_amount])
# plot the histogram
plt.plot(hist_full, color=color)
plt.xlim([0, bin_amount])
plt.show()
创建面具的代码:
mask = np.zeros(image.shape[:2], np.uint8)
# simple mask option
# mask[75:175, 75:175] = 255
# create a mask to ignore white background in the histogram
for row in range(0, len(image)):
for col in range(0, len(image[0])):
if (image[row][col] != np.asarray(prop.background)).all():
try:
mask[row][col] = 255
except IndexError:
print(col)
【问题讨论】:
标签: python opencv image-processing colors histogram