📄 lhiplotsubgraph.m
字号:
function [h, class] = LHIplotsubgraph(varargin)
% Visualizes the subgraphs in an image.
%
% LHIplotsubgraph(annotation, img)
% LHIplotsubgraph(annotation, img, 1) display point id
% or
% LHIplotsubgraph(database, ndx, HOMEIMAGES)
%
% Example:
% [annotation, img] = LMread(filename, HOMEIMAGES)
% LMplot(annotation, img)
%
% thumbnail = size of the image
% The plot uses only 7 colors, therefore, some times, different object.
% Classes might have the same color assigned.
%
% If an object has the field 'confidence', the thickness of the bounding
% box will be equal to the confidence.
bshowid = 0;
switch length(varargin)
case 1
annotation = varargin{1};
img = -1;
case 2
annotation = varargin{1};
img = varargin{2};
case 3
if(ischar(varargin{3}))
D = varargin{1};
ndx = varargin{2};
if ndx>length(D)
return
end
HOMEIMAGES = varargin{3};
annotation = D(ndx).annotation;
%img = imread(fullfile(HOMEIMAGES, annotation.folder, annotation.filename));
img = LHIimread(D, ndx, HOMEIMAGES); % Load image
else
%% display keypoint ids
annotation = varargin{1};
img = varargin{2};
bshowid = varargin{3};
end
otherwise
error('Too many input arguments.')
end
% Define colors
colors = 'rgbcmyw';
colors = hsv(15);
% Draw image
%figure;
if size(img,1)>1
image(uint8(img)); axis('off'); axis('equal'); hold on
if size(img,3) == 1
colormap(gray(256))
end
else
axis('off'); axis('equal'); hold on
end
% Draw each object (only non deleted ones)
h = []; class = [];
if isfield(annotation, 'object')
Nobjects = length(annotation.object); n=0;
for i = 1:Nobjects
n = n+1;
class{n} = annotation.object(i).name; % get object name
col = colors(mod(sum(double(class{n})),15)+1, :);
if (isfield(annotation.object(i),'subgraphs'))
h(n)=drawObject(annotation.object(i),col,bshowid);
%title(class{i});
end
Nparts = length(annotation.object(i).parts);
for j=1:Nparts
if(isfield(annotation.object(i).parts(j),'subgraphs'))
h(n)=drawObject(annotation.object(i).parts(j),col,bshowid);
%text(0,0,annotation.object(i).parts(j).name);
end
end
end
if nargout == 0
legend(h, class);
end
%drawnow
end
function h = drawObject(object,col,bshowid)
Nsubgraphs = length(object.subgraphs);
h = 0;
ptCount = 1;
for i = 1:Nsubgraphs
Ncurves = length(object.subgraphs(i).curves);
for j =1:Ncurves
[X,Y] = getLHIpoints(object.subgraphs(i).curves(j));
markSize = 1; LineWidth = 1;
plot(X,Y,'LineWidth', LineWidth, 'color', [0 0 0]); hold on
h = plot(X,Y,'-o','MarkerFaceColor','g','MarkerEdgeColor','k',...
'MarkerSize',markSize,'LineWidth', LineWidth/2, 'color', col);
Npts = length(X);
if (bshowid)
for k=1:Npts,
text(X(k),Y(k),num2str(ptCount));
ptCount = ptCount + 1;
end
end
hold on
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -