MATLAB:在包含RGB图像的图形中显示灰度图像的颜色条 [英] MATLAB: Show colorbar of a grayscale image in a figure containing a RGB image
问题描述
假设我们有两个图像:
1)RGB图像:
% initialize RGB image:
rgbIm = zeros(100, 100, 3);
rgbIm(20:80, 20:80, 1) = 1;
2)灰度图像:
% initialize grayscale image:
grayIm = zeros(100);
grayIm(20:80, 20:80) = 1;
让它们同时显示:
figure, imshow(rgbIm), colormap('jet'), colorbar;
figure, imshow(grayIm), colormap('jet'), colorbar;
正如我们所看到的,第二张图中的 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.
我要实现的是在与RGB图像相对应的图中显示灰度图像的颜色栏.
这似乎没有什么意义,但这只是我做一个很小的例子,以展示我想在更大的项目中做什么.
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.
有什么想法吗?
非常感谢:)
EDIT1 :请允许我解释为什么我需要这样做
Allow me to explain why I would need this
假设我在感兴趣的某些区域计算一个MRI切片的一些生理参数,结果如下:
Suppose I compute some physiological parameters one MRI slice in certain regions of interest, yielding something like this:
现在,我想将这些参数叠加在原始切片的顶部,并创建一个RGB图像来实现此目的:
Now I want to superimpose these parameters on top of the original slice, and I create one RGB image to achieve this:
颜色图没有意义,这就是为什么我要在RGB图像(即叠加图像)中显示与参数图像相对应的颜色图.
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).
有什么想法吗?
感谢您的关注.
推荐答案
(回答我自己的问题,希望以后可以帮助某人)
(Answering my own question so I can hopefully help someone in the future)
借助上述答案和
I just accomplished what I intended, with the help of the above answer and a post from Steve Eddins' blog. Here's how:
baseImage = baseImage/(max(baseImage(:))); % normalize base (anatomical) image
rgbSlice = baseImage(:,:,[1 1 1]); % converting to RGB (ignore colormaps)
imshow(parameterROIImage, []); % show parametric image
colormap('jet'); % apply colormap
hold on;
h = imshow(rgbSlice); % superimpose anatomical image
set(h, 'AlphaData', ~bwROIlocations); % make pixels in the ROI transparent
colorbar;
其中parameterROIImage
是:
bwROIlocations
是包含ROI像素的逻辑矩阵:
bwROIlocations
is the logical matrix containing the ROI pixels:
最终结果:
感谢Shai的帮助.
这篇关于MATLAB:在包含RGB图像的图形中显示灰度图像的颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!