📄 lhidbshowimage.m
字号:
function LHIdbshowimage(D, imageIndex, HOMEIMAGES)
%
% Shows hierarchical decomposition of a single image.
%
% LHIdbshowimage(D, imageIndex, HOMEIMAGES)
Nx = 14; Ny = 14;
Dy = 1/Ny; Dx = 1/Nx;
y = Ny-5; x=0; %original image
handle=figure;maximize(handle); %maximize current display window
%% Plot whole image
axes('position',[x*Dx y*Dy 5*Dx 5*Dy]);
img = LHIimread(D,imageIndex,HOMEIMAGES);
scaling = min(1,320/size(img,1)); %height normalize to 320 or smaller
[annotation,img] = LHIimscale(D(imageIndex).annotation, img, scaling, 'nearest');
[h,class] = LHIplot(annotation, img);
%% Plot objects
p.xOri = 5;
p.x = p.xOri; p.y = Ny - 1.5; p.Dx = Dx;
p.Dy = Dy; p.Nx = Nx; p.Ny = Ny;
p.yOffset = 0.5; ;
Nobjects = length(D(imageIndex).annotation.object);
for i=1:Nobjects
p.level = ['OBJECT',num2str(i)];
object = annotation.object(i);
[h,p]= plotObject(object,img,annotation,p);
drawnow;
end
%% Plot objects' parts
y = min(y,p.y);
for i=1:Nobjects
object = annotation.object(i);
if (length(object.parts)<=0) continue;
end
p.y=min(p.y,y)-2.5;p.x=0; y = p.y;
if p.y<0
p.y = Ny-2.5; y=p.y;
handle=figure;maximize(handle);
end
X=[];Y=[];
Nregions = length(object.regions);
for j=1:Nregions
[a,b] = getLHIpoints(object.regions(j));
X = [X;a]; Y = [Y;b];
end
Nsubgraphs = length(object.subgraphs);
for j=1:Nsubgraphs
Ncurves = length(object.subgraphs(j).curves);
for k=1:Ncurves
[a,b] = getLHIpoints(object.subgraphs(j).curves(k));
X = [X;a]; Y = [Y;b];
end
end
if (Nsubgraphs == 0 & Nregions == 0), continue; end;
[nrows ncols c] = size(img);
crop(1) = max(min(X)-2,1);
crop(2) = min(max(X)+2,ncols);
crop(3) = max(min(Y)-2,1);
crop(4) = min(max(Y)+2,nrows);
crop = round(crop);
% Image crop:
h = axes('position', [p.x*p.Dx p.y*p.Dy 2*p.Dx 2*p.Dy]); % create axis
imgCrop = img(crop(3):crop(4), crop(1):crop(2), :);
image(imgCrop); axis('off'); axis('equal'); hold on;
title(h,['OBJECT',num2str(i),':',object.name]);
drawnow
Nparts = length(object.parts);
p.xOri = 2;
p.x=p.xOri; p.y = p.y + 1;
if (Nparts>0)
for j=1:Nparts,
p.level = ['PART',num2str(j)];
part = object.parts(j);
[h,p]=plotObject(part,img,annotation,p);
drawnow
end
end
end
%% plotObject function
function [h,p] = plotObject(object,img,annotation,p)
%% Get object crop boundary
[nrows ncols c] = size(img);
X={};Y={};Xs={};Ys={}; %initialize
Nregions = 0; Nsubgraphs = 0; h=[];
Nregions = length(object.regions);
for j=1:Nregions
[a,b] = getLHIpoints(object.regions(j));
X{j} = a; Y{j} = b;
end
Nsubgraphs = length(object.subgraphs);
count = 1;
for j=1:Nsubgraphs
Ncurves = length(object.subgraphs(j).curves);
for k=1:Ncurves
[a,b] = getLHIpoints(object.subgraphs(j).curves(k));
Xs{count} = a; Ys{count} = b;
count = count + 1;
end
end
if (Nsubgraphs == 0 & Nregions == 0), return; end;
matX=[]; matY=[];
for i=1:length(Xs)
matX = [matX; Xs{i}];
matY = [matY; Ys{i}];
end
for i=1:length(X)
matX = [matX; X{i}];
matY = [matY; Y{i}];
end
crop(1) = max(min(matX)-2,1);
crop(2) = min(max(matX)+2,ncols);
crop(3) = max(min(matY)-2,1);
crop(4) = min(max(matY)+2,nrows);
crop = round(crop);
%% End of crop boundary
%% Image crop:
imgCrop = img(crop(3):crop(4), crop(1):crop(2), :);
imgwhite = ones(size(imgCrop)); imgwhite(:) = 1.0;
h = axes('position', [p.x*p.Dx p.y*p.Dy 1.5*p.Dx p.Dy]); % create axis
title(h,[p.level,':',object.name]);axis('off'); axis('equal'); hold on;
if (Nsubgraphs == 0) % Single image
h = axes('position', [p.x*p.Dx p.y*p.Dy 1.5*p.Dx p.Dy]); % create axis
xStep = 1.5;
else
h = axes('position', [p.x*p.Dx p.y*p.Dy p.Dx p.Dy]); % create axis;
xStep = 2;
end
image(imgCrop); axis('off'); axis('equal'); hold on;
if (length(X)>0)
for i=1:length(X)
plot([X{i};X{i}(1)]-crop(1)+1, [Y{i};Y{i}(1)]-crop(3)+1, 'r', 'linewidth', 2);
end
end
%text(Dx,Dy+0.8,object.name);
if Nsubgraphs > 0
h = axes('position', [(p.x+1)*p.Dx p.y*p.Dy p.Dx p.Dy]); % create axis
image(imgwhite);axis('off'); axis('equal'); hold on;
for i=1:length(Xs),
plot(Xs{i}-crop(1)+1, Ys{i}-crop(3)+1, '-o','MarkerFaceColor','g','MarkerEdgeColor','k',...
'MarkerSize',2,'LineWidth',1 ,'color', 'b');
end
end
%% Calculate offset
p.x = p.x+xStep;
if p.x>p.Nx-xStep
p.x = p.xOri; p.y = p.y-(1+p.yOffset);
if p.y<0
p.y = p.Ny-(1+p.yOffset);
handle=figure;maximize(handle);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -