计算机图形学简单示例程序代码及截图
- 格式:doc
- 大小:363.50 KB
- 文档页数:6
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('灰度阈值图');