bugGNU Octave - Bugs: bug #36473, colormaps different from matlab

 
 

bug #36473: colormaps different from matlab

Submitter:  Carnë Draug <carandraug>
Submitted:  Tue 15 May 2012 11:12:53 AM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
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
   

Jump to the original submission

Tue 09 Apr 2013 10:23:29 PM UTC, comment #30: 

Finished the last colormap, jet, with this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/3731a1992083).  Closing report.

Rik <rik5>
Group administrator
Mon 08 Apr 2013 10:31:48 PM UTC, comment #29: 

I've attatched jetmaps.mat.zip



(file #27819)

Ben Abbott <bpabbott>
Group Member
Mon 08 Apr 2013 10:29:10 PM UTC, comment #28: 

Ben,

I checked in a change for the bone map (http://hg.savannah.gnu.org/hgweb/octave/rev/328048fd43b8).  Only the jet map remains to be deciphered.  Can you get me the output from the following commands?


jet1 = jet (1);
jet2 = jet (2);
jet3 = jet (3);
jet4 = jet (4);
jet5 = jet (5);
jet6 = jet (6);
jet7 = jet (7);
jet8 = jet (8);
jet9 = jet (9);
jet10 = jet (10);
jet11 = jet (11);
jet12 = jet (12);
jet13 = jet (13);
jet24 = jet (24);
jet25 = jet (25);
jet26 = jet (26);
jet27 = jet (27);
jet28 = jet (28);
jet29 = jet (29);
jet30 = jet (30);
jet31 = jet (31);
jet32 = jet (32);
jet33 = jet (33);
jet65 = jet (65);
jet66 = jet (66);
jet67 = jet (67);
jet68 = jet (68);
jet69 = jet (69);
jet70 = jet (70);
jet71 = jet (71);
jet72 = jet (72);
jet73 = jet (73);
jet123 = jet(123);
save jetmaps.mat jet*


Rik <rik5>
Group administrator
Fri 05 Apr 2013 11:58:31 PM UTC, comment #27: 

Attached bone.mat.zip

(file #27785)

Ben Abbott <bpabbott>
Group Member
Fri 05 Apr 2013 11:53:19 PM UTC, comment #26: 

I checked in a change for the pink colormap(http://hg.savannah.gnu.org/hgweb/octave/rev/7762d56dbc8a).

Only two more maps to go.  Can I get the results of running the following?


bone1 = bone (1);
bone2 = bone (2);
bone3 = bone (3);
bone4 = bone (4);
bone5 = bone (5);
bone6 = bone (6);
bone7 = bone (7);
bone8 = bone (8);
bone9 = bone (9);
bone24 = bone (24);
bone25 = bone (25);
bone26 = bone (26);
bone27 = bone (27);
bone28 = bone (28);
bone29 = bone (29);
bone30 = bone (30);
bone31 = bone (31);
bone32 = bone (32);
bone33 = bone (33);
bone65 = bone (65);
bone66 = bone (66);
bone67 = bone (67);
bone68 = bone (68);
bone69 = bone (69);
bone70 = bone (70);
bone71 = bone (71);
bone72 = bone (72);
bone73 = bone (73);
save bonemaps.mat bone*


Rik <rik5>
Group administrator
Mon 25 Mar 2013 11:38:52 PM UTC, comment #25: 

pinkmaps8.zip is attached.

(file #27689)

Ben Abbott <bpabbott>
Group Member
Mon 25 Mar 2013 11:17:20 PM UTC, comment #24: 

I checked in a changeset which fixes hot.m (http://hg.savannah.gnu.org/hgweb/octave/rev/6964e6b92fc1).  Now back to pink.  I suspect Matlab is doing the same thing with something modulo 8.  Can you upload the results of the following?


pink24 = pink (24);
pink25 = pink (25);
pink26 = pink (26);
pink27 = pink (27);
pink28 = pink (28);
pink29 = pink (29);
pink30 = pink (30);
pink31 = pink (31);
pink32 = pink (32);
pink65 = pink (65);
pink66 = pink (66);
pink67 = pink (67);
pink68 = pink (68);
pink69 = pink (69);
pink70 = pink (70);
pink71 = pink (71);
pink72 = pink (72);
pink3 = pink (3);
pink4 = pink (4);
pink5 = pink (5);
pink6 = pink (6);
pink7 = pink (7);
pink8 = pink (8);
pink9 = pink (9);
save pinkmaps8.mat pink*



Rik <rik5>
Group administrator
Mon 25 Mar 2013 06:14:55 PM UTC, comment #23: 

I've added those maps to the attached zip archive.

(file #27683)

Ben Abbott <bpabbott>
Group Member
Mon 25 Mar 2013 05:28:56 PM UTC, comment #22: 

Matlab is doing something funny, occasionally, for the hot colormap.  I'm trying to decide if it is something that is cyclical in 4 or in 8.  Could I get the following code run and attached to this report?


hot24 = hot (24);
hot25 = hot (25);
hot26 = hot (26);
hot27 = hot (27);
hot28 = hot (28);
hot29 = hot (29);
hot30 = hot (30);
hot32 = hot (32);
hot65 = hot (65);
hot66 = hot (66);
hot67 = hot (67);
hot68 = hot (68);
hot69 = hot (69);
hot70 = hot (70);
hot71 = hot (71);
hot72 = hot (72);
save hotmaps8.mat hot*


Rik <rik5>
Group administrator
Mon 25 Mar 2013 03:35:39 PM UTC, comment #21: 

I've zipped and attached the hotmaps.mat

(file #27678)

Ben Abbott <bpabbott>
Group Member
Mon 25 Mar 2013 03:06:54 PM UTC, comment #20: 

I have a cset ready for the hot colormap.  I need a bit more data to verify the result, which seem different for n<64.  Can someone run the following in Matlab and upload the results?


hot4 = hot (4);
hot8 = hot (8);
hot31 = hot (31);
hot73 = hot (73);
hot74 = hot (74);
save hotmaps.mat hot*


Rik <rik5>
Group administrator
Fri 22 Mar 2013 01:40:32 AM UTC, comment #19: 

Rik,

I've added pink200 to the mat-file

Ben


(file #27648)

Ben Abbott <bpabbott>
Group Member
Thu 21 Mar 2013 10:55:52 PM UTC, comment #18: 

Ben,

Different results than what I expected, particularly for pink73.  Does pink(200) for you match the pink200 that Carne uploaded earlier?  I'm wondering if there are different versions of Matlab at play and whether there might be any differences due to that.  It seems unlikely, given that these colormaps have been in Matlab for a long time.  But I thought I would check because otherwise I have to figure out a different scheme for pink().

Rik <rik5>
Group administrator
Thu 21 Mar 2013 10:32:46 PM UTC, comment #17: 

RIk,

The pink-maps are attached.

(file #27647)

Ben Abbott <bpabbott>
Group Member
Thu 21 Mar 2013 09:53:58 PM UTC, comment #16: 

I've got a changeset for pink() which works for all but pink(2).  In order to debug it could someone upload a file with the Matlab results for


pink1 = pink (1);
pink4 = pink (4);
pink8 = pink (8);
pink31 = pink (31);
pink73 = pink (73);
save pinkmaps.mat pink*


Rik <rik5>
Group administrator
Thu 21 Mar 2013 02:50:26 PM UTC, comment #15: 

I checked in two changesets that make copper and hsv colormaps compatible with Matlab:

http://hg.savannah.gnu.org/hgweb/octave/rev/b8a4f313e78e
http://hg.savannah.gnu.org/hgweb/octave/rev/ca395af72d88

This leaves bone, hot, jet, and pink.  The work by Ben suggests that jet is a very complicated beast and maybe we can't actually get to identical results for that map.

Rik <rik5>
Group administrator
Tue 19 Jun 2012 11:28:07 AM UTC, comment #14: 

Rather than trying to precisely implement ML's versions, what about a simple solution the new version I've attached ... or are the current implementations ok as they are?

(file #26061)

Ben Abbott <bpabbott>
Group Member
Tue 19 Jun 2012 08:33:55 AM UTC, comment #13: 

I don't know how to fix it on a more elegant way either. At the time I got the results from matlab and thought I could make sense of them.

I have attached a .mat file with the matlab results for colormaps that are still incompatible (they are bone, copper, hot, hsv, jet and pink) of size 2, 10, 64, 200 and 1000.

(file #26059)

Carnë Draug <carandraug>
Group Member
Tue 19 Jun 2012 12:58:16 AM UTC, comment #12: 

I've attached an ugly changeset. Is strict compatibility needed. If not, I'd prefer a more elegant solution.


(file #26056)

Ben Abbott <bpabbott>
Group Member
Sun 17 Jun 2012 09:18:09 PM UTC, comment #11: 

I took a look at how ML behaves.

For jet(n) with n = 16, 32, or 64, the code below works.


cmap = [0.0 0.0 0.5
        0.0 0.0 1.0
        0.0 0.5 1.0
        0.0 1.0 1.0
        0.5 1.0 0.5
        1.0 1.0 0.0
        1.0 0.5 0.0
        1.0 0.0 0.0
        0.5 0.0 0.0];
r = size (cmap, 1);
x = (0:(r-1)) / (r-1);
jet = @(n) interp1 (x, cmap, (1:n)/n);


However, something very different is being done for other values of n. Some examples are below. The "# m" comments indicate when the value coincides with cmap(m).


jet1 = [0     1     1]; # 4

jet2 = [0     0     1   # 2
        0     1     1]; # 4

jet3 = [0     0     1   # 2
        0     1     1   # 4
        1     1     0]; # 6

jet4 = [0     0     1   # 2
        0     1     1   # 4
        1     1     0   # 6
        1     0     0]; # 8

jet5 = [ 0    0.5000    1.0000   # 3
         0    1.0000    1.0000   # 4
    0.5000    1.0000    0.5000   # 5
    1.0000    1.0000         0   # 6
    1.0000    0.5000         0]; # 7

jet6 = [ 0         0    1.0000   # 2
         0    0.5000    1.0000   # 3
         0    1.0000    1.0000   # 4
    0.5000    1.0000    0.5000   # 5
    1.0000    1.0000         0   # 6
    1.0000    0.5000         0]  # 7

jet7 = [ 0         0    1.0000   # 2
         0    0.5000    1.0000   # 3
         0    1.0000    1.0000   # 4
    0.5000    1.0000    0.5000   # 5
    1.0000    1.0000         0   # 6
    1.0000    0.5000         0   # 7
    1.0000         0         0]; # 8

jet8 = [     0         0    1.0000   # 2
             0    0.5000    1.0000   # 3
             0    1.0000    1.0000   # 4
        0.5000    1.0000    0.5000   # 5
        1.0000    1.0000         0   # 6
        1.0000    0.5000         0   # 7
        1.0000         0         0   # 8
        0.5000         0         0]; # 9

jet9 = [ 0         0    1.0000   # 2
         0    0.3333    1.0000
         0    0.6667    1.0000
         0    1.0000    1.0000   # 4
    0.3333    1.0000    0.6667
    0.6667    1.0000    0.3333
    1.0000    1.0000         0   # 6
    1.0000    0.6667         0
    1.0000    0.3333         0];

jet10 = [0         0    0.6667
         0         0    1.0000   # 2
         0    0.3333    1.0000
         0    0.6667    1.0000
         0    1.0000    1.0000   # 4
    0.3333    1.0000    0.6667
    0.6667    1.0000    0.3333
    1.0000    1.0000         0   # 6
    1.0000    0.6667         0
    1.0000    0.3333         0];


I don't recognize what ML is doing here.

Ben Abbott <bpabbott>
Group Member
Thu 17 May 2012 02:17:37 AM UTC, comment #10: 

Don't close this bug just yet. The changeset I sent only fix the bug for length =< 1 and implement a list of colormaps (which came up in the discussion but was not originally related to the bug report).

The original bug, still exists. It's not fixed yet. I'll need some time to understand how the hell do they build their colormaps. I don't understand how is it acceptable for such thing to not be properly documented...

Carnë Draug <carandraug>
Group Member
Wed 16 May 2012 08:57:57 PM UTC, comment #9: 

I checked in the changes as separate changesets with a few minor edits.

http://hg.savannah.gnu.org/hgweb/octave/rev/b9c02ee24de1
http://hg.savannah.gnu.org/hgweb/octave/rev/5f1d4def40e1

Thanks!

John W. Eaton <jwe>
Group administrator
Tue 15 May 2012 11:21:17 PM UTC, comment #8: 

Done. Both commits in a changeset and a NEWS entry.

(file #25865)

Carnë Draug <carandraug>
Group Member
Tue 15 May 2012 10:18:59 PM UTC, comment #7: 

Sure, you could add a NEWS entry for this change.

Could you also merge all the changes into one changeset?

John W. Eaton <jwe>
Group administrator
Tue 15 May 2012 10:07:30 PM UTC, comment #6: 

I remember now, should have I added a NEWS entry for the new options to colormap?

Carnë Draug <carandraug>
Group Member
Tue 15 May 2012 09:53:04 PM UTC, comment #5: 

This second changeset (it applies after the previous), implements the list, register and unregister options to colormap. I have also made the colormaps functions register with with PKG_ADD.

I don't think that contrast is really a colormap so I didn't add it.

(file #25862)

Carnë Draug <carandraug>
Group Member
Tue 15 May 2012 05:02:29 PM UTC, comment #4: 

I attahced the first changeset. I won't have time to look more into this today. Some of the current colormaps behave bad when size is < 1 (sometimes errors, others NaN, etc). Others return an empty matrix 0x0 (matlab returns 0x3). This changeset fixes those problems.

It also makes sure that when size is 1 the values returned are the same as matlab.

(file #25860)

Carnë Draug <carandraug>
Group Member
Tue 15 May 2012 04:18:21 PM UTC, comment #3: 

I'd rather not hard code a list of colormaps if possible.

How about using a persistent cellstr list in the colormap function, then
allow the list to be displayed with


colormap ("list")


and added to with


colormap ("register", "name")


Then you could add lines like


## PKG_ADD: colormap ("register", "jet");


to all the colormap functions and the documentation just needs to say
"colormap ("list") displays a list of all available colormaps."

The docstrings for all the available colormap functions (with
descriptions) should be grouped together in the manual, so I
don't think it is necessary to provide a list describing them in the
colormap function docstring.

John W. Eaton <jwe>
Group administrator
Tue 15 May 2012 03:35:16 PM UTC, comment #2: 

I don't think their contents are listed anywhere. I'll have to deduce it myself, can't be that complicated. I just wanted to know if I should even bother in the first place.

The only one that seems to be explained is `hsv' that according to mathworks site says hsv(m) is the same as hsv2rgb([h ones(m,2)]) where h is the linear ramp, h = (0:m–1)'/m.

Also, it has been asked on the mailing list to have a way to list all available colormaps[1]. Other than having their list hardcoded somewhere I don't see how to do it. Would it be acceptable to have colormap ("list") return such a list? If not, can I submit a patch that at least lists them on the documentation of colormap? In the case of colormap ("list"), would there be a way to make it increase the list. For example, the image package implementing extra colormaps and have PKG_ADD add it.

Carnë

[1] http://octave.1599824.n4.nabble.com/list-available-colomaps-td4366121.html

Carnë Draug <carandraug>
Group Member
Tue 15 May 2012 02:36:50 PM UTC, comment #1: 

It would be nice to be compatible, but are the contents of the colormaps precisely documented somewhere?

If not, then I suppose you could try to make Octave compatible by writing a test script and having someone run that in Matlab for you, then attempt to deduce the algorithm used to generate the colormap values.

What you should defintely NOT do is read (or have someone read for you) the Matlab colormap functions and base your implementation on that.

John W. Eaton <jwe>
Group administrator
Tue 15 May 2012 11:12:53 AM UTC, original submission:  

Hi

I noticed that the colormaps we have in Octave are a bit different from matlab. I have noticed this when trying to implement imhist and kept getting different results from matlab, then I noticed that after indexing my images were different.

For example:

jet(1)
 [0 1 1]   # matlab
 [0 0 0.5] # octave
m = jet;
jet(1:3, :)
# in matlab
   0   0   0.5625
   0   0   0.6250
   0   0   0.6875
# in octave
   0.00000   0.00000   0.50000
   0.00000   0.00000   0.56349
   0.00000   0.00000   0.62698


I didn't try every single colormap as I don't have matlab and didn't want to bother anyone too much but at least jet and hot are different.

Is this considered a bug? Should I even try to fix it?
Carnë

Carnë Draug <carandraug>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #27819:  jetmaps.mat.zip added by bpabbott (3KiB - application/zip)
file #27785:  bonemaps.mat.zip added by bpabbott (12KiB - application/zip)
file #27689:  pinkmaps8.zip added by bpabbott (15KiB - application/zip)
file #27683:  hotmaps8.zip added by bpabbott (3KiB - application/zip)
file #27678:  hotmaps.zip added by bpabbott (867B - application/zip)
file #27648:  pinkmaps.zip added by bpabbott (6KiB - application/zip)
file #27647:  pinkmaps.zip added by bpabbott (2KiB - application/zip)
file #26061:  changeset.patch added by bpabbott (2KiB - application/octet-stream - simple implementation)
file #26059:  colormaps.mat added by carandraug (180KiB - application/octet-stream - colormap results from matlab)
file #26056:  changeset.patch added by bpabbott (4KiB - application/octet-stream)
file #25865:  colormaps.diff added by carandraug (18KiB - text/x-diff)
file #25862:  colormaps-list.diff added by carandraug (10KiB - 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 rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by carandraug (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 19 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-04-09 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2013-04-08 bpabbott Attached File- Added jetmaps.mat.zip, #27819
    2013-04-05 bpabbott Attached File- Added bonemaps.mat.zip, #27785
    2013-03-25 bpabbott Attached File- Added pinkmaps8.zip, #27689
    2013-03-25 bpabbott Attached File- Added hotmaps8.zip, #27683
    2013-03-25 bpabbott Attached File- Added hotmaps.zip, #27678
    2013-03-25 rik5 StatusFixed In Progress
    2013-03-22 bpabbott Attached File- Added pinkmaps.zip, #27648
    2013-03-21 bpabbott Attached File- Added pinkmaps.zip, #27647
    2012-06-19 bpabbott Attached File- Added changeset.patch, #26061
    2012-06-19 carandraug Attached File- Added colormaps.mat, #26059
    2012-06-19 bpabbott Attached File- Added changeset.patch, #26056
    2012-05-17 jwe Open/ClosedClosed Open
    2012-05-16 jwe StatusNone Fixed
        Open/ClosedOpen Closed
    2012-05-15 carandraug Attached File- Added colormaps.diff, #25865
    2012-05-15 carandraug Attached File- Added colormaps-list.diff, #25862
    2012-05-15 carandraug Attached File- Added colormaps-small-sizes.diff, #25860

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code