% -- External Function: cmap = odv_colormap( nval ); % % Returns the colormap/palette from Ocean Data View (ODV) of length `nval'. % If `nval' is left unspecified, a default length of 64 is assumed. % Test: % figure; colormap(odv_colormap); imagesc(peaks); colorbar; % % Source: Figure 15-1, Ocean Data View User's Guide Version 5.6.6, % Reiner Schlitzer, October 23, 2023. % Implementation: Pierre St-Laurent psl@fastmail.net 2024-03-06. function cmap = odv_colormap( nval ) if ( nargin < 1 ) nval = 64; % Matlab palettes have a default length of 64. end % ODV's original rainbow palette includes 113 colors RGB=(0-255): orig = [ ... 217.0000 119.0000 255.0000; ... 206.0000 107.0000 255.0000; ... 198.0000 94.0000 255.0000; ... 185.5000 85.0000 255.0000; ... 173.0000 70.0000 255.0000; ... 162.5000 69.0000 255.0000; ... 150.0000 59.0000 255.0000; ... 141.0000 50.5000 255.0000; ... 135.0000 49.0000 255.0000; ... 121.5000 49.0000 255.0000; ... 116.0000 52.0000 255.0000; ... 109.0000 56.0000 255.0000; ... 107.0000 57.0000 255.0000; ... 103.0000 64.0000 255.0000; ... 99.0000 70.0000 255.0000; ... 96.0000 76.0000 255.0000; ... 96.0000 76.0000 255.0000; ... 94.0000 86.0000 255.0000; ... 91.0000 94.0000 255.0000; ... 86.0000 103.0000 255.0000; ... 86.0000 103.0000 255.0000; ... 79.0000 113.5000 255.0000; ... 72.0000 125.0000 255.0000; ... 68.5000 130.0000 255.0000; ... 53.5000 135.0000 255.0000; ... 41.0000 140.0000 255.0000; ... 41.0000 141.0000 254.0000; ... 32.0000 150.0000 250.0000; ... 26.5000 157.5000 247.0000; ... 19.5000 167.5000 243.5000; ... 16.0000 169.0000 243.0000; ... 12.0000 175.5000 240.5000; ... 10.0000 181.0000 239.0000; ... 9.0000 184.0000 227.0000; ... 7.0000 188.0000 215.0000; ... 5.0000 194.0000 203.0000; ... 4.0000 198.0000 198.5000; ... 4.0000 207.0000 192.0000; ... 2.0000 209.0000 180.0000; ... 0 214.0000 164.0000; ... 4.0000 213.0000 157.5000; ... 2.0000 213.0000 142.0000; ... 1.0000 213.0000 123.0000; ... 0 212.0000 120.0000; ... 0 206.0000 104.0000; ... 0 198.0000 87.0000; ... 0 198.0000 86.0000; ... 3.0000 194.0000 73.0000; ... 5.0000 191.0000 66.5000; ... 8.0000 186.0000 58.5000; ... 13.0000 181.0000 49.0000; ... 16.0000 181.0000 49.0000; ... 17.0000 179.5000 44.0000; ... 24.5000 177.0000 33.5000; ... 33.5000 175.0000 26.0000; ... 43.0000 173.0000 18.0000; ... 45.0000 173.0000 16.0000; ... 54.5000 173.0000 12.0000; ... 65.0000 173.0000 8.0000; ... 68.5000 176.5000 7.0000; ... 85.0000 179.0000 3.0000; ... 99.0000 181.0000 0; ... 108.5000 184.0000 0; ... 122.0000 188.5000 0; ... 133.0000 191.0000 0; ... 143.5000 193.5000 0; ... 163.0000 197.0000 0; ... 174.5000 198.0000 0; ... 187.0000 200.5000 0; ... 198.0000 206.0000 0; ... 212.0000 206.0000 0; ... 222.0000 206.0000 0; ... 231.0000 206.0000 0; ... 240.0000 206.0000 0; ... 248.0000 203.0000 0; ... 255.0000 201.0000 0; ... 255.0000 199.5000 0; ... 255.0000 198.0000 0; ... 255.0000 198.0000 0; ... 255.0000 193.0000 0; ... 255.0000 189.0000 0; ... 255.0000 181.0000 0; ... 255.0000 173.0000 0; ... 255.0000 165.0000 0; ... 255.0000 152.0000 12.0000; ... 255.0000 136.5000 5.5000; ... 253.0000 123.0000 3.0000; ... 243.0000 105.5000 0.5000; ... 239.0000 92.5000 0; ... 231.0000 74.0000 0; ... 227.0000 58.5000 3.0000; ... 222.0000 49.0000 8.0000; ... 217.5000 38.0000 12.0000; ... 214.0000 33.0000 16.0000; ... 214.0000 28.0000 22.0000; ... 214.0000 26.5000 30.5000; ... 214.0000 29.5000 38.5000; ... 214.0000 35.0000 46.0000; ... 214.0000 40.0000 55.5000; ... 215.0000 49.5000 60.0000; ... 216.0000 60.0000 73.0000; ... 220.0000 70.0000 82.0000; ... 225.0000 82.0000 88.5000; ... 227.0000 97.0000 101.0000; ... 231.0000 111.0000 110.0000; ... 237.0000 126.0000 115.0000; ... 241.0000 138.5000 122.0000; ... 245.0000 155.0000 128.0000; ... 248.0000 164.5000 130.0000; ... 252.0000 180.0000 132.0000; ... 255.0000 189.0000 132.0000; ... 255.0000 189.0000 132.0000; ... 255.0000 190.5000 132.0000; ... ]; % Interpolate the 113 values to match the requested size (nval): xori = (0 : size( orig, 1 ) - 1)' / (size( orig, 1 ) - 1); xitp = (0 : nval - 1)' / (nval - 1); cmap = nan( nval, 3 ); cmap( :, 1 ) = interp1( xori, orig( :, 1 ), xitp, 'pchip', 'extrap' ); cmap( :, 2 ) = interp1( xori, orig( :, 2 ), xitp, 'pchip', 'extrap' ); cmap( :, 3 ) = interp1( xori, orig( :, 3 ), xitp, 'pchip', 'extrap' ); clear orig xori xitp; % Matlab expects RGB=(0-1): cmap = cmap / 255.; cmap( find( cmap > 1. ) ) = 1.; cmap( find( cmap < 0. ) ) = 0.; end