颜色矩的特征提取

来源:互联网 发布:淘宝女式冲锋衣 编辑:程序博客网 时间:2024/04/30 00:36


 转载于

    http://blog.csdn.net/langb2014/article/details/45557935

颜色特征是一种全局特征,描述了图像或图像区域所对应的景物的表面性质.一般颜色特征是基于像素点的特征,此时所有属于图像或图像区域的像素都有各自的贡献.由于颜色对图像或图像区域的方向、大小等变化不敏感,所以颜色特征不能很好地捕捉图像中对象的局部特征.另外,仅使用颜色特征查询时,如果数据库很大,常会将许多不需要的图像也检索出来.颜色直方图是最常用的表达颜色特征的方法,其优点是不受图像旋转和平移变化的影响,进一步借助归一化还可不受图像尺度变化的影响,基缺点是没有表达出颜色空间分布的信息.

(颜色直方图):

       A color histogram of an image represents the distribution of the composition of colors in the image. It shows different types of colors appeared and the number of pixels in each type of the colors appeared. The relation between a color histogram and a luminance histogram is that a color histogram can be also expressed as “Three Color Histograms”, each of which shows the brightness distribution of each individual Red/Green/Blue color channel.

      使用最多的可能就是灰度直方图,而它丢失了很多颜色信息,所以努力实现颜色直方图,它能够直接代表实际图中的颜色的数量。

MATLAB实现:

 
[plain] view plain copy print?
  1. function createColorHistograms(im_str)  
  2.   
  3. if ~isstr(im_str)  
  4.     if ndims(im_str)==3  
  5.         try  
  6.             col_array_vals=double(im_str);  
  7.         catch  
  8.             disp('Input is not a valid three-dimensional array');  
  9.             return;  
  10.         end  
  11.     end  
  12. else  
  13.     try  
  14.         col_array_vals=double(imread(im_str));  
  15.         if ndims(col_array_vals)~=3  
  16.             disp('Input is not a valid three-dimensional array');  
  17.             return;  
  18.         end  
  19.   
  20.     catch  
  21.         disp('Input string does not point to a valid image file');  
  22.         return;  
  23.     end  
  24. end  
  25.   
  26. res_val=90;  
  27.   
  28. t_count=res_val*floor(col_array_vals(:,:,1)/res_val)+256*(res_val*floor(col_array_vals(:,:,2)/res_val))+256*256*(res_val*floor(col_array_vals(:,:,3)/res_val));  
  29. t_count=sort(t_count(:));  
  30.   
  31. [col_val,ind_first]=unique(t_count,'first');  
  32. [col_val,ind_last]=unique(t_count,'last');  
  33. disp('Drawing color bars')  
  34.   
  35. disp('Drawing image')  
  36. subplot(121);  
  37. set(gcf,'position',[5   61   274   236]);  
  38. imshow(col_array_vals/255)  
  39. colorbars(col_val,ind_last-ind_first,1/3,1/4)  
  40.   
  41.   
  42. function colorbars(triplet_color,triplet_freq,varargin)  
  43.   
  44. if nargin==2  
  45.     color_pow=1/3;  
  46.     freq_pow=1/4;  
  47. else  
  48.     color_pow=varargin{1};  
  49.     freq_pow=varargin{2};  
  50. end  
  51.   
  52. N_rand=randperm(length(triplet_freq));  
  53. triplet_freq=sqrt(triplet_freq(N_rand));  
  54. triplet_color=triplet_color(N_rand);  
  55.   
  56. triplet_color=([rem(triplet_color,256) floor(rem(triplet_color,256*256)/255) floor(triplet_color/(256*256))]/255);  
  57. triplet_color_norm=triplet_color./repmat(((sum(triplet_color.^(1),2))+.005),1,3);  
  58. max(triplet_color_norm)  
  59. triplet_diff=sum(abs(triplet_color_norm-repmat(triplet_color_norm(end,:),size(triplet_color_norm,1),1)),2);  
  60.   
  61. triplet_diff=sum(abs(triplet_color_norm-repmat([.9 0 0],size(triplet_color_norm,1),1)),2);  
  62.   
  63. max(triplet_diff)  
  64.   
  65. triplet_diff=(triplet_diff/max(triplet_diff).^(color_pow))+(triplet_freq*0).^(freq_pow);  
  66.   
  67.   
  68.   
  69. [d,inds_sort]=sort(triplet_diff);  
  70. triplet_freq=(triplet_freq(inds_sort));  
  71. triplet_color=(triplet_color(inds_sort,:));  
  72.   
  73. num_bars=length(triplet_color);  
  74. max_val=max(triplet_freq);  
  75. % close all;  
  76. subplot(122);  
  77. axis([0 num_bars 0 1]);  
  78. %%   
  79.     [~,ind] = max(triplet_freq);  
  80.     triplet_color(ind,:)=[];  
  81.     triplet_freq(ind,:)=[];  
  82.     num_bars = num_bars-1;  
  83. %%     
  84. for i=1:num_bars  
  85.     tempColor=min(triplet_color(i,:),.9);  
  86.     %===  
  87.     % Use patch to draw individual bars  
  88.     %===  
  89.     patch([i-1 i-1 i i],...  
  90.         [0 triplet_freq(i)/max_val triplet_freq(i)/max_val 0],...  
  91.         tempColor,...  
  92.         'edgecolor',...  
  93.         tempColor);  
  94.       
  95. end  
  96. % colorbar('LineWidth',1);  
  97.   
  98. set(gca,'xtick',[0:10:255])  
  99. set(gca,'ytick',[0:0.05:1])  
  100. set(gcf,'position',[5 378 560 420]);  
  101. set(gca,'visible','on')  
  102.   
  103. function y_val=sigmoidVal(x_val,varargin)  
  104.   
  105. if nargin==1  
  106.     multip_val=15;  
  107. else  
  108.     multip_val=varargin{1};  
  109. end  
  110.   
  111. y_val=1./(1+exp(-(x_val-.5)*multip_val));  
0 0