资源简介
程明明老师Global contrast based salient region detection的HC部分的matlab实现,测试很快,好用。文件很全,包括HC.m , RGB2lab.m , lab2RGB.m ,作者的源代码也放了进去。
代码片段和文件信息
%function saliency = HC(img_name)
%读取图像
%orpic = imread(img_name);
orpic = imread(‘1_1.bmp‘)
%获取图像的长、宽和通道值
[row column nn] = size(orpic);
%%将颜色的RGB通道都由256量化成12,再选择能包含其中95%颜色数据的颜色,其余颜色归到选择的颜色中
%生成调色板pallet(colornumber)
pallet = zeros(row*column2);
%设置阶梯值,为了将rgb量化后的结果化成一个12进制的数
w = [12*12121];
idx = uint32(1);
SUM = uint32(0);
RGBSUM = zeros(rowcolumn);
for i = 1 : row
for j = 1 : column
%获取第i行第j列的R、G、B通道的值,并量化为12阶后再转化为一个数
a1 = floor((double(orpic(ij1))/255)*(12-0.0001))*w(3);
%a2 = floor((double(orpic(ij2))/255)*(12-0.0001))*w(2);
%a3 = floor((double(orpic(ij3))/255)*(12-0.0001))*w(1);
%SUM = int32(a1) + int32(a2) + int32(a3);
SUM = 3* int32(a1);
RGBSUM(ij) = SUM;
%找出处理后的数据有多少种颜色值,以及其频数
if idx == 1
pallet(idx1) = SUM;
pallet(idx2) = pallet(idx2) + 1;
idx = idx + 1;
continue;
end;
flag = 0;
for m = 1 : idx-1
if pallet(m1) == SUM
pallet(m2) = pallet(m2) + 1;
flag = 1;
break;
end;
end
if flag == 0
pallet(idx1) = SUM;
pallet(idx2) = pallet(idx2) + 1;
idx = idx + 1;
end;
end
end
%获取图中所有的颜色值
idx = idx -1;
pallet = pallet(1:idx:);
%生成新的调色板num(numbercolor),使得颜色按照频数从大到小排列,且一号位为频数大小,二号位为处理后的颜色值
palletemp = pallet(:2);
[bpos] = sort(palletemp‘descend‘);
num = zeros(idx2);
for i = 1 : idx
num(i1) = b(i);
num(i2) = pallet(pos(i)1);
end
%计算如果要保留95%的处理后的颜色值,需要保留调色板的多少位
maxnum = idx;
maxdropnum = floor(row*column*(1-0.95));
crnt = num(maxnum1);
while(crnt1)
crnt = crnt + num(maxnum-11);
maxnum = maxnum - 1;
end;
%保证保留的颜色值小于256且尽量不太小
maxnum = min(maxnum256);
if maxnum < 10
maxnum = min(idx100);
end;
%将处理后的颜色值转化回RGB对应的值
color3i = zeros(idx3);
for i = 1:idx
color3i(i1) = round(num(i2)/w(1));
color3i(i2) = round(mod(num(i2)w(1))/w(2));
color3i(i3) = round(mod(num(i2)w(2)));
end;
%建立色板pallet(numbercolorpos),其中pos为保留颜色的序号
a = zeros(idx1);
pallet = [numa];
for i = 1:maxnum
pallet(i3) = i;
end;
%将舍弃的颜色归到其最相近的颜色当中
for i = (maxnum+1):idx
simidx = 99999999;simval = 99999999;
for j = 1:maxnum
d_ij = round((color3i(i1)-color3i(j1))^2 + (color3i(i2)-color3i(j2))^2 + (color3i(i3)-color3i(j3))^2);
if d_ij < simval
simval = d_ij;
simidx = j;
end;
end;
pallet(simidx1) = pallet(simidx1) + pallet(i1);
pallet(i3) = simidx;
end;
%将图像中属于某一“颜色值”的所有颜色的rgb值累加之后求平均再归一,即调整保留下来颜色值
rgbcolor = zeros(idx4);
for n =1:idx
for i = 1:row
for j = 1:column
if RGBSUM(ij) == pallet(n2)
rgbcolor(n1) = int32(rgbcolor(n1)) + int32(orpic(ij1));
%rgbcolor(n2) = int32(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-14 09:31 HC、RC方法\
文件 98304 2014-03-11 15:03 HC、RC方法\1_1.bmp
文件 19917 2017-10-29 16:27 HC、RC方法\583.jpg
文件 30942 2017-10-23 10:17 HC、RC方法\cat.jpg
目录 0 2017-12-13 21:14 HC、RC方法\CmCode-master\
文件 124 2017-07-14 15:37 HC、RC方法\CmCode-master\.gitignore
文件 572 2017-07-14 15:37 HC、RC方法\CmCode-master\clean.bat
文件 5404 2017-07-14 15:37 HC、RC方法\CmCode-master\CmCode.sln
目录 0 2017-12-13 21:14 HC、RC方法\CmCode-master\CmLib\
目录 0 2017-12-13 21:14 HC、RC方法\CmCode-master\CmLib\Basic\
文件 20401 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmCv.cpp
文件 7295 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmCv.h
文件 2494 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmDefinition.cpp
文件 7731 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmDefinition.h
文件 11113 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmFile.cpp
文件 7021 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmFile.h
文件 2082 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Basic\CmTimer.h
目录 0 2017-12-13 21:14 HC、RC方法\CmCode-master\CmLib\Cluster\
文件 1673 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Cluster\CmAPCluster.cpp
文件 4552 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Cluster\CmAPCluster.h
文件 12224 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Cluster\CmColorQua.cpp
文件 2827 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Cluster\CmColorQua.h
文件 4572 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Cluster\CmGMM.cpp
文件 17468 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\Cluster\CmGMM.h
文件 3587 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\CmLib.h
文件 16304 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\CmLib.vcxproj
文件 9662 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\CmLib.vcxproj.filters
目录 0 2017-12-13 21:14 HC、RC方法\CmCode-master\CmLib\CRF\
文件 1223 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\CRF\fastmath.h
文件 13835 2017-07-14 15:37 HC、RC方法\CmCode-master\CmLib\CRF\permutohedral.h
目录 0 2017-12-13 21:14 HC、RC方法\CmCode-master\CmLib\Illustration\
............此处省略423个文件信息
评论
共有 条评论