您的位置:首页 > 编程语言 > MATLAB

【Matlab】 RGB照片转化成灰度图叠加显示

2014-12-16 17:03 260 查看

两张图片lena.png和fiona.jpg转化为灰度图像叠加显示

%overlap two pictures
%read pic lena
I1 = imread('lena.png');
A1 = rgb2gray(I1);
a1 = double(A1(:));
%read pic fiona
I2 = imread('fiona.jpg');
A2 = rgb2gray(I2);
a2 = double(A2(:));

A=[a1 a2];
x = rand(2,1);%transparency
y = A*x;
%adjust to the size like I2
I3 = reshape(y,size(I2));
%show pic
figure, imshow(I3,[]);


遇到问题

Error using reshapeTo RESHAPE the number of elements must not change.

help reshape可知

reshape(X,M,N,P,...) returns an N-D array with the same elements as X but reshaped to have the size M-by-N-by-P-by-...M*N*P*... must be the same as PROD(SIZE(X)).

修改reshape那行代码:

I3 = reshape(y,size(A2));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: