cs231n assignment1 feature

本文介绍了在Stanford CS231n课程作业中使用LBP(Local Binary Patterns)进行图像特征提取的方法。通过安装skimage库并修改feature.py文件,实现了LBP特征的提取,并给出了完整的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图像特征提取方法 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()



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值