I'm having some trouble creating a customized MATLAB colormap and colorbar. I want to display an image (with imagesc for example) and I want to define a colormap via an Nx4 matrix
cMap = [ x(1) r(1) g(1) b(1); ...
x(2) r(2) g(2) b(2); ...
...
x(N) r(N) g(N) b(N)];
such that image values between x(i) and x(i+1) have color r(i),g(i),b(i). The vector x needs to be increasing, but not necessarily in a linear fashion. In addition, I want to be able to click on the image with the GUI and see the actual image value at each pixel, so I don't want to reassign pixel values before displaying. Finally, I want a colorbar on which each color represented by a segment of equal length.
I'm able to do 2/3 of these things by finding the least common multiple of diff(x), and concatenating several constant color rows into one colormap, however the colorbar this makes has color sizes which are proportional to the differences along x, and it looks bad and hard to read.
To get around the colorbar problem, I've tried making several patch objects of the colors in cMap, placing them at [inf inf] and then calling legend on these objects, but setting all the legend and axis properties required to make this look good for all sized colormaps is very hard, and I'm constantly debugging this as multiple users are using this tool. I would love to use MATLAB colorbar if I could.
Has anyone ever dealt with a problem like this? Thanks!