From: N JK on
Hi Matlab users,
Does anyone know of a method that will pull out the indices of multiple polygons specified by a mask, for example, say I have a matrix with two polygons:

mask = [ 0 1 0 0 0;
0 1 1 0 0;
0 0 0 0 1;
0 0 0 1 1;]

The problem is trivial with one polygon, but separating indices into separate polygons takes a little more work... anyone know of the function I'm looking for?

Thanks!
NK
From: Walter Roberson on
N JK wrote:
> Hi Matlab users, Does anyone know of a method that will pull out the
> indices of multiple polygons specified by a mask, for example, say I
> have a matrix with two polygons:
>
> mask = [ 0 1 0 0 0;
> 0 1 1 0 0;
> 0 0 0 0 1;
> 0 0 0 1 1;]
>
> The problem is trivial with one polygon, but separating indices into
> separate polygons takes a little more work... anyone know of the
> function I'm looking for?

use bwlabel() to separate the polygons; then the indices become simple matters
of find(labeledmask == polygonnumber)