||
1.Introduction
颜色相关直方图(color correlogram),结合了图像中的颜色与空间信息,用颜色之间(不同颜色或相同颜色)的量化距离来构建直方图。而传统的颜色直方图只考虑了颜色信息。如下示例:
左侧的图像与右侧的图像具有相同的颜色直方图信息;如果不考虑颜色之间的空间位置关系信息,很难区分两个图。
2.Modeling
假设图像的记号为I(x,y),x、y为空间坐标;包含的颜色有C1,C2,C3...Cn.设置两种颜色之间的距离为d.那我们将生成这样的一个直方图:它的bin的个数为n的平方(颜色的组合数目),对于其中的每个Bin,Bin的大小为
Bin(Ci,Cj) = Σx,y{||I(x,y,Ci)-I(x,y,Cj)|| = d}。其中,||*||表示像素值为Ci,Cj的两个像素的空间距离,然后统计这样的像素个数。所以,要是设置不同的距离d1,d2,d3...dm(共D个).那个Bin的维数为(n*n*D)。
进一步,我们只考虑相同颜色之间空间关系,就称为颜色自相关图(color auto-correlogram)那个Bin的维数为(n*D)。
3.Experiment
Color histogram rank: 310 Autocorrelogram rank: 5
这个是颜色相关图在基于内容的图像检索中的应用,比原来的rank结果提高了。
4.Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function output = ColorCorrelogram(rgb,d)
R = rgb(:,:,1);
G = rgb(:,:,2);
B = rgb(:,:,3);
R_BITS = 2;%bit量化
G_BITS = 2;
B_BITS = 2;
size_color = 2^R_BITS*2^G_BITS*2^B_BITS;%归一化后的颜色种数
R1=bitshift(R,-(8-R_BITS));
G1=bitshift(G,-(8-G_BITS));
B1=bitshift(B,-(8-B_BITS));
%包含的颜色种数为:4x4x4
I=R1+G1*2^R_BITS+B1*2^R_BITS*2^B_BITS;%新生图像
temp = zeros(size_color,1);
os = offset(d);
s = size(os);
for i = 1:s(1)
offset = os(i,:);
glm = GLCMATRIX(I,offset,size_color);
temp = temp+glm;
end
hc = zeros(size_color,1);
for j = 0:size_color-1
hc(j+1) = numel(I(I == j));%Index为j的计数
end
output = temp./(hc+eps);
output = output/(8*d);
end
function os = offset(d)
[r,c] = meshgrid(-d:d,-d:d);
r = r(:);
c = c(:);
os = [r c];
bad = max(abs(r),abs(c)) ~= d;
os(bad,:) = [];
end
function out = GLCMATRIX(si,offset,nl)
s = size(si);%图像大小
[r,c] = meshgrid(1:s(1),1:s(2));%网格化,很明显
r = r(:);%向量化
c = c(:);%向量化
r2 = r+offset(1);%加偏置
c2 = c+offset(2);%加偏置
bad = c2<1|c2>s(2)|r2<1|r2>s(1);%筛选出index不在图像内的点
Index = [r c r2 c2];%原始距离与相对距离的矩阵
Index(bad,:) = [];%剔除坏点
v1 = si(sub2ind(s,Index(:,1),Index(:,2)));%从索引到数据
v2 = si(sub2ind(s,Index(:,3),Index(:,4)));
v1 = v1(:);
v2 = v2(:);
Ind = [v1 v2 ];
bad = v1~=v2;%这里计算的是颜色自相关图
Ind(bad,:) = [];
if isempty(Ind)
oneGLCM2 = zeros(nl);
else
oneGLCM2 = accumarray(Ind+1,1,[nl,nl]);
end
out = [];
for i = 1:nl
out = [out oneGLCM2(i,i)];
end
out = out(:);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Reference
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-27 00:20
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社