Changeset 14580


Ignore:
Timestamp:
04/15/13 14:23:24 (12 years ago)
Author:
Eric.Larour
Message:

CHG: some mods on morphological routines

Location:
issm/trunk-jpl/src/m/morphological
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/morphological/aggregation.m

    r14525 r14580  
    1 function mask=aggregation(mask,windowsize,threshhold)
    2 %congrid algorithm using windowsize pixel neighboors.
     1function [mask,varargout]=aggregation(mask,windowsize,threshhold,varargin)
     2%AGGREGATION - aggregation of an image to a lower sized image
     3%
     4%  mask is an image of arbitrary size, format binary, with values 1 for foreground, and 0 for background
     5%  mask is first convoluted with a square matrix of size windowsize (where windowsize is an even number),
     6%       it is then filtered according to the threshhold value, and finally subsampled using 1/windowsize as
     7%       sample scaling.
     8%  x,y can be provided as optional arguments, as coordinates of the center points of the mask. aggregation will
     9%       then return subsampled x,y arguments in output.
     10%
     11%  Usage:   mask2=aggregation(mask,7,7^2/2);
     12%           [mask2,x2,y2]=aggregation(mask,7,7^2,x,y];
     13%
     14%  See also CLOSING, OPENING, DILATION, EROSION
    315
    4 %check on windowsize
     16%check input arguments  %{{{
     17%even windowsize
    518if mod(windowsize,2)==0,
    619        error('windowsize should be an even number');
    720end
    821
    9 %convolve:
     22%check on presence of varargin:
     23optional=0;
     24if nargin>3,
     25        if nargin~=5,
     26                help aggregation;
     27                error('wrong number of optional arguments specified');
     28        else
     29                optional=1;
     30                x=varargin{1};
     31                y=varargin{2};
     32        end
     33end
     34
     35%check on presence of varargout:
     36if optional,
     37        if nargout~=3,
     38                help aggregation;
     39                error('wrong number of optional output arguments specified');
     40        end
     41end
     42%}}}
     43
     44%convolve mask
    1045matrix=ones(windowsize,windowsize);
     46mask=filter2(matrix,mask,'same');
    1147
    12 %convolve mask:
    13 mask=filter2(matrix,double(mask),'same');
    14 
     48%apply threshhold
    1549pos=find(mask>threshhold);
    1650pos2=find(mask<=threshhold);
     
    1852mask(pos2)=0;
    1953
    20 %now subsample:
     54%mask has been transformed into double format from the filter2  operation. Bring back to binary.
     55mask=logical(mask);
     56
     57%subsample:
    2158s=size(mask);
    2259mask=mask(1:windowsize:s(1),1:windowsize:s(2));
     60
     61if optional,
     62        s=size(mask);
     63        varargout{1}=x(1:windowsize:s(2));
     64        varargout{2}=y(1:windowsize:s(1));
     65end
  • issm/trunk-jpl/src/m/morphological/vectorialize.m

    r14536 r14580  
    11function contours=vectorialize(mask,connectivity);
    22
    3         vec=bwboundaries(mask,8);
     3        vec=bwboundaries(mask,connectivity);
    44       
    55        contours=struct([]);
Note: See TracChangeset for help on using the changeset viewer.