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

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

[Octave-bug-tracker] [bug #62452] [octave forge] (image) bwmorph spur pr


From: anonymous
Subject: [Octave-bug-tracker] [bug #62452] [octave forge] (image) bwmorph spur produces wrong result
Date: Wed, 18 May 2022 12:40:44 -0400 (EDT)

Follow-up Comment #12, bug #62452 (project octave):

I figured out the following generating function:

1 . Pad the image with the value 1.
2.  Use the structuring elements described in Wikipedia [1] to find the end
points and remove them. If the end-points image consists of two elements
connnected components like this:


    [1 1] , [1; 1] , [1 0; 0 1] , [0 1; 1 0]


- For the vertical pattern keep the top element.
- For the horizontal pattern keep the left element.
- For the diagonal patterns keep the right element.
  However it seems that MATLAB has a random behavior. For example in the case
of the diagonal pattern it sometimes keeps the left element and sometime keeps
the right element.

3. Keep sigle pixels.
4. Remove the padded border.

The generating function would be:


bw = padarray (bw, [1 1], true);

endpoints_fcn = @(x) x(5) && ((x(2) && all (! x([4 6 7 8 9])))...
  ||(x(4) && all (! x([2 3 6 8 9])))...
  ||(x(8) && all (! x([1 2 3 4 6])))...
  ||(x(6) && all (! x([1 2 4 7 8])))...
  ||(sum(x(:)) == 2 && any (x(:) & [1 0 1;0 0 0;1 0 1](:))));

endpoints_lut = makelut(endpoints_fcn, 3);   

endpoints_image = applylut(bw, lut);

endpoints_keep_fcn = @(x) (x(5) && sum(x(:)) == 2 ...
  && any (x(:) & [1 0 0;0 0 1;1 1 0](:)))...          # two elements pattern
  || (x(5) && sum(x(:)) == 1);                        # single pixel

endpoints_keep_lut = makelut(endpoints_keep_fcn, 3);  

remaining_endpoints_image = applylut(endpoints_image, endpoints_keep_lut);

bw = xor(bw, remaining_endpoints_image);

bw = bw(2:end-1, 2:end-1);


By precomputing the look-up table the function will be reduced to (to be used
in bwmorph.m):
  
  
lut1 = false (512, 1);
lut2 = false (512, 1);

lut1 ([18,19,20,21,23,24,25,26,49,53,81,89,90,145,209,273,305,309,401,465]) =
true;
lut2 ([17, 19, 25, 81, 273]) = true;

morph = @(x) xor (x, applylut (applylut (padarray (x, [1 1], true), lut1),
lut2)(2:end-1, 2:end-1));
  

[1] https://en.wikipedia.org/wiki/Pruning_(morphology)#Structuring_Elements


    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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