No BSD License  

Highlights from
GeoML

image thumbnail
from GeoML by Gabriele Lombardi
A general morphable template tool for image segmentation.

GeoMLIterate(model,join,mode)
function pts = GeoMLIterate(model,join,mode)
% GEOMLITERATE  Iterate on a model.
%
% function pts = GeoMLIterate(model,join,mode)
%
%  Iterate on a model and generate the points that describes
% its curves. An iteration mode can be specified and can be:
%
%  int  =  This is the default mode and allow to obtain the pixel
%         coordinates of a model.
%  real =  In this case the pixel real values are returned, the number of
%         elements can be different.
%
%  Params
%  ------
% IN:
%  model    = The model to iterate on.
%  join     = Must the points be joined in a single sequence? (def=true)
%  mode     = The iteration mode. (def='int')
% OUT:
%  pts      = A cell containing the points for each part of the model.
%
%  Pre
%  ---
% -  model must be a model and mode must be either 'int' or 'real'.
%
%  Post
%  ----
% -  The points are returned in the order given from the model, as column
%   points in a cell.

% Check params:
if nargin<1 error('A model must be provided.'); end
if nargin<2 join = true; end
if nargin<3 mode = 'int'; end

% Importing classes:
import com.dsi.libs.geoml.iterate.*;

% Check the mode:
switch mode
    case 'int'
        pim = PIMCoordsInt;
    case 'real'
        pim = PIMCoords;
    otherwise
        error('A correct mode string must be provided!');
end

% Iterating on the model:
o = PixelIterator.iterateOnPaths(model,pim,true);

% Extracting points:
nsh = size(o,1);
if join
    % All in a single array:
    sze = 0;
    for ind=1:nsh
        sze = sze + size(o(ind),1)/2;
    end
    pts = zeros(2,sze);
    % Iterating on parts:
    pos = 1;
    for ind=1:nsh
        % Reshaping the data:
        nel = size(o(ind),1)/2;
        pts(:,pos:pos+nel-1) = reshape(o(ind),[2,nel]);
        pos = pos + nel;
    end
else
    % All in a cell:
    pts = cell([1,nsh]);
    % Iterating on parts:
    for ind=1:nsh
        % Reshaping the data:
        pts{ind} = reshape(o(ind),[2,size(o(ind),1)/2]);
    end
end

Contact us at files@mathworks.com