Gabor特征已广泛用于 图像分析和处理(字符和面部识别)。 Gabor(诺贝尔奖获得者,电气工程师和物理学家)使用了以下措辞,我认为在这个小插图中值得一提, “你无法预测未来,但你可以发明它。”
在下面的几行中,我将描述 GaborFeatureExtract R6类,其中包括以下方法,
GaborFeatureExtract |
---|
gabor_filter_bank() |
gabor_feature_extraction() |
gabor_feature_engine() |
这些方法基于Matlab代码 Gabor Feature Extraction of M. Haghighat,S。Zonouz,,“CloudID:Trustworthy cloud-based and cross-enterprise biometric identification,”Expert Systems with Applications,vol。42,不。21,, http://。修改了最初的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 = = 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] .....$ : cplx [1:39, 1:39] .....$ : cplx [1:39, 1:39] .....$ : cplx [1:39, 1:39] .....$ : cplx [1:39, 1:39] ..........$ gabor_imaginary:List of 40..$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] ..........$ gabor_real :List of 40..$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] - .....$ : num [1:39, 1:39] .....$ : num [1:39, 1:39] ..........
第一 个子列表( gaborArray)由复杂类型的40个矩阵(5个刻度×8个方向)组成,其中每个matix的尺寸为39 x 39(gabor滤波器)。第二 个子列表( gabor_imaginary)是虚部(数字),而第三 个子列表是实部( gabor_real)。实部(数字)用于绘制gabor滤波器。
该文档包含所使用的每个参数的更多详细信息。
gabor_feature_extraction
该 gabor_feature_extraction方法提取图像的Gabor特征。与初始Matlab代码相比,此方法得到修改,以便用户可以选择对图像进行下采样或对特征进行标准化。此外,我添加了 Magnitude功能,因为根据 文献,它提高了可预测性。
基于前面提到的 图像,
# read image#-----------pth_im = ("tmp_images", "", 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 = , thresholding = TRUE)
gabor_feature_engine
该 gabor_feature_engine方法是初始Matlab代码的扩展,并且允许用户从多个图像中提取Gabor特征。此方法的工作方式与 HOG_apply方法相同,后者采用图像矩阵(如mnist数据集),并在处理后返回要素。以下示例说明如何将 gabor_feature_engine方法与mnist数据集一起使用,
mnist <- (unz("", ""), 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 : 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函数执行相同的 操作,
通过平均 gabor和 HoG特征,平均准确度增加到%,这非常接近于 KernelKnn()的 HoG +强力方法的得分,
来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。