Matlab在二进制图像上叠加图像

时间:2018-03-20 16:20:55

标签: matlab

我正在尝试将图像图像叠加在二进制图像上。我在网上搜索它,但没有运气。以下是我的代码:

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

我得到的输出看起来像右边的图像,而不是白色顶部的喷射色彩图线。有人可以帮我解决这个问题吗?我感谢您的时间和精力。

谢谢,

二进制图像

Binary image

喷射图像

Jet image

得到我不想要的东西

Result what I am getting which I do not want

1 个答案:

答案 0 :(得分:0)

所以我们首先阅读您的bw数据a并创建一些喷射图像b,这是一些强度的nxm矩阵:

 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数组。我们将创建一个蒙版并为其指定白色......

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)

enter image description here

相关问题