Depth color coding using Volumeviewer/ Volshow
13 views (last 30 days)
Show older comments
Hi,
I am uisng the below script to display focal stacks in 3D. May I know how to include colormap for depth?
filePattern = fullfile(fileFolder, '*.png');
all_images = dir(filePattern);
I = imread(all_images(1).name);
I= rgb2ind(I,256);
W=365;
H=365;
D = numel(all_tiff);
stack = zeros(W,H,D);
stack(:,:,1) = first_image;
for i = 2:D
II = imread(all_tiff(i).name);
II = rgb2ind(II,256);
stack(:,:,i) = II;
end
volumeViewer(stack);
I also tried below tutorial which involves Volshow(), However I got the below shown graphics error while running
Error using images.ui.graphics3d.Volume/validateData
Expected input to be finite.
Error in images.ui.graphics3d.Volume/setData
Error in images.ui.graphics3d.GraphicsContainer/set.Data
Error in images.ui.graphics3d.internal.AbstractContainer/set
Error in images.ui.graphics3d.GraphicsContainer
Error in images.ui.graphics3d.Volume
Error in volshow (line 32)
hVolume = images.ui.graphics3d.Volume(viewer, 'Data', V, remainingInputs{:});
Error in depthVolumeColorCoder (line 83)
V = volshow(arr,...
clear; close all; clc;
%% Display Grayscale Spiral
%set colormap to use for depth coding
colormap = hsv;
%load data from MATLAB
load('spiralVol.mat');
vol = spiralVol;
%display grayscale volume
volshow(vol)
%snap pic of the grayscale volume for publishing
snapnow
close;
%% Display Color Coded Spiral
%colorcode the spiral
depthVolumeColorCoder(vol,colormap)
3 Comments
Accepted Answer
Gayathri
on 3 Jun 2025
To view the volume with the colormap, please use the following lines of code
clear; close all; clc;
%% Display Grayscale Spiral
%set colormap to use for depth coding
colormap = hsv;
%load data from MATLAB
load('spiralVol.mat');
vol = spiralVol;
%display grayscale volume
volshow(vol,Colormap=colormap)
I hope this is your expectation. Let me know if you need something more!
Please refer to the below example, which illustrates the usage of 'volshow' funtion with 'Colormap' argument.
openExample('images/VisualizeVolumeOfMRIDataExample')
More Answers (0)
See Also
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!