我是深度学习领域的新手,在确定两个图像是否具有统一的颜色和纹理时遇到问题。例如,我有一个
主图——
现在,关于这张图片,我需要确定以下图片是否具有均匀的纹理和颜色分布 -
图片 1 -
图 2 -
图 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,他们能解决问题吗?还有什么可以是其他更好的方法。



