## Friday, May 27, 2016

### Colormap for NDVI

Setting up NDVI colorbar can be tricky! You want a nice representation of the vegetation and bare surfaces in the map.

1. I found an easy way would be to flip the default matlab summer color bar upside down!
colormap('summer')
map2 = (colormap);
map2 = flipud(map2);
colormap(map2);
cmap = colormap;
It looks like:
However, the negatives are not treated nicely. For the first approximation, I could set x<0 == 0.

2. Found a nice one:
https://publiclab.org/notes/cfastie/08-26-2014/new-ndvi-colormap
The colorbar is nice, but, I was not much happy with the squeezed RBG dance!

3. Having seen them, I wanted to create my own.
I combined the inverted summer with the graded b/w scheme.  The idea is to set inverted summer for x > 0 with  the gray image for x < 0!
So, I wrote this small piece!

r1 = [0 1];
g1 = [0 1];
b1 =  [0 1];
rgb1 = [r1; g1; b1]';
rgbt = interp1([1 2],rgb1, linspace(1,2,32 ));

r1 = [ 1 0];
g1 = [1 0.5];
b1 =  [0.4 0.4];
rgb2 = [r1; g1; b1]';
rgbb= interp1([1 2],rgb2, linspace(1,2,32 ));

newNDVI = [rgbt;rgbb];

figure
colormap(newNDVI );
cmap = colormap; % cmap nicely puts colormap into 3 col data
% colorbar
caxis([-1 1])
hc = colorbar('southoutside');
set(hc, 'FontSize', 16)

axis off; set(gcf,'Color','White')
You can set that linspace limit to 128, and make 256x3 colormap, making a smooth colorbar.
The new NDVI colorbar looks like:

The color scheme looks like:

For the first half, it goes from dark to bright, and then smoothly to green from yellow at the center!

Try it! and let me know if you like this scheme for NDVI!
Here is a small preview. I changed the lower rgbb matrix to 224x3 arrays which nicely set yellow limit at ~0.2! (some info on NDVI for the cusious minds: http://earthobservatory.nasa.gov/Features/MeasuringVegetation/measuring_vegetation_2.php)

### Forcing Matlab colorbar to display climits

Matlab sometimes can not register the upper and lower limits of the color bar when the figures are saved (eg with export_fig).

I found a way around it:
instead of setting caxis limit at the exact values, increase/decrease the upper/lower limit
caxis([0.94 0.99] )
to >> caxis([0.94 0.99001] )

This worked for me!

## Thursday, May 26, 2016

### Set Lat Lon Limits at the edge of the map

It looks nicer when you have the numbers at the edge.
setm(gca,'fontsize', 12,'PLabelLocation',[ylim(1)+0.001, mean(ylim), ylim(2)],'PLineLocation',[ylim(1)+0.001, mean(ylim), ylim(2)],...
'PLabelRound',-3,'MLabelLocation',[xlim(1), mean(xlim), xlim(2)],'MLineLocation',[xlim(1), mean(xlim), xlim(2)], 'MLabelRound',-3, ...
'Grid','on')

## Thursday, May 5, 2016

### Colormap Stark #matlab colorbar

I wanted to have a colormap which had a great degree of contrast, and was not really a rainbow scheme.

I have tried to solve this issue by poking at different colormaps
http://usefulcodes.blogspot.com/2015/06/colormap-hotjet.html
(very close, but keeps the rainbow defect flat intensity for the large part in the middle.)
http://usefulcodes.blogspot.com/2015/06/colormap-goofy-matlab.html
(looks green and goofy! Did not like it.)
http://usefulcodes.blogspot.com/2015/06/matlab-colormap-rose.html
(has nice monotonic intensity gradient, but not that beautiful on maps.)
See the examples: http://usefulcodes.blogspot.com/search/label/colormap
I present you a new one! Colormap "stark".
This does have the defect of not linearly increasing the intensity, but does not stay flat in the middle. It has two saddles, allowing the left/right contrast. I like it so far.
Well, it is inspired from the LST image from MODIS
http://neo.sci.gsfc.nasa.gov/view.php?datasetId=MOD11C1_M_LSTDA

 175 256 255 100 249 255 50 223 253 10 191 252 9 144 252 12 106 255 11 79 254 26 56 254 34 38 255 50 34 255 79 33 255 85 33 255 101 34 255 132 35 255 150 36 255 177 39 255 217 36 255 243 35 255 255 35 213 255 34 175 255 30 143 255 36 110 255 34 88 255 33 65 255 44 35 255 72 35 254 95 39 255 116 45 254 138 41 254 160 46 255 183 45 255 199 46 255 210 47 253 225 47 254 230 75 256 256 110 R G B

newN = 1:64;

isn = floor(linspace(1,64,36));
%RGB = [R G B];
R1 = RGB(:,1);
G1 = RGB(:,2);
B1 = RGB(:,3);

Rn = runmean(interp1(isn, R1, newN),2);
Gn = runmean(interp1(isn, G1, newN),2);
Bn = runmean(interp1(isn, B1, newN),2);

newC=  [Rn', Gn', Bn']./256;

close all
figure ;
plot(newN, Rn, 'r-')
hold on
plot(newN, Gn, 'G-')
plot(newN, Bn, 'b-')
colormap(newC);
colorbar('southoutside')
ylim([0 260])
xlim([1 64])
legend('R', 'G', 'B','Location','southoutside','Orientation','horizontal')
xlabel('C-index')
ylabel('R,G,B')
export_fig([ 'RGB-colormap'   ],'-jpeg','-r250')

figure;
plot(newN, sum(newC,2)./3, 'r-')
ylabel('Intensity')
xlabel('C-index')
xlim([1 64])
export_fig([ 'RGB-intensity' ],'-jpeg','-r250')

Here is an alternate
 175 256 255 100 249 255 50 223 253 10 191 252 9 144 252 12 106 255 11 79 254 26 56 254 34 38 255 50 25 255 79 15 255 85 15 255 101 30 255 132 50 255 150 70 255 177 80 255 217 100 255 243 100 255 255 80 213 255 70 175 255 50 143 255 30 110 255 15 88 255 25 65 255 44 35 255 72 35 254 95 39 255 116 45 254 138 41 254 160 46 255 183 45 255 199 46 255 225 47 253 240 47 254 250 75 256 256 129 R G B

It adds whiteness in the middle, creating W shaped swing to the green pallets.