【问题标题】:Finding similar objects in different images在不同的图像中寻找相似的对象
【发布时间】:2021-08-12 03:21:26
【问题描述】:

我正在使用 python3图像处理 库(例如 OpenCV)开发公司徽标图像搜索系统。

到目前为止,我已经设法从给定图像中提取单个对象,这些对象被提取为二进制图像,因此它们可以轻松用作蒙版。

这是通过 K-Means 对图像进行聚类,使用具有 4 路连接性的 cv2.connectedComponents,然后应用 Watershed 来分离对象来完成的。

# Making a binary version of the kmeans clustered image
gray = cv2.cvtColor(masked_image, cv2.COLOR_BGR2GRAY);
_, binary = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY_INV)

# Euclidean Distance and Distance Mapping
D = ndimage.distance_transform_edt(binary)
localMax = peak_local_max(D, indices = False, min_distance = 25, labels = binary)

# Connected Component Analysis on local peaks and watershed algorithm
markers = ndimage.label(localMax, structure=np.ones((3,3)))[0]
labels = watershed(-D, markers, mask=binary)
print('{} components found'.format(len(np.unique(labels))- 1))

# Loop over unique labels
for label in np.unique(labels):
  if label == 0:
    continue
  
  # Draw label on the mask
  mask = np.zeros(gray.shape, dtype="uint8")
  mask[labels == label] = 255

  # Detect contours in the mask 
  cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  cnts = imutils.grab_contours(cnts)
  c = max(cnts, key=cv2.contourArea)
 
  # Draw all contours
  image = cv2.drawContours(mask, cnts, -1, (0, 255, 0), 1)
  cv2_imshow(image)
  cv2.imwrite("/content/watershed/contour{}.png".format(label), image)

例子:

输入图像

输出对象之一

我现在的目标是在我的数据集中找到包含与上面的玫瑰相似的对象(不一定是完全相同的玫瑰)的图像。这可以通过 R-CNN 实现吗?还有哪些匹配方式有用?

【问题讨论】:

    标签: python numpy opencv image-processing


    【解决方案1】:

    您有很多选择。我列出了一些想法:

    1. 与直方图的距离 - 您可以计算 RGB 通道中的图像直方图,当每种颜色的每个 bin 将成为特征向量的一个分量时,您可以测量蒙版图像的距离并找到所有图像低于阈值。
    2. 使用 CNN 作为特征提取器 - 采用预训练模型(例如在 imageNet 上训练的 VGG16)。将蒙版图像调整为固定形状,并将模型输出用作特征向量。然后,您可以使用欧几里得距离或其他度量对其进行分类。
    3. 模板匹配 - 您可以将所有蒙版对象调整为特定大小,并使用旋转 N 角的玫瑰进行模板匹配或 MSE(或其他技术)。您也需要在此处设置阈值。

    有很多解决方案,您应该尝试其中一些并将它们与验证集进行比较。
    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2015-06-09
      • 1970-01-01
      • 2010-09-09
      • 2020-10-23
      • 2012-12-12
      • 2014-11-30
      • 1970-01-01
      • 2019-06-22
      • 2015-10-22
      相关资源
      最近更新 更多