赞
踩
最近在学习区域卷积神经网络(RCNN)时,候选框产生使用了选择搜索(selective search),为了更透彻地理解RCNN的工作原理,所以决定基于python代码,实现选择搜索(selective search)。
关于选择搜索(selective search)的基本原理和初步认知,可以参考以下博客:
https://blog.csdn.net/mao_kun/article/details/50576003
在这里主要结合自己的理解作简要总结和梳理:
def _generate_segments(img_path, neighbor, sigma, scale, min_size):
# open the Image
im_mask = graphbased_segmentation(img_path, neighbor, sigma, scale, min_size)
im_orig = skimage.io.imread(img_path)
# merge mask channel to the image as a 4th channel
im_orig = numpy.append(
im_orig, numpy.zeros(im_orig.shape[:2])[:, :, numpy.newaxis], axis=2)
im_orig[:, :, 3] = im_mask
return im_orig
对原图像作图像分割,把分割的每个像素所属区域的编号作为图像的第4通道。
def _calc_colour_hist(img): """ calculate colour histogram for each region the size of output histogram will be BINS * COLOUR_CHANNELS(3) number of bins is 25 as same as [uijlings_ijcv2013_draft.pdf] extract HSV """ BINS = 25 hist = numpy.array([]) for colour_channel in (0, 1, 2): # extracting one colour channel c = img[:, colour_channel] # calculate histogram for each colour and join to the result hist = numpy.concatenate( [hist] + [numpy.histogram(c, BINS, (0.0, 255.0))[0]]) # L1 normalize hist = hist / len(img) return hist def _calc_texture_gradient(img): """ calculate texture gradient for entir
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。