cs231n assignment1 feature

来源:互联网 发布:淘宝卖家需要用的软件 编辑:程序博客网 时间:2024/06/05 10:25

图像特征提取方法 LBP



在做stanford cs231n assignment1时,最后一个作业题用到了图像的特征提取, 作业里给的是HOG和color histogram

这里我简单的在网上找了一下,在图像处理方面一般有三种图像特征提取方法,

1)HOG  2)LBP  3)Haar


因为作业里的feature.py代码写的很好,可以很容易添加不同的extract feature functions,

所以bonus time环节就可以多用一些function了。

然后我是这样做的

在运行环境下安装skimage包,直接pip安装

然后在feature.py中导入包

from skimage import feature as skft

最后附上我的代码。。。完全照抄挺简单的。。。

把下面这个函数直接加在feature.py再调用就可以了,

这里对应的feature.ipynb可能需要重头开始加载,因为我一开始没重头加载一直显示导入不了lbp_feature这个函数

def lbp_feature(im):  """Local Binary Patterns (LBP) feature for an image         https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/_texture.pyx       https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/texture.py          Reference:       (1, 2) Face recognition with local binary patterns. Timo Ahonen, Abdenour Hadid, Matti Pietikainen,        http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.214.6851, 2004.         Parameters:      im : an input grayscale or rgb image          Returns:      feat: Local Binary Patterns (LBP) feature     """    # convert rgb to grayscale if needed  if im.ndim == 3:    image = rgb2gray(im)  else:    image = np.at_least_2d(im)      # settings for LBP  # Small radius can get fine texture.  radius = 1  n_point = radius * 8  #Using LBP to extract texture feature of image.  lbp = skft.local_binary_pattern(image, n_point, radius, 'default')  #Satistics histogram of image  max_bins = int(lbp.max() + 1)  train_hist, _ = np.histogram(lbp, normed=True, bins=max_bins, range=(0, max_bins))    # return histogram  return train_hist.ravel()



原创粉丝点击