图像 matlab 峰值信噪比 im2double double

来源:互联网 发布:厦门海关网络自主申报 编辑:程序博客网 时间:2024/05/24 04:40
简介
PSNR 是最普遍,最广泛使用的评鉴画质的客观量测法,不过许多实验结果都显示,PSNR 的分数无法和人眼看到的视觉品质完全一致,有可能 PSNR 较高者看起来反而比PSNR 较低者差。
这是因为人眼的视觉对于误差的敏感度并不是绝对的,其感知结果会受到许多因素的影响而产生变化(例如:人眼对空间频率较低的对比差异敏感度较高,人眼对亮度对比差异的敏感度较色度高,人眼对一个区域的感知结果会受到其周围邻近区域的影响)。
(参考百度百科)

计算公式:
未命名.PNG
2010-12-15 21:45:44 上传
下载附件(10.22 KB)

未命名1.PNG
2010-12-15 21:45:41 上传
下载附件(4.23 KB)


代码
  1. % 图像峰值信噪比PSNR、均方根误差MSE
  2. % By lyqmath
  3. % Dalian University of Technology
  4. % School of Mathematical Sciences
  5. function [PSNR, MSE] = psnr(X, Y)
  6. % 计算峰值信噪比PSNR、均方根误差MSE
  7. % 如果输入Y为空,则视为X与其本身来计算PSNR、MSE

  8. if nargin<2
  9.     D = X;
  10. else
  11.     if any(size(X)~=size(Y))
  12.         error('The input size is not equal to each other!');
  13.     end
  14.     D = X-Y;
  15. end
  16. MSE = sum(D(:).*D(:))/prod(size(X));
  17. PSNR = 10*log10(255^2/MSE);
复制代码
实例
  1. function main()
  2. clc; close all;
  3. I = imread('rice.png');
  4. I1 = imnoise(I, 'salt & pepper');
  5. figure;
  6. subplot(1, 2, 1); imshow(I); title('原图像');
  7. subplot(1, 2, 2); imshow(I1); title('加噪声图像');
  8. [PSNR, MSE] = psnr(I, I1)

  9. % 图像峰值信噪比PSNR、均方根误差MSE
  10. % By lyqmath
  11. % Dalian University of Technology
  12. % School of Mathematical Sciences
  13. function [PSNR, MSE] = psnr(X, Y)
  14. % 计算峰值信噪比PSNR、均方根误差MSE
  15. % 如果输入Y为空,则视为X与其本身来计算PSNR、MSE

  16. if nargin<2
  17.     D = X;
  18. else
  19.     if any(size(X)~=size(Y))
  20.         error('The input size is not equal to each other!');
  21.     end
  22.     D = X-Y;
  23. end
  24. MSE = sum(D(:).*D(:))/prod(size(X));
  25. PSNR = 10*log10(255^2/MSE);
复制代码
untitled.png
2010-12-15 21:53:36 上传
下载附件(75.09 KB)

untitled1.png
2010-12-15 21:54:31 上传
下载附件(16.56 KB)



总结
有一些方法中采用了分块计算PSNR等参数,用来得到更为有效地信息。也有的方法提出一些新的计算公式,当然这都是为了统计处图像处理前后的差异信息。
类似的,对于相近的公式,也可以如上做编码。

注:部分内容参考网络共享资料。

 

 

坑爹啊有木有!!!

尼玛图像要转换格式有木有!!!

a simple test will show you that
when you use im2double, it will convert your uint8 image from the
range of 0-255 into a double array in the range 0-1. In general, all
Image Processing Toolbox functions that take floating point arrays
want them in the range of 0 to 1. I find it kind of annoying but
that's the way it is. That's basically what "rescaling" means. So
this imdouble() function is there to help you get to what you might
need for later calls to Image Processing Toolbox functions. If you
use double() you would have to divide by 255 yourself if you needed
to. If you're doing your own custom functions then you can leave it
in the original range if you want.

 

Using im2double will rescale the data (if necessary) from your image.
Using double won't.

怪不得总出错!!!

铭记!!!

原创粉丝点击