第一次实验代码及结果 - 图文 联系客服

发布时间 : 星期日 文章第一次实验代码及结果 - 图文更新完毕开始阅读6f017b0f0812a21614791711cc7931b765ce7bc7

第一次实验代码及结果

红绿通道互换:

clear; clc; close all;

Image1=imread('newlotus.jpg'); Image2=Image1;

Image2(:,:,1)=Image1(:,:,2); Image2(:,:,2)=Image1(:,:,1);

subplot(231),imshow(Image1),title('原图');

subplot(232),imshow(Image1(:,:,1)),title('原图红通道'); subplot(233),imshow(Image1(:,:,2)),title('原图绿通道'); subplot(234),imshow(Image1(:,:,3)),title('原图蓝通道'); subplot(235),imshow(Image2),title('红绿通道互换');

结果:

灰度化转换: clear; clc; close all;

I=imread('newlotus.jpg');

R1=0.299*I(:,:,1)+0.587*I(:,:,2)+0.114*I(:,:,3); R2=rgb2gray(I);

subplot(131); imshow(I); title('原图');

subplot(132); imshow(R1); title('公式法灰度转换'); subplot(133); imshow(R2); title('函数法灰度转换');

结果:

旋转:

clear; clc; close all; I=imread('lake.jpg'); gray=rgb2gray(I);

Newgray1=imrotate(gray,15);

Newgray2=imrotate(gray,15,'bilinear'); subplot(221);imshow(I),title('原图彩色'); subplot(222);imshow(gray),title('原图灰度');

subplot(223);imshow(Newgray1),title('旋转15°(最邻近插值)'); subplot(224);imshow(Newgray2),title('旋转15°(双线性插值)'); 结果:

放大:

clear; clc; close all; I=imread('flower.jpg'); gray=rgb2gray(I);

Newgray3=imresize(gray,5,'nearest'); Newgray4=imresize(gray,5,'bilinear');

% figure;

subplot(131),imshow(gray),title('原图');

subplot(132),imshow(Newgray3),title('放大5倍,最近'); subplot(133),imshow(Newgray4),title('放大5倍双线性'); 结果:

算术运算:

clear; clc; close all; I1=imread('lake.jpg'); I2=imread('plane1.jpg'); ADD=I1+I2; SUB=I1-I2; AB=I1.*I2; CB=I1./I2;

subplot(231); imshow(I1);title('原图1'); subplot(232); imshow(I2);title('原图2'); subplot(233); imshow(ADD);title('加运算'); subplot(234); imshow(SUB);title('减运算'); subplot(235); imshow(AB);title('乘运算'); subplot(236); imshow(CB);title('除运算'); 结果:

拼接:

clear; clc; close all;

Image2=imread('lake.jpg'); HImage=flipdim(Image2,2); VImage=flipdim(Image2,1); CImage=flipdim(HImage,1);

NewImage=[Image2 HImage;VImageCImage]; imshow(NewImage),title('图像镜像与拼接'); 结果:

图片拆分:

clear; clc; close all;

I=imread('newlotus.jpg'); [a,b]=size(I); fori=1:a/2 for j=1:b/6 A(i,j,:)=I(i,j,:);

B(i,j,:)=I((a/2+i),j,:); C(i,j,:)=I(i,(b/6+j),:);

D(i,j,:)=I((a/2+i),(b/6+j),:); end

end

subplot(231); imshow(I);title('原图'); subplot(232); imshow(A);title('左上'); subplot(233); imshow(B);title('左下'); subplot(234); imshow(C);title('右上'); subplot(235); imshow(D);title('右下'); 结果: