Volshow contrast or scaling the colormap

B
Benicio · Oct 30, 2020 · 2.1K views
Question
Is there a way to scale the colormap in volshow()? Similar to using 'caxis', [min max] for image()?
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Nov 20, 2025
% Example volume
imcube = bsxfun(@power, rand(30, 30, 100),...
    permute(linspace(0, 8, 100), [3, 1, 2])).*...
    permute(linspace(1, 0, 100), [3, 1, 2]);

% Pick your color map
cmp = jet;

% Generate your volume object
V = volshow(imcube,...
    'Renderer', 'MaximumIntensityProjection',...
    'Colormap', cmp,...
    'BackgroundColor', [0, 0, 0]);

% Set your new color axis. This does the same thing as caxis normally
% would.

% % % % % % % % % % % % CAXIS EQUIVALENT % % % % % % % % % %
VAxis = [0.2, 1.5];
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 

% Generate new scale
newscale = linspace(min(imcube(:)) - min(VAxis(:)),...
    max(imcube(:)) - min(VAxis(:)), size(cmp, 1))/diff(VAxis);
newscale(newscale < 0) = 0;
newscale(newscale > 1) = 1;

% Update colormap in volshow
V.Colormap = interp1(linspace(0, 1, size(cmp, 1)), cmp, newscale);



volshow(V) displays 3-D grayscale volume V in a figure. You can rotate and zoom in and out on the display interactively using the mouse.

for example

Load MRI data and remove the singleton dimension.

load mri
V = squeeze(D);

Generate a colormap and transparency (alpha) map suited for MRI images.

intensity = [0 20 40 120 220 1024];
alpha = [0 0 0.15 0.3 0.38 0.5];
color = ([0 0 0; 43 0 0; 103 37 20; 199 155 97; 216 213 201; 255 255 255]) ./ 255;
queryPoints = linspace(min(intensity),max(intensity),256);
alphamap = interp1(intensity,alpha,queryPoints)';
colormap = interp1(intensity,color,queryPoints);

View the volume with the custom colormap and transparency map. Click and drag the mouse to rotate the volume. Use the scroll wheel to zoom in and out of the volume.

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!