Description

[xb,yb] = mask2outline(x,y,mask) returns the coordinates xb,yb of the outline of a 2D mask whose input coordinates pixel centers are given by x,y.

[xb,yb] = mask2outline(x,y,mask,'buffer',buf) specifies a buffer in units of x,y to place around the mask. For example, if the units of x and y are meters and buf=10e3, then that places a 10 km buffer around the mask. The buffer can be negative to buffer into the mask.

[xb,yb] = mask2outline(...,'region',N) only returns the outline of the Nth largest region by area.

Example

% Load the default peaks dataset:
[X,Y,Z] = peaks(500);

% Convert x,y coordinates to something like meters to make it intuitive:
X = X*1000;
Y = (Y+5)*1000;

% Define a mask as anything where Z>5:

figure
xlabel 'eastings (m)'
ylabel 'northings (m)' Let's say you want to find the coordinates that mark the boundary of the mask:

% Plot the border with a red outline:
hold on
plot(xb,yb,'r','linewidth',2) Buffer the border

Suppose you want to buffer the border by 600 meters:

% Plot the border with a red dotted outline:
plot(xb,yb,'r:','linewidth',2) Multipe sections

figure
xlabel 'eastings (m)'
ylabel 'northings (m)' The same method as above works. (This is really just an exercise in the documentation to ensure consistent behavior in case of future changes to the function).

% Plot the border with a red outline:
hold on
plot(xb,yb,'r','linewidth',2) Buffer in: This time we'll buffer into each mask by 200 m: 