Viewing a volumetric data using user defined colormap
Show older comments
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
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
Anand P
on 8 Jun 2019
Walter Roberson
on 8 Jun 2019
I worked on this a bit last night, but I was not successful.
The situation appeared to be related in part to the Alpha parameters -- but only in part.
Even if you get the colors to work, you will not be able to use this to view the individual images except for the particular case you have where you have exactly two images. The volshow() tool does not give you slice planes, only a 3D volume. volumeViewer() is a more complete tool that includes some slice plane work.
Anand P
on 9 Jun 2019
Walter Roberson
on 9 Jun 2019
By default, imagesc() does
caxis( [min(TheData(:)), max(TheData(:))])
Walter Roberson
on 9 Jun 2019
Do not try to return anything from the caxis call.
caxis does not scale the data itself: caxis sets the CLim and CLimMode axes properties.
Anand P
on 9 Jun 2019
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
on 10 Jun 2019
Categories
Find more on Modify Image Colors 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!
