COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### removing isolated element from a matrix

• Email
• Follow

```Is there any simple way to remove the isolated values from a matrix?
The isolated element is the one for instant surrounded by 1 zero in the same row and 2 zeros in the same column and one zero in diagonal...

Assuming:
in=[ 1     1     1     1;...
1     0     1     0;...
1     1     1     1;...
0     0     0     0;...
0     0     0     0;...
0     5     0     0;...
0     0     0     1;...
1     0     0     0;...
0     5     0     0;...
0     0     0     1];

then the out put shall not include the 5 in the 6th row:
out=[ 1     1     1     1;...
1     0     1     0;...
1     1     1     1;...
0     0     0     0;...
0     0     0     0;...
0     0     0     0;...
0     0     0     1;...
1     0     0     0;...
0     5     0     0;...
0     0     0     1];
```
 0

See related articles to this posting

```On 12/14/2011 9:29 AM, SM wrote:
> Is there any simple way to remove the isolated values from a matrix?
> The isolated element is the one for instant surrounded by 1 zero in the
> same row and 2 zeros in the same column and one zero in diagonal...
....

Don't have any great ideas; one possible that comes to mind would be to
convert to a logic array and apply a convolution filter/matching to the
columns in question.  But, don't see any way other than run that across
the area.

Alternatively, might consider turning into an image an looking at it as
a image processing problem of boundaries/edge detection.

Hmmm...that strikes as making the first logical array and it's edge
detection there as well (connected edges, precisely).

--
```
 0
Reply none1568 (7455) 12/14/2011 6:59:22 PM

```dpb <none@non.net> wrote in message <jcarm7\$nm7\$1@speranza.aioe.org>...
> On 12/14/2011 9:29 AM, SM wrote:
> > Is there any simple way to remove the isolated values from a matrix?
> > The isolated element is the one for instant surrounded by 1 zero in the
> > same row and 2 zeros in the same column and one zero in diagonal...
> ...
>
> Don't have any great ideas; one possible that comes to mind would be to
> convert to a logic array and apply a convolution filter/matching to the
> columns in question.  But, don't see any way other than run that across
> the area.
>
> Alternatively, might consider turning into an image an looking at it as
> a image processing problem of boundaries/edge detection.
>
> Hmmm...that strikes as making the first logical array and it's edge
> detection there as well (connected edges, precisely).
>
> --Hi
i would suggest to check
BW2 = bwmorph(BW,operation)
with operation='clean'
it is specificllay aimed toward "Removin isolated pixels (individual 1s that are surrounded by 0s), such as the center pixel in this pattern".

http://www.mathworks.com/help/images/ref/bwmorph.html
Doron
```
 0