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

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

[Octave-bug-tracker] [bug #52933] [octave-forge] (image) regionprops Per


From: Avinoam Kalma
Subject: [Octave-bug-tracker] [bug #52933] [octave-forge] (image) regionprops Perimeter returns Matlab incompatible results
Date: Mon, 22 Jan 2018 13:05:39 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

Follow-up Comment #4, bug #52933 (project octave):

Please review the following code


function perim = rp_perimeter (cc, bw)
  CHAIN_CODE = [3, 2, 1, 4, -1, 0, 5, 6, 7];
  if (! islogical (bw)) # Then input was not really a bw. Create it.
    bw = false (cc.ImageSize);
    bw(cell2mat (cc.PixelIdxList(:))) = true;
  endif

  no = cc.NumObjects;
  boundaries = bwboundaries (bw, 8, "noholes");
  npx = cellfun ("size", boundaries, 1);
  perim = zeros(no, 1, 'double');
  for i=1:no
    if (npx(i) == 2)
## single pixel - perimeter is 0      
      perim(i) = 0;
    else

## calculating perimeter according to Vossepoel and Smeulders,
## Computer Graphics and Image Processing 20(4):347-364, 1982.
## see: Cris Luengo, "Measuring boundary length" 
## http://www.crisluengo.net/index.php/archives/310

      # boundary of component i
      boundary = boundaries {i};
      # distance between consequtive pixels in the boundary
      dists = boundary (2:end,:) - boundary (1:end-1,:) + 2;
      # converting x_y distances to vector
      dists_vec = dists(:,2) + (dists(:,1)-1)*3;
      # converting distances to chain code
      chain_code = CHAIN_CODE (dists_vec);
      # odd numbers in the chain code - digonal movement
      odd =  sum(mod (chain_code, 2));
      # even entries in the chain code - vetical of digonal movement
      even = npx(i) - 1 - odd;
      # corners are places where the chain code changes value
      chain_code_change = chain_code - [chain_code(end),
chain_code(1:end-1)];
      corners = numel(find (chain_code_change != 0));
      # using Vossepoel and Smeulders formula
      perim(i) = even*0.980 + odd*1.406 - corners*0.091;
    endif
  endfor

## old code, should be used with perimeterold option  
#cdists = diff (cell2mat (boundaries));
# dists(cumsum (npx)(1:end-1),:) = [];
# dists = sqrt (sumsq (dists, 2));

# subs = repelems (1:no, [1:no; (npx-1)(:)']);
# perim = accumarray (subs(:), dists(:), [no 1]);
endfunction


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?52933>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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