
%我觉得是你计算 PSNR的方法错了,应该是用最大像素值,
%灰度图像的最大像素值是255, 而不是512。
%另外计算MSE也不用那么麻烦
%下面是计算 MSE和PSNR的程序,我拿一张试了一下,结果肯定是不一样的。
%还有统计像素值出现的次数,用直方图imhist会更简单点,这个程序我没写。
I=imread('boatbmp');
J=imnoise(I,'gaussian',0,001);
Jg=double(J);
%均值滤波
k1=filter2(fspecial('average',3),Jg);
k2=filter2(fspecial('average',5),Jg);
figure,subplot(221),imshow(I);title('原图');
subplot(222),imshow(J);title('加入高斯白噪声以后的图像');
subplot(223),imshow(uint8(k1));title('33模板均值滤波');
subplot(224),imshow(uint8(k2));title('55模板均值滤波');
%中值滤波
k3=medfilt2(Jg,[3 3]);
k4=medfilt2(Jg,[5 5]);
figure,subplot(221),imshow(I);title('原图');
subplot(222),imshow(J);title('加入高斯白噪声以后的图像');
subplot(223),imshow(uint8(k3));title('33模板中值滤波');
subplot(224),imshow(uint8(k4));title('55模板中值滤波');
%计算均值滤波后图像的PMSE与PSNR
diff=(double(I)-k1)^2;
mse=mean(diff(:));
pmse_avg=mse;
max_value=max(k1(:));
psnr=double(10log(max_valuemax_value/mse)/log(10));
%计算中值滤波后的各项指标
diff=(double(I)-k3)^2;
mse=mean(diff(:));
max_value=max(k3(:));
pmse_mid=mse;
psnr_mid=double(10log(max_valuemax_value/mse)/log(10));
I=imread('D:\我的文档\MATLAB\cameramanbmp');
J0=imnoise(I,'gaussian');
J1=imnoise(I,'salt & pepper');
J0J3=imfilter(J0,fspecial('average'));
J0J5=imfilter(J0,fspecial('average',[5 5]));
J0Z3=medfilt2(J0);
J0Z5=medfilt2(J0,[5 5]);
J1J3=imfilter(J1,fspecial('average'));
J1J5=imfilter(J1,fspecial('average',[5 5]));
J1Z3=medfilt2(J1);
J1Z5=medfilt2(J1,[5 5]);
subplot(2,2,1),imshow(I);
title('原始图像');
subplot(2,2,2),imshow(J0);
title('加入零均值高斯噪声');
subplot(2,2,3),imshow(J1);
title('加入椒盐噪声');
figure,
subplot(2,2,1),imshow(J0J3);
title('对高斯噪声,采用3x3均值滤波');
subplot(2,2,2),imshow(J0J5);
title('对高斯噪声,采用5x5均值滤波');
subplot(2,2,3),imshow(J0Z3);
title('对高斯噪声,采用3x3中值滤波');
subplot(2,2,4),imshow(J0Z5);
title('对高斯噪声,采用5x5中值滤波');
figure,
subplot(2,2,1),imshow(J1J3);
title('对椒盐噪声,采用3x3均值滤波');
subplot(2,2,2),imshow(J1J5);
title('对椒盐噪声,采用5x5均值滤波');
subplot(2,2,3),imshow(J1Z3);
title('对椒盐噪声,采用3x3中值滤波');
subplot(2,2,4),imshow(J1Z5);
title('对椒盐噪声,采用5x5中值滤波');
黑白的意思是灰度化吗?用I=imread('1bmp');%读取图像文件'1bmp',文件应该保存在matlab的\x0d\%工作路径下,否则应该使用绝对路径。\x0d\J=rgb2gray(I);%讲转为灰度图并且保存到J当中。\x0d\figure%打开新的作图窗口。\x0d\imshow(I)%;显示转换前的彩色图。\x0d\figure;%打开新的作图窗口。\x0d\imshow(J);%显示转换后的灰度图J。
下边的程序是我自己编的希望能给你参考。其中的imhist是显示直方图的,如果你不用可以直接删去。我已经将程序里的地址写成了d:\bloodjpg你将存在d盘,标明名字blood,注意类型为jpg即可。
11
显示更加清楚可以用直方图均衡化。
程序1:
%直方图均衡化,令对比度自适应直方图均衡化
I=imread('你的(注意要用英文的。比如'd:\bloodjpg')');
I=rgb2gray(I);
J=adapthisteq(I);
subplot(221),imshow(I)
title('原图');
subplot(222),imshow(J)
title('直方图均衡化后的结果')
subplot(223),imhist(I,64)
title('原图的直方图');
subplot(224),imhist(J,64)
title('直方图均衡化后的结果的直方图');
12 让看清楚还可以让变亮一些(因为你这图看起来很暗)。
程序2:
I=imread('d:\bloodjpg');
J=imadjust(I,[],[05 1]);
%通过修改highout值使变亮
K=imadjust(I,[],[],03);
%通过修改r(描述I,J关系曲线形状)
subplot(231),imshow(I);
title('原图');
subplot(232),imshow(J);
title('修改highout');
subplot(233),imshow(K);
title('修改r值')
subplot(234),imhist(I,64);
title('原图的直方图');
subplot(235),imhist(J,64);
title('修改highout直方图');
subplot(236),imhist(K,64);
title('修改r值直方图');
21 边缘检测的有很多算子,你自己试试看哪个算子比较好。
程序3:
I=imread('d:\bloodjpg');
figure,imshow(I);%显示原图
f= rgb2gray(I);%转化为灰度图
BW1=edge(f,'Roberts');%使用roberts算子进行边缘提取
figure;imshow(BW1); %显示边缘提取结果
BW2=edge(f,'sobel');%使用sobel算子进行边缘提取
figure;imshow(BW2);%显示边缘提取结果
BW3=edge(f,'prewitt');%使用prewitt算子进行边缘提取
figure;imshow(BW3);%显示边缘提取结果
BW4=edge(f,'log');%使用log算子进行边缘提取
figure;imshow(BW4);%显示边缘提取结果
BW5=edge(f,'canny');%使用canny算子进行边缘提取
figure;imshow(BW4);%显示边缘提取结果
以上就是关于一个matlab简单图像处理的程序,共执行了均值,中值滤波,然后计算各个处理后图像的MSE,PSNR等值全部的内容,包括:一个matlab简单图像处理的程序,共执行了均值,中值滤波,然后计算各个处理后图像的MSE,PSNR等值、matlab图像处理、数字图像处理怎么把RGB图变成黑白图像,还有matlab程序是什么等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)