最新计算机图形学简单示例程序代码及截图

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.读入一幅RGB图像,变换为灰度图像和二值图像,并在同一个窗口内分成三个子窗口来分别显示RGB图像、灰度图像、二值图像,注上文字标题。

>> a=imread('D:/1.jpg');

>> i=rgb2gray(a);

>> I=im2bw(a,0.5);

>> subplot(3,1,1);imshow(a);title('原图像');

>> subplot(3,1,2);imshow(i);title('灰度图像');

>> subplot(3,1,3);imshow(I);title('二值图像');

2.给定一幅RGB图像,绘制图像角度直方图,并对图像进行均衡化处理。

>>a=imread('D:\2.jpg');

>>b=rgb2gray(a);

>>c=histeq(b);

>>subplot(3,1,1);imshow(a);title('原图像');

>>subplot(3,1,2);imshow(b);title('直方图像');

>>subplot(3,1,3);imshow(c);title('均衡化图像');

3. 读入两幅RGB图像,对两幅不同图像执行加、减、乘、除操作,在同一个窗口内分成五个子窗口来分别显示,注上文字标题。

>> a=imread('D:/3.jpg');

>> A=imresize(a,[800 800]);

>> b=imread('D:/4.jpg');

>> B=imresize(b,[800 800]);

>> Z1=imadd(A,B);

>> Z2=imsubtract(A,B);

>> Z3=immultiply(A,B);

>> Z4=imdivide(A,B);

>> subplot(3,2,1);imshow(A);title('原图像A');

>> subplot(3,2,2);imshow(B);title('原图像B');

>> subplot(3,2,3);imshow(Z1);title('加法图像');

>> subplot(3,2,4);imshow(Z2);title('减法图像');

>> subplot(3,2,5);imshow(Z3);title('乘法图像');

>> subplot(3,2,6);imshow(Z4);title('除法图像');

4.对一幅图像进行灰度变化,实现图像变亮、变暗和负片效果,在同一个窗口内分成四个子窗口来分别显示,注上文字标题。

>> a=imread('D:/5.jpg');

>> m=imadjust(a,[,],[0.5;1]);

>> n=imadjust(a,[,],[0;0.5]);

>> g=255-a;

>> subplot(2,2,1);imshow(a);title('原图像');

>> subplot(2,2,2);imshow(m);title('图像变亮');

>> subplot(2,2,3);imshow(n);title('图像变暗');

>> subplot(2,2,4);imshow(g);title('负片效果');

5.采用MATLAB中的函数filter2对受高斯噪声干扰的图像进行均值滤波,写出程序代码和运行结果。

>>a=imread('D:/6.jpg');

>> i=rgb2gray(a);

>> subplot(3,1,2);imshow(i);title('灰度图像');

>> J=imnoise(i,'gaussian',0,0.005);

>> subplot(2,1,1);imshow(J);title('噪声干扰图像');

>> subplot(3,1,1);imshow(i);title('灰度图像');

>> subplot(3,1,2);imshow(J);title('噪声干扰图像');

>> M= filter2(fspecial('average',9),J)/255;

>> subplot(3,1,3);imshow(M);title('均值后的图像');

6. 用一种阀值方法实现图像分割,写出程序代码和运行结果。

>>I=imread('D:/7.jpg');

>>A=imresize(I,[200 200]);

>>i=rgb2gray(A);

>>subplot(3,1,1);imshow(i);title('灰度图像');

>>C=histc(i,0:255);

>>n=sum(C);

>>N=sum(n);

>>t=n\N;

>>subplot(3,1,2);imhist(i);title('灰度直方图');

>>hold off;

>>axis([0,255,0,500]);

>> [p,threshold]=min(t(120:150));

>>threshold=threshold+120;

>>tt=find(i>threshold);

>>i(tt)=255;

>>tt=find(i

>>i(tt)=0;

>>subplot(3,1,3);imshow(i);title('灰度阈值图');

相关文档
最新文档