MATLAB Answers

Viewing a volumetric data using user defined colormap

10 views (last 30 days)
Anand P
Anand P on 8 Jun 2019
Commented: Anand P on 10 Jun 2019
Initially I have converted an RGB image, represented by a 3 dimensional matrix into an indexed image represented by a 2 dimensional matrix using
[IND1,map] = rgb2ind(RGB1,256); where RGB1 is my RGB image and IND1 is my indexed image
I have done this for another RGB image RGB2 using
[IND2,map] = rgb2ind(RGB2,256);
Then I have stacked the indexed image, IND1 and IND2 into a matrix A so that A becomes a 3-D volume. This is done using the following code
A(:,:,1) = IND1
A(:,:,2) = IND2
Image IND1 and IND2 is viewed using the following code. I was able to view IND1 and IND2 in accordance with my colormap
When I made an attempt to view the 3D volume 'A' using the follwing code, the volume is displayed in black and white and not in the colormap defined by me (ie 'map')
What improvements can i do in the code so that I am able to view the volume in the colormap defined by me ?
size of RGB1 and RGB2 = 256*256*3;
size of IND1 and IND2 = 256*256;
size of A is 256 *256 *2
Thanks in advance


Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 8 Jun 2019
[IND1,map] = rgb2ind(RGB1,256);
[IND2,map] = rgb2ind(RGB2,256);
Those two are converted into different maps. You should be using
IND2 = rgb2ind(RGB2, map);


Show 6 older comments
Anand P
Anand P on 9 Jun 2019
So if I want to know the values in the matrix A after applying imagesc on it, How do I know that ?
returns only a 1x1 matrix and do not contain the values of A after imagesc is applied.
Is there another way ?
Do reply. Thanks
Walter Roberson
Walter Roberson on 9 Jun 2019
imagesc() does not change values. imagesc() basically does
function h = imagesc(img)
ax = gca();
h = image(ax, img);
caxis(ax, [min(img(:)), max(img(:))]);
which in turn is equivalent to
function h = imagesc(img)
ax = gca();
np = get(ax, 'NextPlot');
if strcmp(np, 'replace');
h = image('Parent', ax, 'CData', img);
set(ax, 'CLim', [min(img(:)), max(img(:))], 'CLimMode', 'manual')
The values that are stored in the image() object are the original inputs: the axes is told how it should interpret the data. The renderer will examine the axes CLim property and the CData property and the renderer will internally use the changed values (more likely the renderer will instruct the system graphics subsystem what value mapping is desired.)
If you want to see the values that would result from the scaling, use the mat2gray() routine that I mentioned earlier. mat2gray() is not what is used internally (graphics subsytem is used internally) but it has the same behaviour.
Anand P
Anand P on 10 Jun 2019
So, is it possible to stack up indexed images and view the resulting volume using the same colors used to view indexed images. If yes, can you provide me the code. Thanks in advance.

Sign in to comment.

Sign in to answer this question.