[scilab-Users] Finding continuous parts in a mask (ie a binary matrix)

Samuel GOUGEON Samuel.Gougeon at univ-lemans.fr
Tue Mar 8 13:11:52 CET 2011


  Hello Antoine,

----- Message d'origine -----
De : Antoine Monmayrant
Date : 08/03/2011 10:58:
> Hi everyone,
>
> I have question that is more about image filtering than scilab, but I haven't 
> found any answer so far so I'm turning towards scilab users.
> I am looking for a way to determine continuous parts in a matrix made of 1 or 0.
> Basically, this matrix is used as a mask to filter an image and I need to 
> determine the number of isolated "grains" (ie continuous parts where the 
> matrix is equal to 1) in this mask.
> As an example, here is a mask:
>
> -->mask
>  mask  =
>
>     0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>     0.    0.    0.    0.    0.    0.    1.    1.    1.    0.
>     0.    0.    0.    0.    0.    0.    1.    1.    1.    0.
>     0.    0.    0.    0.    0.    0.    1.    1.    1.    0.
>     0.    1.    1.    0.    0.    0.    0.    0.    0.    0.
>     0.    1.    1.    1.    0.    0.    0.    0.    0.    0.
>     0.    0.    1.    1.    0.    0.    0.    0.    0.    0.
>     0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>     0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>     0.    0.    0.    0.    0.    0.    0.    0.    0.    0.
>
There are first a number of decisions to be taken about
waht you will consider being a acceptable domain:

* Do you consider 2 domains just connected by a right wire as distincts ?
     0.    0.    0.    0.    0.    0.    0.    0.
     0.    1.    1.    0.    0.    0.    0.    0.
     0.    1.    1.    1.    0.    0.    0.    0.
     0.    0.    1.    1.    0.    0.    0.    0.
     0.    0.    0.    1.    0.    0.    0.    0.
     0.    0.    0.    1.    1.    0.    0.    0.
     0.    0.    1.    1.    1.    1.    0.    0.
Likely no. There are the same...

* Do you consider 2 domains just connected by a diagonal wire as distincts?
     0.    0.    0.    0.    0.    0.    0.    0.
     0.    1.    1.    0.    0.    0.    0.    0.
     0.    1.    1.    1.    0.    0.    0.    0.
     0.    0.    1.    1.    0.    0.    0.    0.
     0.    0.    0.    0.    1.    1.    0.    0.
     0.    0.    0.    1.    1.    1.    0.    0.
     0.    0.    0.    1.    1.    1.    0.    0.
This is a classic neighbouring option

*  Do you consider only doubly connex domains, so with no hole(s), unlike here?:
     0.    0.    0.    0.    0.    0.    0.    0.
     0.    1.    1.    1.    0.    0.    0.    0.
     1.    1.    0.    1.    0.    0.    0.    0.
     1.    1.    0.    1.    0.    0.    0.    0.
     0.    1.    1.    2.    0.    0.    0.    0.
     0.    0.    0.    0.    0.    0.    0.    0.

* Do you consider only un-nested domain? Counter-example:
     0.    1.    1.    1.    0.    1.    0.    0.
     0.    1.    1.    1.    1.    1.    1.    0.
     1.    1.    0.    0.    0.    0.    1.    0.
     1.    1.    0.    Z.    Z.    0.    1.    0.
     1.    1.    0.    0.    0.    0.    1.    0.
     0.    1.    1.    1.    1.    1.    1.    0.
     0.    0.    1.    1.    1.    1.    0.    0.

IMO, it is hard to implement and discuss any algo before answering to all these 
cases.

Regards
Samuel




More information about the users mailing list