Matlab在二进制图像上覆盖图像 [英] Matlab overlay imagesc on binary image
问题描述
我正在尝试将imagesc图像覆盖在二进制图像的顶部.我在网上搜索,但没有运气.下面是我的代码:
I am trying to overlay an imagesc image on top of a binary image. I searched for it online, but no luck. Below is my code:
figure;
imshow(BW4);
hold on
imagesc(image2,'AlphaData',0.5); axis equal; axis tight; axis off;
myColorMap = jet(256);
myColorMap(1,:) = 0;
colormap(myColorMap); colorbar;
hold off
我得到的输出看起来像右下方的图像,而不是白色顶部的喷射色图线.有人可以帮我解决此问题吗?感谢您的投入和时间.
The output what I am getting looks like below image on right, instead of the jet colormap lines on top of white color. Can someone help me to fix this issue? I appreciate your time and effort.
谢谢
二进制图片
Jet图片
得到我不想要的东西
推荐答案
因此,我们首先读取bw数据a
并创建一些喷射图像b
,它是强度的nxm矩阵:
So we first read your bw data a
and create some jet image b
which is some nxm matrix of intensities:
a=rgb2gray(imread('fFIG2.png'));
a=a==max(a(:));
a=a>0; % now it is binary
% make jet data with 0 being it's minimal value
b=(imresize(peaks(100),size(a))).*a ;
b=b.*(b>0);
现在,我们将b
中的数据归一化为0到1,并用它制作一个RGB阵列.我们将创建一个蒙版并为其分配白色...
Now we normalize the data in b
between 0 and 1 and make an RGB array out of it. The we'll create a mask and assign white to it...
cmap=[0,0,0;jet(255)]; % set the colormap to be always black and jet
% normalize from nxm matrix to nxmx3 rgb values
c=b;
c=round( ((c-min(c(:)) )/(max(c(:))-min(c(:))))*(length(cmap)-1)+1);
im=reshape(cmap(c(:),:),[size(c),3]);
% get the mask for all pixels that are in a but are zero in b
bw2=repmat( (a>0 & b==0),[1 1 3]);
im(bw2)=1; % assign this pixels with rgb=white
imagesc(im)
这篇关于Matlab在二进制图像上覆盖图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!