Viewing a volumetric data using user defined colormap

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

Antworten (1)

Walter Roberson
Walter Roberson am 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 Kommentare

Thanks for the reply. I have made the change. But that doesnt exactly solve my problem
This is how IND1 is displayed. Similarly IND2 is displayed using the same colors. ( The code to display the image is given in the quesiton)
image.JPG
But when I stacked IND1 and IND2 and tried to view the resulting volume, it appeared like this. ( The code I used to display the volume is given in the question)
volume.JPG
What can i do so that i am able to view the volume using the same colors with which i am able to view the individual images.
Thanks in advance
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.
First of all, thanks for the reply.
I do not want to view the slice of volume, I intend to view the volume intself.
See, while viewing the image, the imshow() function does not give what I want (it gives a distorted image,one similar to the second image i have posted in my previous comment) but the imagesc() function gives exactly what I want.
The description about imagesc() says that it "Display image with scaled colors". What exactly does this do. Does it scale the colormap that we are using or does it scale the values of the matrix which represents the image ? If it is scaling the colormap or the matrix values, by what values/how does the scaling occur ?
If we can apply a similar function like imagesc() to our volume, we might be able to view the volume in our user defined color map.
I am facing the same problem while using the volumeViewer, it displays the volume, but not in the colors I want.
Do reply, Thanks in advance
By default, imagesc() does
caxis( [min(TheData(:)), max(TheData(:))])
Anand P
Anand P am 9 Jun. 2019
Bearbeitet: Anand P am 9 Jun. 2019
TheData' is my image represented by 2D matrix
But when I do that I get the following error
Output argument "cmin" (and maybe others) not assigned during call to "caxis".
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.
okay.
So if I want to know the values in the matrix A after applying imagesc on it, How do I know that ?
B=imagesc(A)
returns only a 1x1 matrix and do not contain the values of A after imagesc is applied.
Is there another way ?
Do reply. Thanks
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 am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Modify Image Colors finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Jun. 2019

Kommentiert:

am 10 Jun. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by