1.减法运算
A = imread ('3.jpg');
B = imread ('2.png');
C = A -0.3* B ;
subplot (1,3,1);
imshow ( A );
title ('混合图');
subplot (1,3,2);
imshow ( B );
title ('背景图');
subplot (1,3,3);
imshow ( C );
title ('分离后的图');
I = imread ('1.png');
I =rgb2gray(I);
J = imread ('2.png');
I =im2double(I);
J =im2double(J);
K = I +0.3* J ;
subplot (1,3,1);
imshow (I);
title ('人物图');
subplot (1,3,2);
imshow ( J );
title ('背景图');
subplot (1,3,3);
imshow ( K );
title ('相加后的图');
imwrite (K,'3.jpg');
A=imread("1.png");
A=rgb2gray(A);
A=im2double(A);
subplot(1,3,1);
imshow(A);
title('原图');
B=zeros(235,235);
B(30:200,40:160)=1;
subplot(1,3,2);
imshow(B);
title('方框');
K=A.*B;
subplot(1,3,3);
imshow(K);
title('局部图');
imwrite(K,'Lenna5.jpg')
A=imread("3.jpg");
B=imopen(A,strel('disk',15));
C=imabsdiff(A,B);
D=imdivide(A,C);
subplot(1,3,1),imshow(A),title('原图');
subplot(1,3,2),imshow(C),title('减去背景的图像');
subplot(1,3,3),imshow(D),title('原图和减去背景的图像相除');
5.图像缩放
A=imread("3.jpg");
B1=imresize(A,1.5);
B2=imresize(A,[420 384]);
C1=imresize(A,0.7);
C2=imresize(A,[150 180]);
imshow(B1);
title('比例放大图');
figure;
imshow(B2);
title('非比例放大图');
figure;
imshow(C1);
title('比例缩小图');
figure;
imshow(C2);
title('非比例缩小图');
6.图像旋转
I=imread("1.png");
J=imrotate(I,45);
K=imrotate(I,90);
subplot(1,3,1);
imshow(I);
subplot(1,3,2);
imshow(J);
subplot(1,3,3);
imshow(K);
I = imread("橙子.png");
figure;
subplot(1,3,1);
imshow(I);
title('原图');
J= imadjust(I,[0.3;0.6],[0.1;0.9]); %设置灰度变换的范围
subplot(1,3,2);
imshow(J);
title('线性扩展');
I1 = double(I); %将图像转换为double类型
I2 = I1/255;
C=2;
K=C*log(1+I2); %求图像的对数变换
subplot(1,3,3);
imshow(K);
title("非线性扩展");
M=255-I; %将此图像取反
figure;
subplot(1,3,1);
imshow(M);
title('灰度倒置');
N1=im2bw(I,0.4); %将此图像二值化,阈值为0.4
N2=im2bw(I,0.7); %将此图像二值化,阈值为0.7
subplot(1,3,2);
imshow(N1);
title('二值化阈值0.4');
subplot(1,3,3);
imshow(N2);
title('二值化阈值0.7');