lhidrawsubgraph.m

来自「This code can parse any image in matlab.」· M 代码 · 共 68 行

M
68
字号
function img = LHIdrawsubgraph(varargin)
% Draw the subgraphs in an image.
% LHIdrawsubgraph(annotation, img)
% LHIdrawsubgraph(database, ndx, HOMEIMAGES)
%
% Example:
%   [annotation, img] = LHIread(filename, HOMEIMAGES)
%   LHIdrawsubgraph(annotation, img)

switch length(varargin)
   case 2
       annotation = varargin{1};
       img = varargin{2};
   case 3
       D = varargin{1};
       ndx = varargin{2};
       
       if ndx>length(D)
           error('Index out of range');
       end
       
       HOMEIMAGES = varargin{3};

       annotation = D(ndx).annotation;
       %img = imread(fullfile(HOMEIMAGES, annotation.folder, annotation.filename));
       img = LMimread(D, ndx, HOMEIMAGES); % Load image
   otherwise
       error('Input arguments not right.')
end

imgsize = size(img);
if ((ndims(imgsize)==3))
    img = grb2gray(img);
end
% Draw each object (only non deleted ones)
if isfield(annotation, 'object')
   Nobjects = length(annotation.object); n=0;
   for i = 1:Nobjects

       if (isfield(annotation.object(i),'subgraphs'))
           img =drawImageObject(img, annotation.object(i));
       end
       Nparts = length(annotation.object(i).parts);
       for j=1:Nparts
           if(isfield(annotation.object(i).parts(j),'subgraphs'))
               img = drawImageObject(img, annotation.object(i).parts(j));
               %text(0,0,annotation.object(i).parts(j).name);
           end
       end
   end
end


function img = drawImageObject(img,object)
Nsubgraphs = length(object.subgraphs);
[height,width]=size(img);
h = 0;
for i = 1:Nsubgraphs
    Ncurves = length(object.subgraphs(i).curves);
    for j =1:Ncurves
        [X,Y] = getLHIpoints(object.subgraphs(i).curves(j));
        X(X<1)=1; X(X>width)=width; Y(Y<1)=1; Y(Y>height)=height;
        for k = 1:(length(X)-1),
            img = func_DrawLine(img, Y(k),X(k),Y(k+1),X(k+1),255);
        end
    end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?