bugGNU Octave - Bugs: bug #52926, [octave forge] (image)...

 
 

bug #52926: [octave forge] (image) regionprops('perimeter') fails with labeled image of conn 4

Submitter:  Hartmut <hardy>
Submitted:  Thu 18 Jan 2018 09:45:44 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 19 Jan 2018 06:22:08 PM UTC, comment #4: 

Thanks for (mostly) fixing this so amazingly fast, Carné.

Hartmut <hardy>
Fri 19 Jan 2018 03:58:38 PM UTC, comment #3: 
  • Throwing an error on the 'perimeter' property with conn=4


The problem is that the Perimeter property must be computed by measuring the distance around elements using connectivity.  That is part of Matlab documentation.  The problem arises when instead of a bw image, we use a labelled image, or a bwconncomp structure, that was generated with a different connectivity and would identify different objects with connectivity 8.

I have fixed it in the stable branch now with
http://hg.code.sf.net/p/octave/image/rev/41b32e3648d3

  • slightly different results when measuring Perimeter


This is Matlab being backwards incompatible. I went to look into Matlab Release Notes and seems like they changed it 2014a

> regionprops function uses new algorithm to calculate perimeter
>
> The regionprops function uses a new algorithm to calculate a perimeter, when used with the 'Perimeter' option. Because of this change, regionprops returns different results for the perimeter calculations than it did in earlier releases.
>
>Compatibility Considerations
>
> While the new algorithm used with regionprops returns more accurate perimeter calculation, you can get the same return value as previous releases by specifying the 'perimeterold' option.


I have opened a new bug #52933 for it

  • slightly different results when measuring eccentricity


This issue was fixed on the image package version 2.6.2.  The computation of Eccentricity is dependent on MajorAxisLength and MinorAxisLength and version 2.6.0 and 2.6.1 had a bug on those.  This has been fixed and released.

Carnë Draug <carandraug>
Group Member
Thu 18 Jan 2018 10:15:22 PM UTC, comment #2: 

(adding people to cc)

Hartmut <hardy>
Thu 18 Jan 2018 10:12:49 PM UTC, comment #1: 

There seem to be several issues with this:

  • Throwing an error on the 'perimeter' property with conn=4 :
    • This definitly is a proper bug.
    • Maybe somewhere in the subfunction rp_perimeter of regionprops.m
    • This seems to be a regression. At least this still works (i.e. does NOT throw any error) with an older version I have.


  • (slightly) different values of the 'perimeter' property:
    • Yes, those are formally a Matlab incompatibility bug.
    • The currenct Octave results seem to be in good agreement with the Matlab help page. But maybe there is some ambiguity in their defition.
    • I am not sure if those small differences will be too big a nuisance in practice.


  • (even slighter) differences in values of the 'eccentricity' property.
    • Yes,this is formally also a Matlab compatibility bug.
    • The only different value is in region 2 with conn=8. (after you get the code running at all with conn=4, by only asking for the eccentricity).
    • I am not sure if those small differences will be too big a nuisance in practice.


So in my opinion, the first thing to fix here, would be the 'perimeter' property with conn=4. I am not sure when I will find the time for this.



Hartmut <hardy>
Thu 18 Jan 2018 09:45:44 PM UTC, original submission:  

quote (slightly adapted) from the mailing list
( http://octave.1599824.n4.nabble.com/Octave-vs-Matlab-regionprops-differences-td4686389.html )

-------------

Hi all,

please try this script in Matlab (with the image processing toolbox) and
in octave (first loading the image package):


BW = logical([1 1 1 0 0 0 0 0
              1 1 1 0 1 1 0 0
              1 1 1 0 1 1 0 0
              1 1 1 0 0 0 1 0
              1 1 1 0 0 0 1 0
              1 1 1 0 0 0 1 0
              1 1 1 0 0 1 1 0
              1 1 1 0 0 0 0 0]);

L = bwlabel(BW, 8);   % ,4 or ,8 (default)
s = regionprops(L, 'Perimeter', 'Eccentricity')

for j = 1:size(s)
   disp(s(j).Perimeter)
   disp(s(j).Eccentricity)
end



Here is the result, with connectivity = 4 or 8, and Matlab or octave:


Connectivity = 4, Matlab:

s =

   3×1 struct array with fields:
     Eccentricity
     Perimeter

    17.2760
     0.9270
     3.5560
      0
     7.0130
     0.9315


Connectivity = 4,  octave

error: vertical dimensions mismatch (1x3 vs 1x2)
error: called from
     regionprops>rp_perimeter at line 767 column 8
     regionprops at line 412 column 26
     testOctaveVSMatlab at line 13 column 3
 >>

Connectivity = 8, Matlab

s =
   2×1 struct array with fields:
     Eccentricity
     Perimeter

    17.2760
     0.9270
    13.1080
     0.9429


Connectivity = 8, octave

s =
   2x1 struct array containing the fields:
     Perimeter
     Eccentricity

  18
  0.92702
  14.243
  0.98641
 >>


As you see, with 4-connectivity, octave breaks. With 8-connectivity,
perimeters and eccentricities are different.

Thanks

Giorgio (Denunzio)

Hartmut <hardy>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by hardy
  • -email is unavailable- added by hardy
  • -email is unavailable- added by hardy (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-02 jwe Summary[octave-forge] (image) regionprops('perimeter') fails with labeled image of conn 4 [octave forge] (image) regionprops('perimeter') fails with labeled image of conn 4
    2018-01-19 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
    2018-01-19 carandraug Summary[octave-forge] (image) regionprops('perimeter') gives unexpected error / 'eccentricicty' inaccurate [octave-forge] (image) regionprops('perimeter') fails with labeled image of conn 4
    2018-01-18 hardy Carbon-Copy- Added carandraug
        Carbon-Copy- Added avinoam

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code