📄 lhiregulatenames.m
字号:
function [db,excludelist] = LHIregulatenames(db, HOMELABELMAPS, NEWHOMELABELMAPS, namelistfile)
%
% D = LHIregulatenames(D, HOMEIMAGES, HOMELABELMAPS)
%
% namelist: {'sky','ground,court,playground','water,sea',...}
fid=fopen(namelistfile);
ni = 1;
tline={};
while 1
line = fgetl(fid);
if ~ischar(line), break, end
if strcmp(line(1),'%'), continue, end
tline{ni} = line;
ni = ni + 1;
end
fclose(fid);
namelist = {};
for i=1:length(tline)
query = parseContent(tline{i});
namelist{i} = strrep(query{1},'+','');
tline{i} = strrep(tline{i},' ','+');
db = LHIreplaceobjectname(db, tline{i}, namelist{i}{1}, 'rename','word');
end
excludelist = [];
for i=1:length(namelist)
excludelist = strcat(excludelist,'-',namelist{i});
end
excludelist = excludelist{1};
excludelist=strrep(excludelist,' ','-');
if nargout == 2
return;
end
db = LHIreplaceobjectname(db, excludelist, 'other', 'rename','word');
[names, counts, imagendx, objectndx, descriptionndx] = LHIobjectnames(db);
[ff, ndx] = sort(counts,'descend');
imagendx = imagendx(ndx);
objectndx = objectndx(ndx);
Nimage = length(db);
for i=1:Nimage,
i
labelmap = LHILMread(db,i,HOMELABELMAPS);
mapcpy = labelmap;
%initialize color to other
for j=1:length(names)
if (strcmp(names{ndx(j)},'other'))
[R,G,B] = getRGB(j);
break;
end
end
a = uint8(reshape([R,G,B],1,1,3));
labelmap = repmat(a, [size(labelmap,1),size(labelmap,2)]);
%begin labelmap layout
for j=1:length(names)
jc = LHIobjectindex(db(i).annotation, strrep(names{ndx(j)},' ','+'),'word');
[R,G,B] = getRGB(j);
for k=1:length(jc)
color = db(i).annotation.object(jc(k)).labelmap;
if length(color) == 0
continue;
end
mask = ((mapcpy(:,:,1)==str2num(color.R))&(mapcpy(:,:,2) == str2num(color.G))&(mapcpy(:,:,3) == str2num(color.B)));
labelmap = imoverlay(labelmap,mask,[R;G;B]);
color.R = num2str(R); color.B=num2str(B); color.G = num2str(G);
db(i).annotation.object(jc(k)).labelmap = color;
end
end
if (~isdir(fullfile(NEWHOMELABELMAPS, db(i).annotation.folder)))
mkdir(fullfile(NEWHOMELABELMAPS, db(i).annotation.folder));
end
filename = fullfile(NEWHOMELABELMAPS, db(i).annotation.folder, strrep(db(i).annotation.filename,'.jpg','.png'));
imwrite(labelmap,filename);
end
Nclass = length(names);
table = zeros(Nclass,4,3);
for i=1:Nclass
namenew{i} = names{ndx(i)};
[R,G,B] = getRGB(i);
table(i,1,:) = R;
table(i,2,:) = G;
table(i,3,:) = B;
table(i,4,:) = [R,G,B];
end
figure;
imagesc(uint8(table));
set(gca, 'YTick', 1:Nclass);
set(gca, 'YtickLabel', namenew);
set(gca, 'XTick', 1:4);
set(gca, 'XtickLabel', {'R','G','B','color'});
legend
function [valR,valG,valB] = getRGB(id)
j=0; valR = 0; valG = 0; valB = 0;
while( id >0)
valR = bitor(valR, bitshift(bitand(bitshift(id,-0),1),(7-j)));
valG = bitor(valG, bitshift(bitand(bitshift(id,-1),1),(7-j)));
valB = bitor(valB, bitshift(bitand(bitshift(id,-2),1),(7-j)));
id = bitshift(id, -3);
j = j+1;
end%while
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -