【问题标题】:Impact of pure white on color histogram纯白色对颜色直方图的影响
【发布时间】: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


    【解决方案1】:

    见:http://docs.opencv.org/2.4/modules/imgproc/doc/histograms.html

    重要部分:

    Python: cv2.calcHist(images, channels, mask, histSize, range[, hist[, accumulate]]) → hist

    参数:... 范围 - 每个维度中直方图 bin 边界的 dims 数组的数组。当直方图是统一的(uniform =true)时,对于每个维度 i,指定第 0 个直方图 bin 的下(包括)边界 L_0 和上(不包括)边界 U_{\texttt{histSize}[ i]-1} 为最后一个直方图 bin histSize[i]-1 .

    尝试更改这部分代码

    hist_full = opencv.calcHist([chan], [0], mask, [bin_amount], [0, bin_amount])
    

    如下

    hist_full = opencv.calcHist([chan], [0], mask, [bin_amount], [0, 256])
    

    您需要在图片中指定实际值的范围(不包括上边界)。 很可能,现在您只计算值 0-63 而忽略直方图中的 64-255。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      相关资源
      最近更新 更多