- 图像加法
imgRice = rgb2gray(imread('rice.png'));
imgCameraman = imread('cameraman.tif');
imgCameraman = imgCameraman(:,1:255);
addimg = imadd(imgRice,imgCameraman);
figure,
subplot(131),imshow(imgRice);
subplot(132),imshow(imgCameraman);
subplot(133),imshow(addimg);
注意的地方,相加的两张图片的尺寸大小和维度应该是一样的。
- 数值加法
imgflower = imread('flower.tif');
imgAddFlower = imadd(imgflower,30);
figure,
subplot(121),imshow(imgflower);
subplot(122),imshow(imgAddFlower);
结果
注意,如果原来是比较白的部分,会出现溢出限制,变成255;
imgTire = imread('tire.tif');
[m,n]=size(imgTire);
imgeight = imread('eight.tif');
c = imgeight;
imgTire = im2double(imgTire);
imgeight = im2double(imgeight);
c = im2double(imgeight);
for i =1:m
for j = 1:n
c(i,j) = imgTire(i,j)+imgeight(i,j);
end
end
diff=imabsdiff(c,imgeight);
figure,
subplot(221),imshow(imgTire);
subplot(222),imshow(imgeight);
subplot(223),imshow(c);
subplot(224),imshow(diff);