zoukankan      html  css  js  c++  java
  • R语言代写Gabor滤波进行目标图像纹理特征的提取

    Gabor特征已广泛用于图像分析和处理(字符和面部识别)。Gabor(诺贝尔奖获得者,电气工程师和物理学家)使用了以下措辞,我认为在这个小插图中值得一提,“你无法预测未来,但你可以发明它。” 

    在下面的几行中,我将描述GaborFeatureExtract R6类,其中包括以下方法,

    GaborFeatureExtract
    gabor_filter_bank()
    gabor_feature_extraction()
    gabor_feature_engine()
     这些方法基于Matlab代码Gabor Feature Extraction of M. Haghighat,S。Zonouz,M.Abdel-Mottaleb,“CloudID:Trustworthy cloud-based and cross-enterprise biometric identification,”Expert Systems with Applications,vol。42,不。21,pp.7905-7916,2015http://dx.doi.org/10.1016/j.eswa.2015.06.025。修改了最初的Matlab代码(我添加了Magnitude特性和gabor_feature_engine()方法),并在可能的地方使用Rcpp进行并行化。



    Gabor功能

     我在CRAN(综合R档案网络)上进行了常规搜索,但我找不到任何与Gabor特征提取相关的内容(截至2018年8月),因此我决定将Matlab代码移植到R中。网上有很多资源如果有人打算加深他/她对这个主题的了解,我会在Vignette的末尾添加一些我觉得有用的内容(参考文献)。 

    gabor_filter_bank

    gabor_filter_bank方法“......生成自定义尺寸的Gabor滤波器组。它创建一个UxV单元阵列,其元素是MxN矩阵; 根据Matlab代码的作者,每个矩阵都是2-D Gabor滤波器。以下代码块显示了它在R中是如何工作的,

    library(OpenImageR)
    
    
    init_gb = GaborFeatureExtract$ ()
    
    #------------------
    # gabor-filter-bank
    #------------------
    
    gb_f = init_gb$ (scales = 5, orientations = 8, gabor_rows = 39,
    
                                     gabor_columns = 39, plot_data = TRUE)
    
    
    #-----------------------------------------------
    # plot of the real part of the gabor-filter-bank
    #-----------------------------------------------
    
    plt_f = init_gb$ (real_matrices =  $gabor_real, margin_btw_plots = 0.65,
    
                               thresholding = FALSE)

    对于gabor_filter_bank,我使用5个刻度和8个方向来构建大小为39 x 39的过滤器。该方法的输出是长度为3的列表,

    str(gb_f)
    List of 3
     $ gaborArray     :List of 40
      ..$ : cplx [1:39, 1:39] -1.58e-12-0.00i 0.00-5.02e-12i 1.50e-11-0.00i ...
      ..$ : cplx [1:39, 1:39] 4.86e-08-3.96e-08i 1.02e-07+4.63e-08i 6.31e-09+1.93e-07i ...
      ..$ : cplx [1:39, 1:39] 6.24e-06-6.24e-06i 1.18e-05+0.00i 1.10e-05+1.10e-05i ...
      ..$ : cplx [1:39, 1:39] -6.69e-05-3.18e-05i -4.63e-05-7.20e-05i -1.60e-06-9.81e-05i ...
      ..$ : cplx [1:39, 1:39] 1.40e-04+5.81e-05i 1.15e-04+1.15e-04i 6.68e-05+1.61e-04i ...
    .......
     $ gabor_imaginary:List of 40
      ..$ : num [1:39, 1:39] -4.65e-27 -5.02e-12 -1.10e-26 4.21e-11 -2.99e-25 ...
      ..$ : num [1:39, 1:39] -3.96e-08 4.63e-08 1.93e-07 1.53e-07 -3.04e-07 ...
      ..$ : num [1:39, 1:39] -6.24e-06 4.84e-20 1.10e-05 2.01e-05 1.81e-05 ...
      ..$ : num [1:39, 1:39] -3.18e-05 -7.20e-05 -9.81e-05 -9.58e-05 -5.78e-05 ...
      ..$ : num [1:39, 1:39] 5.81e-05 1.15e-04 1.61e-04 1.86e-04 1.83e-04 ...
    .......
     $ gabor_real     :List of 40
      ..$ : num [1:39, 1:39] -1.58e-12 5.54e-27 1.50e-11 -4.12e-26 -1.11e-10 ...
      ..$ : num [1:39, 1:39] 4.86e-08 1.02e-07 6.31e-09 -2.85e-07 -4.28e-07 ...
      ..$ : num [1:39, 1:39] 6.24e-06 1.18e-05 1.10e-05 -8.11e-20 -1.81e-05 ...
      ..$ : num [1:39, 1:39] -6.69e-05 -4.63e-05 -1.60e-06 5.73e-05 1.12e-04 ...
      ..$ : num [1:39, 1:39] 1.40e-04 1.15e-04 6.68e-05 -3.77e-19 -7.57e-05 ...
    .......

    第一个子列表(gaborArray)由复杂类型的40个矩阵(5个刻度×8个方向)组成,其中每个matix的尺寸为39 x 39(gabor滤波器)。第二个子列表(gabor_imaginary)是虚部(数字),而第三个子列表是实部(gabor_real)。实部(数字)用于绘制gabor滤波器。

    该文档包含所使用的每个参数的更多详细信息。

    gabor_feature_extraction

    gabor_feature_extraction方法提取图像的Gabor特征。与初始Matlab代码相比,此方法得到修改,以便用户可以选择对图像进行下采样或对特征进行标准化。此外,我添加了Magnitude功能,因为根据文献,它提高了可预测性。

    基于前面提到的car.png图像,

    # read image
    #-----------
    
    pth_im = system.file("tmp_images", "car.png", package = "OpenImageR")
    
    im = readImage(pth_im) * 255
    
    
    # gabor-feature-extract
    #----------------------
    
    gb_im = init_gb$ (image = im, scales = 5,  ,
    
                                                 downsample_rows = NULL,
    
                                              downsample_col 
                                                , plot_data = TRUE, 
                                              
                                              normalize_features = FALSE, threads = 3)

    此函数再次返回长度为3的列表,

     

    其中gaborFeatures是提取的特征,其行数等于nrow(im)x ncol(im)(或166 x 249),列数等于scale x orientationations(或5 x 8)。第二和第三个子列表是与gabor滤波器卷积后得到的图像的虚部和实部。以下代码块允许用户绘制图像的不同比例方向

    plt_im = init_gb$plot_gabor(real_matrices = gb_im$  , thresholding = FALSE)

    通过将gb_im $ gabor_features_real对象(比例,方向)阈值化为 [0,1],可以直观地探索图像,

    # thresholding parameter is set to TRUE
    #--------------------------------------
    
    plt_im_thresh = init_gb$plot_gabor(real_matrices   ,
    
                                       margin_btw_plots = 0.65, thresholding = TRUE)

    gabor_feature_engine

    gabor_feature_engine方法是初始Matlab代码的扩展,并且允许用户从多个图像中提取Gabor特征。此方法的工作方式与HOG_apply方法相同,后者采用图像矩阵(如mnist数据集),并在处理后返回要素。以下示例说明如何将gabor_feature_engine方法与mnist数据集一起使用,

    
     
    
    
    mnist <- read.table(unz("mnist.zip", "mnist.csv"), nrows = 70000, header = T, 
                        
                        quote = """, sep = ",")
     
    
    dat = init_gb$gabor_feature_engine(img_data = x, img_nrow = 28, img_ncol = 28,
    
                                        scales = 4, orientations = 8, gabor_rows = 13,
    
                                        gabor_columns = 13, downsample_gabor = FALSE,
    
                                        downsample_rows = NULL, downsample_cols = NULL,
    
                                        normalize_features = FALSE, threads = 6, 
                                        
                                        verbose = TRUE)
    
    Time to complete : 4.111672 mins 
     str(dat)
    List of 2
     $ magnitude      : num [1:70000, 1:3136] 0 0 0 0 0 0 0 0 0 0 ...
     $ energy_aptitude: num [1:70000, 1:64] 2682 2576 1399 1178 2240 ...

    DAT目的是长度为2的列表中的第一子列表对应于幅度,而第二子列表到本地能量均值性向。在计算mnist数据的准确性之前要做的第一件事是减少幅度特征的维数(我将使用irlba包来实现此目的),

     

    并且我将创建一个缩小幅度能量 - 能力数据的中心缩放矩阵,

     

    然后我将利用nmslibR库(近似方法'hnsw')来计算mnist数据的准确性,

     
     

    我将使用HOG_apply函数执行相同的操作

     
     

    通过平均gaborHoG特征,平均准确度增加到98.34%,这非常接近于KernelKnn(98.4)的HoG +强力方法的得分

     

    如果您有任何疑问,请在下面发表评论。 

  • 相关阅读:
    Codeforces Gym 100571A A. Cursed Query 离线
    codeforces Gym 100500 J. Bye Bye Russia
    codeforces Gym 100500H H. ICPC Quest 水题
    codeforces Gym 100500H A. Potion of Immortality 简单DP
    Codeforces Gym 100500F Problem F. Door Lock 二分
    codeforces Gym 100500C D.Hall of Fame 排序
    spring data jpa 创建方法名进行简单查询
    Spring集成JPA提示Not an managed type
    hibernate配置文件中的catalog属性
    SonarLint插件的安装与使用
  • 原文地址:https://www.cnblogs.com/tecdat/p/10530900.html
Copyright © 2011-2022 走看看