Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

MATLAB: Show colorbar of a grayscale image in a figure containing a RGB image

Suppose we have two images:

1) RGB Image:

% initialize RGB image:
rgbIm = zeros(100, 100, 3); 
rgbIm(20:80, 20:80, 1) = 1;

2) Grayscale Image:

% initialize grayscale image:
grayIm = zeros(100);
grayIm(20:80, 20:80) = 1;

Lets show both of them:

figure, imshow(rgbIm),  colormap('jet'), colorbar;
figure, imshow(grayIm), colormap('jet'), colorbar;

As we can see, the colorbar in the 2nd figure (i.e. grayscale image) makes total sense. On the other hand I can't really understand the information given by the colormap in the 1st figure.

What I would like to achieve is to display the colorbar of the grayscale image in the figure corresponding to the RGB image.

It might seem that this does not make sense but this is just a very minimal example that I just made up to show what I would like to do in a larger project.

Any thoughts?

Thanks a lot :)

EDIT1: Allow me to explain why I would need this

Suppose I compute some physiological parameters one MRI slice in certain regions of interest, yielding something like this:

parametric image

Now I want to superimpose these parameters on top of the original slice, and I create one RGB image to achieve this:

superimposition on the original image

The colormap does not make sense, and this is why I would like to display the colormap corresponding to the parametric image in the RGB image (i.e. the superimposition image).

Any ideas?

Thank you for your attention.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I still think what you are asking does not make sense.
Let me explain:
What is colorbar? Colorbar is a representation of a function (mapping) from gray-level (scalar) to color. Using jet, in your example, you map the 0 to dark blue and 1 to red.
By asking for a colorbar for an RGB image, you are actually asking for a mapping from RGB triplet to RGB color -- this mapping is the identity mapping! you do not need a colorbar to see this mapping, each pixel represent it!

EDIT

After seeing the edited question, I revise my answer a bit:
Since both MRI signal and whatever physiological parameters you computed makes no sense in RGB space, you have two 1D mappings:
1. MRI signal at each voxel to gray level ("gray" colormap)
2. Physiological measure at each voxel to "jet" color

What I usually do in this cases is convert the 2D MRI slice into RGB gray image by simply replicate it along the third dimension

rgbSlice = twoDSlice(:,:,[1 1 1]);

Now show the images on top of each other

figure;
imshow( rgbSlice );
hold on;
h = imshow( physiologicalParams );
colormap jet;
set(h, 'AlphaData', .5 ); 
colorbar

You might need to play with the color mapping of the axes using caxis or clim to get it right.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...