新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → 如何計算SNR (signal-to-ratio)? (.NET) (C/C++) (C++/CLI) (GDI+) (Image Processing) 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 9704 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: 如何計算SNR (signal-to-ratio)? (.NET) (C/C++) (C++/CLI) (GDI+) (Image Processing) 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 如何計算SNR (signal-to-ratio)? (.NET) (C/C++) (C++/CLI) (GDI+) (Image Processing)

    SNR公式如下
    按此在新窗口浏览图片


    1
    /**//*
    2(C)
    3
    4Filename    : SNR.cpp
    5Compiler    : Visual C++ 8.0 / C++/CLI
    6Description : Demo how to compute SNR
    7Release     : 12/20/2006 1.0
    8*/
    9#include "stdafx.h"
    10#include <iostream>
    11#include <cmath>
    12
    13using namespace System::Drawing;
    14using namespace System::Drawing::Imaging;
    15using namespace std;
    16
    17// Convert RGB to gray level int
    18int colorToInt(Color);
    19
    20// Calculate signal to ratio
    21double SNR(Bitmap^, Bitmap^);
    22
    23int main() {
    24  // Read lena.jpg
    25  Bitmap^ oriImg = gcnew Bitmap("lena.jpg");
    26  // Declare Gaussian image for lena.jpg
    27  Bitmap^ noiseImg = gcnew Bitmap("lena_gaussian.jpg");
    28
    29  double snr = SNR(oriImg, noiseImg);
    30
    31  cout << "SNR of image:" << snr << endl;
    32
    33  return 0;
    34}
    35
    36// Convert RGB to gray level int
    37int colorToInt(Color color) {
    38  return (color.R + color.G + color.B) / 3;
    39}
    40
    41
    42// Calculate signal to ratio
    43double SNR(Bitmap^ oriImg, Bitmap^ noiseImg) {
    44
    45  // ||n||
    46  int n = oriImg->Height * oriImg->Width;
    47
    48  // compute mean of signal
    49  double sumU = 0.0;
    50  for(int y = 0; y != oriImg->Height; ++y) {
    51    for(int x = 0; x != oriImg->Width; ++x) {
    52      sumU += (double)colorToInt(oriImg->GetPixel(x, y));
    53    }
    54  }
    55  double u = (double)sumU / n;
    56  
    57  // compute variance of signal
    58  double diffVS = 0.0, sumVS  = 0.0;
    59  for (int y = 0; y != oriImg->Height; ++y) {
    60    for (int x = 0; x != oriImg->Width; ++x) {
    61      diffVS = (double)colorToInt(oriImg->GetPixel(x, y)) - u;
    62      sumVS += diffVS * diffVS;
    63    }
    64  }
    65  double VS = (double)sumVS / n;
    66
    67  // compute mean of noise
    68  double sumN = 0.0;
    69  for (int y = 0; y != noiseImg->Height; ++y) {
    70    for (int x = 0; x != noiseImg->Width; ++x) {
    71      sumN += (colorToInt(noiseImg->GetPixel(x, y)) - colorToInt(oriImg->GetPixel(x, y)));
    72    }
    73  }
    74  double un = (double)sumN / n;
    75
    76  // compute variance of noise
    77  double diffVN = 0.0, sumVN = 0.0;
    78  for (int y = 0; y != noiseImg->Height; ++y) {
    79    for (int x = 0; x != noiseImg->Width; ++x) {
    80      diffVN = (double)colorToInt(noiseImg->GetPixel(x, y)) -colorToInt(oriImg->GetPixel(x, y))- un;
    81      sumVN += diffVN * diffVN;
    82    }
    83  }
    84  double VN = (double)sumVN / n;
    85
    86  return 20 * log10(sqrt(VS) / sqrt(VN));
    87}

    執行結果


    SNR of image:0.16249
    請按任意鍵繼續 . . .

    原圖


    按此在新窗口浏览图片

    Noise圖片
    按此在新窗口浏览图片


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/3/17 8:08:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/19 22:22:57

    本主题贴数3,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  如何計算SNR (signal-to-ratio)? (.NET) ..(2710字) - 卷积内核,2009年3月17日
        回复:  求信噪比计算公式(摘自论坛)各位高手大家好!求各位给个信噪比的计算公式。数据都是现场故障数据,..(689字) - 卷积内核,2009年3月17日
        回复:  理論上,一個的(信號與噪聲的比值)等於(6.02N+1.76)dB,這裏N等於ADC的位數。雖然我..(8339字) - 卷积内核,2009年3月17日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms