zoukankan      html  css  js  c++  java
  • 目标检测算法:Selective Search(选择性搜索)简述

    Selective search是一种基于特征的目标检测算法,在R-CNN中被用来生成候选区域。

    论文链接:http://www.huppelen.nl/publications/selectiveSearchDraft.pdf

    code链接:https://github.com/AlpacaDB/selectivesearch

    原理简介

    在图像中寻找物体,可以依据多种特征,例如颜色、纹理、形状等。然而,这些特征并不能通用地用来寻找所有的物体,物体在图像中的尺度也大小不一。为了兼顾各种尺度与特征,selective search的做法是先寻找尺寸较小的区域,然后逐渐将特征相近的小尺度的区域合并为大尺度区域,从而得到内部特征一致的物体图像。

    算法的流程为:

    • 对图像进行分割,得到较小的候选区域,使用的是“Felzenswalb and Huttenlocher”算法,这个算法的具体内容有待研究。
    • 对每两个相邻的候选区域,计算其相似度,并将相似度最高的两个区域合并,并计算该合并区域与所有相邻区域的相似度,重复该步骤,直到没有可以计算的相邻区域。

    其中,计算相似度的方法为:颜色越相近的区域相似度越大、纹理越相近的区域相似度越大、越小的区域相似度越大(实际上是权重越大)、区域的吻合度越大相似度越大。

    颜色相近的评价标准是对各个通道计算颜色直方图,然后取各个对应bins的直方图最小值。

    纹理相近的评价标准是计算各个区域的快速sift特征,然后对纹理直方图的各个对应bins求最小值。

    小区域的权重算法是s_size(ri, rj) = 1 - (size(ri) + size(rj)) / size(img)

    区域吻合度指的是,两个区域相邻的边的边长差距不能太大,也就是合并时不能出现“断崖”,表示方法是外接矩形的重合度应当尽可能大。算法为s_fill(ri, rj) = 1 - (size(bbox) - size(ri) - size(rj)) / size(img)

    最终的相似度由这几项加权得到。

    除此之外,为了保证对各种情景下图像的鲁棒性,算法还使用了多种色彩空间变换,来增多色彩的特征数量。

    代码使用方法

    给出的算法的函数原型为:

     1 def selective_search(
     2         im_orig, scale=1.0, sigma=0.8, min_size=50):
     3     '''Selective Search
     4 
     5     Parameters
     6     ----------
     7         im_orig : ndarray
     8             Input image
     9         scale : int
    10             Free parameter. Higher means larger clusters in felzenszwalb segmentation.
    11         sigma : float
    12             Width of Gaussian kernel for felzenszwalb segmentation.
    13         min_size : int
    14             Minimum component size for felzenszwalb segmentation.
    15     Returns
    16     -------
    17         img : ndarray
    18             image with region label
    19             region label is stored in the 4th value of each pixel [r,g,b,(region)]
    20         regions : array of dict
    21             [
    22                 {
    23                     'rect': (left, top, width, height),
    24                     'labels': [...],
    25                     'size': component_size
    26                 },
    27                 ...
    28             ]
    29     '''

    在使用时,需要去除重复区域、过小的区域以及一些长宽比过大或过小的“畸形区域”。以下是一个使用的示例:

     1 import skimage.data
     2 import matplotlib.pyplot as plt
     3 import matplotlib.patches as mpatches
     4 import selectivesearch
     5 
     6 
     7 def main():
     8 
     9     # loading astronaut image
    10     img = skimage.data.astronaut()
    11 
    12     # perform selective search
    13     img_lbl, regions = selectivesearch.selective_search(
    14         img, scale=500, sigma=0.9, min_size=10)
    15 
    16     candidates = set()
    17     for r in regions:
    18         # excluding same rectangle (with different segments)
    19         if r['rect'] in candidates:
    20             continue
    21         # excluding regions smaller than 2000 pixels
    22         if r['size'] < 2000:
    23             continue
    24         # distorted rects
    25         x, y, w, h = r['rect']
    26         if w / h > 1.2 or h / w > 1.2:
    27             continue
    28         candidates.add(r['rect'])
    29 
    30     # draw rectangles on the original image
    31     fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
    32     ax.imshow(img)
    33     for x, y, w, h in candidates:
    34         print(x, y, w, h)
    35         rect = mpatches.Rectangle(
    36             (x, y), w, h, fill=False, edgecolor='red', linewidth=1)
    37         ax.add_patch(rect)
    38 
    39     plt.show()
    40 
    41 if __name__ == "__main__":
    42     main()
  • 相关阅读:
    Redhat各个版本和内核对照
    Java8 lambda表达式总结
    conda 安装指定版本的指定包
    git初始化的几句shell
    MYsqli 绑定插入与查询实例
    按天去除重复数据,为0则取0,否则取最大的那个值
    存储过程,循环插入1000条记录
    主表如何统计在附表中的出现次数?
    Invalid argument supplied for foreach()
    二十、mysql mysqldump备份工具
  • 原文地址:https://www.cnblogs.com/littlenyima/p/13358125.html
Copyright © 2011-2022 走看看