octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #55172] [octave forge] (image) b = bwmorph (BW


From: Avinoam Kalma
Subject: [Octave-bug-tracker] [bug #55172] [octave forge] (image) b = bwmorph (BW, 'thin', 1) is not Matlab compatible
Date: Sat, 8 Dec 2018 03:39:59 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36

Follow-up Comment #2, bug #55172 (project octave):

Matlab algoirthm for bwmorph (BW, 'thin') is based on the paper 
 "Thinning Methodologies - A Comprehensive Survey", by Louisa Lam, Seong-Whan
Lee, and Ching Y. Suen, published in IEEE Transactions on Pattern Analysis and
Machine Intelligence, 
Vol 14, No. 9, September 1992.
https://pdfs.semanticscholar.org/0404/ba243ecbb8efc6bcb07a754b6f8770856131.pdf.

The specific algorithm used by matlab appears on page 879, bottom of first
column through top of second column.
The algorithm has two steps:


function ret = thin_fun1 (A)
  
## stage 1 in thin algorithm

  x1 = A(2,3);
  x2 = A(1,3);
  x3 = A(1,2);
  x4 = A(1,1);
  x5 = A(2,1);
  x6 = A(3,1);
  x7 = A(3,2);
  x8 = A(3,3);
  
  p = A(2,2);

## condition 1
  b1 = (~x1) & (x2 | x3);
  b2 = (~x3) & (x4 | x5);
  b3 = (~x5) & (x6 | x7);
  b4 = (~x7) & (x8 | x1);
  xh = b1 + b2 + b3 + b4;
  
## condition 2
  n1 = (x1 | x2) + (x3 | x4) + (x5 | x6) + (x7 | x8);
  n2 = (x2 | x3) + (x4 | x5) + (x6 | x7) + (x8 | x1);
  m = min(n1, n2);
 
## condition 3
  G3 = (x2 | x3 | (!x8)) & x1;  
  G3 = ~G3;

## point p is deleted iff all three condistions are true  
  ret = p & (~((xh == 1) & (m == 2 | m == 3) & G3));
  
end


and 2nd step:


function ret = thin_fun2 (A)
  
## stage 2 in thin algorithm

  x1 = A(2,3);
  x2 = A(1,3);
  x3 = A(1,2);
  x4 = A(1,1);
  x5 = A(2,1);
  x6 = A(3,1);
  x7 = A(3,2);
  x8 = A(3,3);
  
  p = A(2,2);

## condition 1
  b1 = (~x1) & (x2 | x3);
  b2 = (~x3) & (x4 | x5);
  b3 = (~x5) & (x6 | x7);
  b4 = (~x7) & (x8 | x1);
  xh = b1 + b2 + b3 + b4;
  
## condition 2
  n1 = (x1 | x2) + (x3 | x4) + (x5 | x6) + (x7 | x8);
  n2 = (x2 | x3) + (x4 | x5) + (x6 | x7) + (x8 | x1);
  m = min(n1, n2);
 
## condition 3
  G3 = (x6 | x7 | (~x4)) & x5;
  G3 = ~G3;

## point p is deleted iff all three condistions are true  
  ret = p & (~((xh == 1) & (m == 2 | m == 3) & G3));
  
end


We can use a LUT to implement the function


function bw2 = thin (bw)
  
  lut1 = makelut (@thin_fun1, 3);
  lut2 = makelut (@thin_fun2, 3);
  
  bw1 = applylut (bw, lut1);
  bw2 = applylut (bw1, lut2);
  end


The LUTs I get are different from the LUTs in current version of bwmorph, and
the final command is different.

Attached a revised version of bwmorph.
Please review.


(file #45596, file #45597, file #45598, file #45599)
    _______________________________________________________

Additional Item Attachment:

File name: thin.patch                     Size:6 KB
File name: thin_fun2.m                    Size:0 KB
File name: thin_fun1.m                    Size:0 KB
File name: thin.m                         Size:0 KB


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?55172>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]