bugGNU Octave - Bugs: bug #47115, label2rgb from image-package...


bug #47115: label2rgb from image-package doesn't work for labels with value above the uint16 limit

Submitter:  None
Submitted:  Thu 11 Feb 2016 06:59:13 AM UTC
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Filip Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Wed 10 May 2017 07:08:37 PM UTC, comment #7: 

> We could still do "better" than Matlab and also support uint32 in ind2x.m (called from ind2rgb.m) if this doesn't harm any other function that also uses ind2x.m.

Agreed.  So I pushed http://hg.savannah.gnu.org/hgweb/octave/rev/3ace16b8f062

This doesn't add support for the actual display functions but at least the functinos that convert between image types could support this.  May be worth to look into other similar functions such as cmunique and gray2ind.

Carnë Draug <carandraug>
Group Member
Wed 29 Mar 2017 06:57:16 PM UTC, comment #6: 

When running the "example code" from comment #0 in Matlab, then I do NOT get an error. The result is of class uint8 and the values are 255 everywhere, and at position (1,1) the value is (128,0,0). I get the same Matlab result, when I use uint32(lw) as input for label2rgb.

In the Matlab documentation for label2rgb they say that "The input label matrix L can have any numeric class.  It must contain finite, nonnegative integers. The output of label2rgb is of class uint8."

In the Matlab documentation for ind2rgb they say that "[The input] X can be of class uint8, uint16, or double. [The output] RGB is an m-by-n-by-3 array of class double."

Conclusion: The class support of (core) Octave's ind2rgb seems to be Matlab compatible. But the class support of (image packag's) label2rgb seems to NOT be Matlab compatible, currently.

We could still do "better" than Matlab and also support uint32 in ind2x.m (called from ind2rgb.m) if this doesn't harm any other function that also uses ind2x.m.

Hartmut <hardy>
Sun 26 Mar 2017 02:58:57 AM UTC, comment #5: 

> But even if Matlab does not support uint32 in ind2rgb, why can't we do the same?

I obviously meant "But even if Matlab does not support uint32 in ind2rgb, why do we do the same?". I think it should be fine to add it in core, even if Matlab does not support it.

Carnë Draug <carandraug>
Group Member
Sun 26 Mar 2017 02:57:53 AM UTC, comment #4: 

The label2rgb on the image package just calls ind2rgb from Octave core.  And I remember something about indexed images being only up to uint16 in Matlab and we copying this behaviour.

We could fix the image package to support uint32 too or maybe we need to fix Octave core ind2rgb. Anyone with Matlab could check this? But even if Matlab does not support uint32 in ind2rgb, why can't we do the same?

Carnë Draug <carandraug>
Group Member
Thu 21 Apr 2016 06:49:48 AM UTC, comment #3: 

OP here. Just to clarify, the reason for reporting this bug is because the test code works in Matlab, but not in Octave. I also can't really see any reason why label2rgb() shouldn't work with uint32 and higher.

Filip <fsund>
Tue 29 Mar 2016 07:40:53 PM UTC, comment #2: 

Sorry for the confusion: The file ind2x.m sits in the core Octave repository (image subfolder), not in the image repo.

Hartmut <hardy>
Tue 29 Mar 2016 07:37:44 PM UTC, comment #1: 

The Octave file ind2x.m has currently (image repo) an explicit test for only the two integer classes uint8 and uint16:

  ## Check if X is an indexed image.
  ## An indexed image is defined has having only 2D, and that's how Matlab
  ## behaves.  But we want to support ND images, so we will allow up to 4D
  ## and check that the 3rd dimension is a singleton.
  if (all (ndims (x) != [2 4]) || size (x, 3) != 1
      || iscomplex (x) || issparse (x)
      || (isfloat (x) && x != fix (x))
      || ! any (strcmp (class (x), {"uint8", "uint16", "single", "double"})))
    error ("%s: X must be an indexed image", caller);

Maybe we can change this to allow also uint32 and uint64 integers? Or would this harm any other user of this helper function?

Hartmut <hardy>
Thu 11 Feb 2016 06:59:13 AM UTC, original submission:  

When running label2rgb() on a labelled image with labels larger than 65535 (the 16 bit unsigned integer limit), the function returns an error:

>> label2rgb(lw);
error: ind2rgb: X must be an indexed image
error: called from
    ind2x at line 32 column 5
    ind2rgb at line 49 column 10
    label2rgb at line 126 column 8

Example code:

lw = zeros(10, 10);
lw(1, 1) = 65535 + 1;



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

Attach Files:

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 avinoam (Updated the item)
  • -email is unavailable- added by fsund (Posted a comment)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by hardy
  • -email is unavailable- added by None (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-05-10 carandraug StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2017-03-06 avinoam StatusNone Confirmed
    2016-12-12 avinoam Item GroupNone Matlab Compatibility
    2016-03-29 hardy Carbon-Copy- Added carandraug
    2016-02-15 rik5 Carbon-CopyRemoved 72865 -
    2016-02-15 rik5 CategoryOctave Function Octave Package

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code