Viewing a volumetric data using user defined colormap

9 views (last 30 days)
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
figure
imshow(IND1)
colormap(map)
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')
figure
colormap(map)
volshow(A,'Colormap',colormap)
What improvements can i do in the code so that I am able to view the volume in the colormap defined by me ?
Note:
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

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);
  9 Comments
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(:))]);
end
which in turn is equivalent to
function h = imagesc(img)
ax = gca();
np = get(ax, 'NextPlot');
if strcmp(np, 'replace');
cla(ax);
end
h = image('Parent', ax, 'CData', img);
set(ax, 'CLim', [min(img(:)), max(img(:))], 'CLimMode', 'manual')
end
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!