Below is a demonstration of the features of the resampleColormap function


clear; close all; clc;




The function resampleColormap function resamples the input colormap cmap using n steps. Resampling is based on linear interpolation.


Plot settings


Create example data for visualizations


Example: Create and resample your own colormap

Define your own colormap using RGB values (you can search online fpr color charts with rbg values, if given as unit8 number, normalize by deviding by 255).

Create discrete custom colormap

white_rgb=[1 1 1];
red_rgb=[1 0 0];
green_rgb=[0 1 0];
blue_rgb=[0 0 1];
black_rgb=[0 0 0];
rgbData=[white_rgb; red_rgb; green_rgb; blue_rgb; black_rgb];

Resample colormap e.g. using more intermediate colors

n=250; %Number of color levels

Test colormap

cFigure; hold on;
title('Custom colormap');
surf(X,Y,Z); shading interp;
colormap(my_colormap); colorbar;
view(2); axis equal; axis tight; grid on; box on;


Kevin Mattheus Moerman, [email protected]

GIBBON footer text


GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for image segmentation, image-based modeling, meshing, and finite element analysis.

Copyright (C) 2019 Kevin Mattheus Moerman

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see