Thanks to Judd for excellent examples.  

In addition, putting an extra layer of pixels around the image is a good 
approach to simplify the coding, too.  I used to put one layer of object (i.e. 
1s), including corner pixels.  This ensures that there will be no erosion from 
edges.  This has the same effect to duplicate the edge rows/columns as in 
Judd's example.  New corner pixels need to be 1s also, to avoid erosion from 
corners in case of using a "ones(3)" structure element.

For gray image operation, I think that putting one layer of pixels with highest 
intensity would do the same.

Thanks

 Li-Ping (Li) Yuan





________________________________
From: Judd Storrs <jsto...@gmail.com>
To: Søren Hauberg <so...@hauberg.org>
Cc: octave-dev@lists.sourceforge.net; lipingy...@yahoo.com
Sent: Thu, June 24, 2010 9:25:10 AM
Subject: Re: [OctDev] imerode erodes from edges in Octave but not Matlab.

Here's another example:

Evil:

>> A = ones(5) ;
>> A(2,1) = 0 ;
>> A(5,5) = 0
A =

     1     1     1     1     1
     0     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     0

>> imerode(A,[0,0,0;1,1,1;0,0,0])
ans =

     1     1     1     1     1
     0     0     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     0     0


In octave we get:

> imerode(A,[0,0,0;1,1,1;0,0,0])
ans =

   0   1   1   1   0
   0   0   1   1   0
   0   1   1   1   0
   0   1   1   1   0
   0   1   1   0   0

I think Evil just replicates the boundary values but I'm not entirely
sure what happens to the corners. The correct result can be had in
octave by:

B = ones(7) ;
B(2:6,2:6) = A ;
B(1,2:6) = A(1,:) ;
B(7,2:6) = A(5,:) ;
B(2:6,1) = A(:,1) ;
B(2:6,7) = A(:,5)
B =

   0   1   1   1   1   1   0
   1   1   1   1   1   1   1
   0   0   1   1   1   1   1
   1   1   1   1   1   1   1
   1   1   1   1   1   1   1
   1   1   1   1   1   0   0
   0   1   1   1   1   0   0

imerode(B,[0,0,0;1,1,1;0,0,0])(2:6,2:6)
ans =

   1   1   1   1   1
   0   0   1   1   1
   1   1   1   1   1
   1   1   1   1   1
   1   1   1   0   0

But I'm not sure what values goes in B(1,1), B(1,7), B(7,1), B(7,7).


--judd
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to