interpolate_cbrewer.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function [interp_cmap]=interpolate_cbrewer(cbrew_init, interp_method, ncolors)
  2. %
  3. % INTERPOLATE_CBREWER - interpolate a colorbrewer map to ncolors levels
  4. %
  5. % INPUT:
  6. % - cbrew_init: the initial colormap with format N*3
  7. % - interp_method: interpolation method, which can be the following:
  8. % 'nearest' - nearest neighbor interpolation
  9. % 'linear' - bilinear interpolation
  10. % 'spline' - spline interpolation
  11. % 'cubic' - bicubic interpolation as long as the data is
  12. % uniformly spaced, otherwise the same as 'spline'
  13. % - ncolors=desired number of colors
  14. %
  15. % Author: Charles Robert
  16. % email: tannoudji@hotmail.com
  17. % Date: 14.10.2011
  18. % just to make sure, in case someone puts in a decimal
  19. ncolors=round(ncolors);
  20. % How many data points of the colormap available
  21. nmax=size(cbrew_init,1);
  22. % create the associated X axis (using round to get rid of decimals)
  23. a=(ncolors-1)./(nmax-1);
  24. X=round([0 a:a:(ncolors-1)]);
  25. X2=0:ncolors-1;
  26. z=interp1(X,cbrew_init(:,1),X2,interp_method);
  27. z2=interp1(X,cbrew_init(:,2),X2,interp_method);
  28. z3=interp1(X,cbrew_init(:,3),X2, interp_method);
  29. interp_cmap=round([z' z2' z3']);
  30. end