图像中颜色和纹理的均匀性

问题描述 投票:0回答:2

我是深度学习领域的新手,在确定两个图像是否具有均匀的颜色和纹理时遇到问题。例如,我有一个

主图像 -

MASTER IMAGE

现在,对于该图像,我需要确定以下图像是否具有均匀的纹理和颜色分布 -

图像 1 -

Picture Number 1

图2-

Picture Number 2

图3-

Picture number 3

我需要开发一种算法来评估这 3 个图像与主图像。该算法应批准图像 1,并因其颜色而拒绝图像 2,并因颜色和纹理均匀性而拒绝图像 3。

我解决这个问题的方法是直接分析图像进行纹理检测。我发现局部二进制模式方法在所有纹理识别方法中都很好(但我不确定)。我在 python 中将其 skimage 实现与 opencv 结合使用,发现该方法有效。

from skimage import feature
import numpy as np
import cv2
import matplotlib.pyplot as plt

class LocalBinaryPatterns:
    def __init__(self, numPoints, radius):
        # store the number of points and radius
        self.numPoints = numPoints
        self.radius = radius

    def describe(self, image, eps=1e-7):
        # compute the Local Binary Pattern representation
        # of the image, and then use the LBP representation
        # to build the histogram of patterns
        lbp = feature.local_binary_pattern(image, self.numPoints,
            self.radius, method="uniform")
        (hist, _) = np.histogram(lbp.ravel(),
            bins=np.arange(0, self.numPoints + 3),
            range=(0, self.numPoints + 2))

        # normalize the histogram
        hist = hist.astype("float")
        hist /= (hist.sum() + eps)

        # return the histogram of Local Binary Patterns
        return hist


desc = LocalBinaryPatterns(24, 8)

image = cv2.imread("main.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
hist = desc.describe(gray)

plt.plot(hist,'b-')
plt.ylabel('Feature Vectors')
plt.show()

它检测特征并制作特征向量的直方图。我使用 matplotlib 绘制了直方图,清楚地发现图像 1 和图像 2 纹理特征几乎与主图像相似。并且图像 3 纹理特征不匹配。

然后我开始分析图像的颜色。我使用 opencv 绘制了颜色直方图 -

import cv2
from matplotlib import pyplot as plt

def draw_image_histogram(image, channels, color='k'):
    hist = cv2.calcHist([image], channels, None, [256], [0, 256])
    plt.plot(hist, color=color)
    plt.xlim([0, 256])

def show_color_histogram(image):
    for i, col in enumerate(['b', 'g', 'r']):
        draw_image_histogram(image, [i], color=col)
    plt.show()

show_color_histogram(cv2.imread("test1.jpg"))

我发现图像 1 的颜色直方图与主图像匹配。并且图像 2 和 3 的颜色直方图不匹配。通过这种方式,我发现图像 1 是匹配的,而图像 2 和 3 则不匹配。

但是,我这是非常简单的方法,我不知道它会匹配哪些误报。而且我不知道解决问题的方法是最好的方法。

我也希望这可以通过像 CNN 这样的单一且强大的算法来完成(但计算成本不应该太高)。但我没有使用 CNN 的经验。那么我应该用主图像训练 CNN 吗?请为我指明正确的方向。我也遇到过LBCNN,他们能解决这个问题吗?还有什么其他更好的方法。

非常感谢您的帮助

python opencv machine-learning deep-learning computer-vision
2个回答
1
投票

CNN 擅长捕获数据集的底层特征和分布。但他们需要大量(数十万个示例)来学习和提取这些特征,这是非常昂贵的任务。此外,对于高分辨率图像,将需要更多参数来提取这些特征,这进一步需要更多数据。

如果你有大数据集,你可以更喜欢 CNN,它可以捕获微小的信息,例如这些精细的纹理。否则,这些经典方法(你已经执行过的)也很有效。

还有一种称为

transfer-learning
的方法,我们使用预先训练的模型(在类似的数据集上进行训练)并在我们的
small data-set
上对其进行微调。如果您能找到任何此类模型,那可能是另一种选择。


0
投票

一种更简单的方法是将控制图像划分为象限(例如 3 X 3),并确定一堆相关特征(颜色、边缘长度、黑色空间等)的平均值和 SD。可以将新图像的特征与该数据集进行统计比较,以检查一致性。

© www.soinside.com 2019 - 2024. All rights reserved.