颜色矩的特征提取



 转载于

    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实现:

 
  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));  
function createColorHistograms(im_str)

if ~isstr(im_str)
    if ndims(im_str)==3
        try
            col_array_vals=double(im_str);
        catch
            disp('Input is not a valid three-dimensional array');
            return;
        end
    end
else
    try
        col_array_vals=double(imread(im_str));
        if ndims(col_array_vals)~=3
            disp('Input is not a valid three-dimensional array');
            return;
        end

    catch
        disp('Input string does not point to a valid image file');
        return;
    end
end

res_val=90;

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));
t_count=sort(t_count(:));

[col_val,ind_first]=unique(t_count,'first');
[col_val,ind_last]=unique(t_count,'last');
disp('Drawing color bars')

disp('Drawing image')
subplot(121);
set(gcf,'position',[5   61   274   236]);
imshow(col_array_vals/255)
colorbars(col_val,ind_last-ind_first,1/3,1/4)


function colorbars(triplet_color,triplet_freq,varargin)

if nargin==2
    color_pow=1/3;
    freq_pow=1/4;
else
    color_pow=varargin{1};
    freq_pow=varargin{2};
end

N_rand=randperm(length(triplet_freq));
triplet_freq=sqrt(triplet_freq(N_rand));
triplet_color=triplet_color(N_rand);

triplet_color=([rem(triplet_color,256) floor(rem(triplet_color,256*256)/255) floor(triplet_color/(256*256))]/255);
triplet_color_norm=triplet_color./repmat(((sum(triplet_color.^(1),2))+.005),1,3);
max(triplet_color_norm)
triplet_diff=sum(abs(triplet_color_norm-repmat(triplet_color_norm(end,:),size(triplet_color_norm,1),1)),2);

triplet_diff=sum(abs(triplet_color_norm-repmat([.9 0 0],size(triplet_color_norm,1),1)),2);

max(triplet_diff)

triplet_diff=(triplet_diff/max(triplet_diff).^(color_pow))+(triplet_freq*0).^(freq_pow);



[d,inds_sort]=sort(triplet_diff);
triplet_freq=(triplet_freq(inds_sort));
triplet_color=(triplet_color(inds_sort,:));

num_bars=length(triplet_color);
max_val=max(triplet_freq);
% close all;
subplot(122);
axis([0 num_bars 0 1]);
%% 
    [~,ind] = max(triplet_freq);
    triplet_color(ind,:)=[];
    triplet_freq(ind,:)=[];
    num_bars = num_bars-1;
%%   
for i=1:num_bars
    tempColor=min(triplet_color(i,:),.9);
    %===
    % Use patch to draw individual bars
    %===
    patch([i-1 i-1 i i],...
        [0 triplet_freq(i)/max_val triplet_freq(i)/max_val 0],...
        tempColor,...
        'edgecolor',...
        tempColor);
    
end
% colorbar('LineWidth',1);

set(gca,'xtick',[0:10:255])
set(gca,'ytick',[0:0.05:1])
set(gcf,'position',[5 378 560 420]);
set(gca,'visible','on')

function y_val=sigmoidVal(x_val,varargin)

if nargin==1
    multip_val=15;
else
    multip_val=varargin{1};
end

y_val=1./(1+exp(-(x_val-.5)*multip_val));

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: MATLAB中的颜色提取颜色特征是通过计算图像的颜色分布统计量来描述图像的颜色信息。颜色提取是一种将高维的图像信息转化为低维特征向量的方法,能够有效表征图像的颜色特征,具有较好的鲁棒性和计算效率。 在MATLAB中,可以使用RGB颜色空间或HSV颜色空间来进行颜色的计算。首先,需要加载图像数据,并将其转化为RGB颜色阵或HSV颜色阵。然后,可以使用MATLAB中的统计函数,如mean、var、cov等,来计算图像的颜色。 常用的颜色包括一阶(平均值)、二阶(方差)、三阶(偏度)、四阶(峰度)等。这些值能够反映图像中颜色的亮度、对比度、分布等特征。通过计算颜色,可以得到一个低维度的特征向量,用来表示图像的颜色特征颜色提取方法的优点是提取特征向量维度低,易于存储和比较,适用于大规模图像库的颜色检索。同时,颜色特征对图像的亮度和对比度变化较为鲁棒,能够有效区分不同颜色类别的图像。然而,颜色特征无法准确表示纹理和结构信息,对于具有复杂纹理的图像,可能无法很好地区分。 总之,MATLAB中的颜色提取方法能够通过计算图像的颜色分布统计量来描述图像的颜色特征,从而实现颜色信息的分析和处理。 ### 回答2: MATLAB可以利用颜色方法提取图像的颜色特征颜色是描述颜色分布的一种统计特征,主要分为一阶、二阶和三阶颜色。 一阶颜色包括颜色分布的均值以及标准差。均值反映了图像颜色分布的平均色调,标准差则表示了颜色分布的离散程度。 二阶颜色包括颜色协方差阵,用于描述颜色之间的相关性。可以通过计算不同颜色通道的像素值的协方差来获取相关信息。 三阶颜色颜色的最高阶,包括颜色阵位置信息。它通过计算颜色心位置来描述颜色在图像中的位置分布情况。 为了提取颜色特征,可以通过调用MATLAB的图像处理工具箱中的函数,如`rgb2lab`将RGB图像转换为LAB颜色空间,然后使用`imhist`函数计算每个通道的颜色直方图,进而得到颜色分布的均值和标准差。同时,也可使用相关函数,如`cov`计算颜色协方差阵,或使用`mean`计算颜色阵的中心位置。 颜色提取颜色特征的好处是不受图像大小或旋转等变换的影响,能够在多个颜色空间中有效提取特征。这些颜色特征可以用于图像分类、目标检测、图像检索等应用中。 ### 回答3: Matlab可以通过颜色提取颜色特征颜色是一种用于描述图像颜色分布的特征向量。它可以用来衡量图像中颜色的变化和集中程度。 颜色的计算过程如下: 1. 首先将图像转换到HSV(Hue, Saturation, Value)颜色空间。HSV颜色空间可以更好地表示颜色信息。 2. 将颜色空间划分为若干个子区域,通常是16x16x16。 3. 遍历图像的每个像素点,统计每个子区域中的像素数量。 4. 计算一阶(平均值),二阶(方差),三阶(偏度)和四阶(峰度)。 计算出来的颜色特征可以用于图像检索、图像分类和图像识别等领域。综合考虑不同颜色之间的相似性和差异性,可以实现对图像的更准确的描述和分析。 Matlab提供了很多用于计算颜色的函数和工具包,比如imhist()用于计算直方图,std()用于计算方差等。通过这些函数,我们可以方便地获取图像的颜色特征。 总之,通过使用Matlab提供的函数和工具包,我们可以很容易地提取图像的颜色特征,用于进一步的图像处理和分析。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值