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

 
 

bug #51976: [octave forge] (image) graythresh fails with values outside the [0 1] range

Submitter:  Rafael Laboissière <rlaboiss>
Submitted:  Sun 10 Sep 2017 12:32:29 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  carandraug
Originator Name:  Open/Closed:  * Closed
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 12 Sep 2017 11:36:36 PM UTC, comment #3: 

I have pushed this http://hg.code.sf.net/p/octave/image/rev/e94c46afdc96 which will mean that graythresh will now clip those values.

This has the unfortunate side effect of being backwards compatibility since graythresh was dependent on having values higher than 1 to distinguish between a vector image and an histogram. vector images are sometimes used to work around the input check of some functions that require 2d matrices. This was terrible design from my part, I should had made a separate function to handle histograms instead of trying to cram everything into graythresh.

This change went into the default branch.

Carnë Draug <carandraug>
Group Member
Tue 12 Sep 2017 10:43:52 PM UTC, comment #2: 

Thank you for the patch and the review.

However, the test where this happens checks if indeed pasisng a name for a threshold algorithm uses the same code path as calling graythresh directly (which should). So the real error is on graythresh, which is failing for values outside the [0 1].

Checking in Matlab R2010b, it seems that graythresh accepts values outside the [0 1] and just clips the values.

Carnë Draug <carandraug>
Group Member
Mon 11 Sep 2017 11:26:08 AM UTC, comment #1: 


Indeed, your patch fix the problem.

Change status to 'Patch Reviewed" and add people to CC.

Avinoam Kalma <avinoam>
Group Member
Sun 10 Sep 2017 12:32:29 PM UTC, original submission:  

These two unit tests in im2bw.m fail randomly:


%!test
%! im = [((randn(10)/10)+.3) ((randn(10)/10)+.7)];
%! assert (im2bw (im, "Otsu"), im2bw (im, graythresh (im(:), "Otsu")))
%! assert (im2bw (im, "moments"), im2bw (im, graythresh (im(:), "moments")))

%!test
%! im = [((randn(10)/10)+.3) ((randn(10)/10)+.7)];
%! im = reshape (im, [10 10 1 2]);
%! assert (im2bw (im, "Otsu"), im2bw (im, graythresh (im(:), "Otsu")))
%! assert (im2bw (im, "moments"), im2bw (im, graythresh (im(:), "moments")))


The reason is because, sometimes, the values in the matrix im are negative or greater than 1.0, what makes it a non-valid image.

The patch attached below fixes the problem.

Rafael Laboissière <rlaboiss>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #41774:  im2bw-unit-test.patch added by rlaboiss (822B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by rlaboiss (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-09-12 carandraug Open/ClosedOpen Closed
    2017-09-12 carandraug StatusConfirmed Fixed
    2017-09-12 carandraug StatusPatch Reviewed Confirmed
        Summary[octave forge] (image) Unit tests for im2bw fail randomly [octave forge] (image) graythresh fails with values outside the [0 1] range
    2017-09-11 avinoam StatusNone Patch Reviewed
        Assigned toNone carandraug
        Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
    2017-09-10 rlaboiss Attached File- Added im2bw-unit-test.patch, #41774

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code