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

 
 

bug #50188: [octave forge] (image) poly2mask does incompatible rounding

Submitter:  Hartmut <hardy>
Submitted:  Mon 30 Jan 2017 08:07:25 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Jan 2017 11:37:53 PM UTC, comment #1: 

There is an (still imperfect) fix for this bug in patch #9244 (inside the function rp_convex_image). It might be a starting point to generate a proper solution for this bug.

Hartmut <hardy>
Mon 30 Jan 2017 08:07:25 PM UTC, original submission:  

This happens with the current image-2.6.1 package and Octave 4.2.0.

The current Octave implementation of poly2mask.m rounds its polygon input values to the nearest integer (and correctly says so in its documentation).

In contrast, the Matlab implementation of poly2mask.m also uses fractional input values, and does some 5-by-5 subsampling of pixels. See the Matlab documentation: https://de.mathworks.com/help/images/ref/poly2mask.html#f6-465457

As a result the output values between the Octave and the Matlab version of poly2mask are different.

Here is some typical code that shows the difference, and can be used for implementing an improved version of Octave's poly2mask:


clear;

poly_a = [...
    2   2.5
    1.5 3
    2   3.5
    4   3.5
    4.5 3
    4   2.5
    2   2.5];

mask_a = poly2mask( poly_a(:,1), poly_a(:, 2), 5, 5)

mask_a_matlab = logical([ ...
     0     0     0     0     0
     0     0     0     0     0
     0     1     1     1     0
     0     0     0     0     0
     0     0     0     0     0])

poly_b = [...
    2 2
    9 4
    9 5
    2 5
    2 2];

mask_b = poly2mask( poly_b(:,1), poly_b(:, 2), 6, 11)

mask_b_matlab = logical([ ...
     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0
     0     0     1     1     1     0     0     0     0     0     0
     0     0     1     1     1     1     1     1     0     0     0
     0     0     1     1     1     1     1     1     1     0     0
     0     0     0     0     0     0     0     0     0     0     0])


The current output of Octave is:


mask_a =

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

mask_a_matlab =

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

mask_b =

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

mask_b_matlab =

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


(I hit this bug while implementing a new feature in regionprops.m. I will probably work around this bug in regionprops, to not introduce more dependencies of patches. This means that a future fix to this bug could have a look what's been done in regionprops.m for the 'ConvexImage' calculation.)

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 (Submitted the item)
  • -email is unavailable- added by hardy (add people to cc who care about the image package)
  • -email is unavailable- added by hardy (add people to cc who care about the image package)
  •  

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-26 mtmiller Release4.2.0 dev
    2017-08-12 jwe Summaryimage package: poly2mask does incompatible rounding [octave forge] (image) poly2mask does incompatible rounding
    2017-01-30 hardy Carbon-Copy- Added avinoam
        Carbon-Copy- Added carandraug

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code