From: Christian Eschermann on
Hello,

I need the centres of the „0-areas“ in a 2-dim 0-1-array . Moreover I need the size of each area.

Example:

z = [
1 1 0 1 1;
1 0 0 0 1;
1 1 0 1 1;
1 1 1 1 1;
1 0 0 0 1]

Result:

Centre, Area:
C1 = 12, A1 = 5
C2 = 15, A2 = 3

It’s easy to find centres by using „mean“. But I need a hint how to differentiate between different 0-areas.

For the area-sizes I found this:

>> z = [1 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1];
>> l = findstr([0 z 0],[1 0])-findstr([0 z 0],[0 1])

l =

3 2 1 2 3

Problem: „findstr“ doesn’t work in a 2-dim array. Is there any alternative?


Thank you.
Christian
From: Sean on
"Christian Eschermann" <christian.eschermann(a)still.de> wrote in message <hsbeu8$f82$1(a)fred.mathworks.com>...
> Hello,
>
> I need the centres of the &#8222;0-areas&#8220; in a 2-dim 0-1-array . Moreover I need the size of each area.
>
> Example:
>
> z = [
> 1 1 0 1 1;
> 1 0 0 0 1;
> 1 1 0 1 1;
> 1 1 1 1 1;
> 1 0 0 0 1]
>
> Result:
>
> Centre, Area:
> C1 = 12, A1 = 5
> C2 = 15, A2 = 3
>
> It&#8217;s easy to find centres by using &#8222;mean&#8220;. But I need a hint how to differentiate between different 0-areas.
>
> For the area-sizes I found this:
>
> >> z = [1 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1];
> >> l = findstr([0 z 0],[1 0])-findstr([0 z 0],[0 1])
>
> l =
>
> 3 2 1 2 3
>
> Problem: &#8222;findstr&#8220; doesn&#8217;t work in a 2-dim array. Is there any alternative?
>
>
> Thank you.
> Christian

Do you have the image processing toolbox? If so:
>>help bwconncomp
>>help regionprops
Those two will do exactly what you want.