我正在运行以下代码来叠加两个图像
A = 'gaussians.png';
B = 'gaussiansContour.png';
imAlphaData = repmat(0:1/size(B,2):1-1/size(B,2),size(B,1),1);
hf = figure('units','normalized','position',[.2 .2 .6 .6]);
ax1 = subplot(2,3,1);
ibg = image(A);
axis off;
title('Background');
ax2 = subplot(2,3,4);
iim = image(B);
axis off;
title('Image without transparency yet');
ax3 = subplot(2,3,[2:3, 5:6]);
ibg2 = image(B);
axis off;
hold on;
% Overlay the image, and set the transparency previously calculated
iim2 = image(A,'XData',[30 50],'YData',[10 30]);
set(iim2,'AlphaData',imAlphaData);
title(sprintf('Using transparency while overlaying images:\nresult is multiple image objects.'));
但我遇到了一个错误:
Error using image
Numeric or logical matrix required for image CData
Error in superimpose (line 8)
ibg = image(A);
有人可以告诉我要改变什么以便我的代码正常运行吗?
答案 0 :(得分:3)
image
采用像素数据矩阵,而不是字符串。使用imread
image(imread('gaussians.png'))
答案 1 :(得分:2)
尝试:
A = imread('gaussians.png');
B = imread('gaussiansContour.png');
而不是你的:
A = 'gaussians.png';
B = 'gaussiansContour.png';