bugGNU Octave - Bugs: bug #46392, image package -...


bug #46392: image package - regionprops(bw,'Perimeter') gives incorrect result

Submitter:  Hartmut <hardy>
Submitted:  Fri 06 Nov 2015 08:21:06 PM UTC
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Thu 07 Jul 2016 06:26:11 PM UTC, comment #4: 

regionprops is already working. It's just that some properties  haven't been converted yet. I have done so for Perimeter today http://hg.code.sf.net/p/octave/image/rev/db54e8cb5f9b

Carnë Draug <carandraug>
Group Member
Tue 05 Jul 2016 08:02:53 PM UTC, comment #3: 

Sorry, but I suspect that in the near future I won't find any time to make regionprops.m work again.

Hartmut <hardy>
Fri 24 Jun 2016 10:39:50 PM UTC, comment #2: 

I have pushed your patch http://hg.code.sf.net/p/octave/image/rev/a0405f2664f4

However, as you have noticed yourself, the current version of regionprops is a work in progress (unfortunately, a much more slow progress than I initially hoped for).  The purpose of this work is to vectorize the computations of the properties which were just too slow.  What this means is that the computations for Perimeter will have to be rewritten anyway.

Take a look on how regionprops has been written now if you are interested in making it work for the next release of the image package.  I hope the comments are quite explicit how the code is supposed to work but I will be happy to clear up anything.

Carnë Draug <carandraug>
Group Member
Fri 06 Nov 2015 08:39:19 PM UTC, comment #1: 

Here is a PATCH to fix this issue. It works as described before.

Since the current version of regionprops.m in the repo is not functional for the 'diameter' property, I could not test my final patch. But the (few) code lines to properly calculate the diameter value as well as the code of the new test where themselfs tested somehow, and should also be Matlab compatible.

(file #35403)

Hartmut <hardy>
Fri 06 Nov 2015 08:21:06 PM UTC, original submission:  

This happens with Octave 4.0.0 and the current image package 2.4.1 (as well as the current repo tip of the image package). Here is a little script to show the behavior:

clear, close all;
pkg load image

% create test image (circle with diameter 201)
I = zeros(400);
disk = fspecial('disk',100);
disk = disk./max(disk(:));
I(100:300, 100:300) = disk;
bw = im2bw(I);

% calculate perimeter of circle:
props = regionprops(bw, 'Perimeter', 'Area');
area = props.Area
perim = props.Perimeter

The results of Octave are: area = 31397 and perim = 564 .
The results of Matlab R2013b are: area = 31397 and perim = 658.4407 .

The "correct" result of the perimeter of a circle of radius 100.5 is perim = 631.46 . This is much closer to the Matlab approximation value than to the current Octave return value.

I think I understand the difference and will be able to fix it: Octave only counts the plain number of pixels that form the boundary. This results in a too small result at positions where two boundary pixels are only connected diagonally. Octave will currently calculate the length at this position to be 1 (as for any other pixels as well). But a better approximation for the distancy between to diagonally connected pixels is sqrt(2).

I will try to soon prepare a patch for this.

Hartmut <hardy>


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

Attach Files:

Attached Files
file #35403:  regionprops_diameter.patch added by hardy (1KiB - text/x-diff)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -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 project members can vote.


    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-06-24 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
    2015-11-06 hardy Attached File- Added regionprops_diameter.patch, #35403

    Back to the top

    Powered by Savane 3.12