全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:6414
推到 Plurk!
推到 Facebook!

如何算出MSE , PSNR??

尚未結案
skyshine
一般會員


發表:1
回覆:2
積分:0
註冊:2004-10-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-31 09:58:11 IP:218.171.xxx.xxx 未訂閱
小弟寫了一個去後面4bit的壓縮法 我想知道一張圖的品質如何.... MSE愈低愈好,則PSNR是愈高愈好    我寫的程式內容為 void __fastcall TForm1::cut1Click(TObject *Sender) {         Graphics::TBitmap *TheBitmap;         Byte* ptr;         Image2->Picture->Bitmap=Image1->Picture->Bitmap ;         TheBitmap=Image2->Picture->Bitmap;         for(int y=0;yHeight;y ) { ptr=(Byte*)TheBitmap->ScanLine[y]; for(int x=0;xWidth;x ) { int z=240; ptr[x]=(byte)(ptr[x]&z); } } } 請教一下...PSNR的值 謝謝^^
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-31 14:42:38 IP:211.76.xxx.xxx 未訂閱
skyshine 您好:    distortion就是您刪去的那四個bits,把它們取出並取平方後相加即是所有的distortion。
引言: 小弟寫了一個去後面4bit的壓縮法 我想知道一張圖的品質如何.... MSE愈低愈好,則PSNR是愈高愈好 我寫的程式內容為
#include <math.h>  // for log10(.)
....
void __fastcall TForm1::cut1Click(TObject *Sender)
{
        Graphics::TBitmap *TheBitmap;
        Byte* ptr;
        Image2->Picture->Bitmap=Image1->Picture->Bitmap ;
        TheBitmap=Image2->Picture->Bitmap;
        double mse, distortion=0.0;
        for(int y=0;yHeight;y  )
        {
                ptr=(Byte*)TheBitmap->ScanLine[y];
                for(int x=0;xWidth;x  )
                {
                        int z=240;
                        ptr[x]=(byte)(ptr[x]&z);
                        distortion  = (ptr[x] & 0x0f)*(ptr[x] & 0x0f);
                }
        }
        mse = distortion / (TheBitmap->Height)*(TheBitmap->Width);
        double psnr = 10*log10(255*255/mse)
}
請教一下...PSNR的值 謝謝^^
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
skyshine
一般會員


發表:1
回覆:2
積分:0
註冊:2004-10-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-10-31 15:56:21 IP:218.171.xxx.xxx 未訂閱
#include <math.h> // for log10(.) .... void __fastcall TForm1::cut1Click(TObject *Sender) { Graphics::TBitmap *TheBitmap; Byte* ptr; Image2->Picture->Bitmap=Image1->Picture->Bitmap ; TheBitmap=Image2->Picture->Bitmap; double mse, distortion=0.0; for(int y=0;yHeight;y ) { ptr=(Byte*)TheBitmap->ScanLine[y]; for(int x=0;xWidth;x ) { int z=240; ptr[x]=(byte)(ptr[x]&z); distortion = (ptr[x] & 0x0f)*(ptr[x] & 0x0f); } } mse = distortion / (TheBitmap->Height)*(TheBitmap->Width); double psnr = 10*log10(255*255/mse); } 執行後開圖會錯 原因Floating point division by Zero. 還有請問一下... Edit2->Text=StrToInt(psnr); 這樣寫好像是錯的....應該double是到小數好幾位.... 我要讓它顯示很多位應該如何改呢?
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-01 17:54:58 IP:211.76.xxx.xxx 未訂閱
引言: #include <math.h> // for log10(.) .... void __fastcall TForm1::cut1Click(TObject *Sender) { Graphics::TBitmap *TheBitmap; Byte* ptr; Image2->Picture->Bitmap=Image1->Picture->Bitmap ; TheBitmap=Image2->Picture->Bitmap; double mse, distortion=0.0; for(int y=0;yHeight;y ) { ptr=(Byte*)TheBitmap->ScanLine[y]; for(int x=0;xWidth;x ) { int z=240; ptr[x]=(byte)(ptr[x]&z); distortion = (ptr[x] & 0x0f)*(ptr[x] & 0x0f); } } mse = distortion / (TheBitmap->Height)*(TheBitmap->Width); double psnr = 10*log10(255*255/mse); } 執行後開圖會錯 原因Floating point division by Zero. 有種可能是您的圖形是JPG格式,所以用ScanLine(.)去讀會發生問題。 底下程式可將Image的JPG格式轉為BITMAP,請參考。
void JpgToBmp(TImage *image)
{ Graphics::TBitmap *bmp = new Graphics::TBitmap();      bmp->Width  = image->Picture->Width;
  bmp->Height = image->Picture->Height;
  bmp->Canvas->Draw(0,0,image->Picture->Graphic);
  image->Picture->Bitmap->Assign(bmp);
  image->Refresh();      delete bmp;
}
還有請問一下... Edit2->Text=StrToInt(psnr); 這樣寫好像是錯的....應該double是到小數好幾位.... 我要讓它顯示很多位應該如何改呢?
  AnsiString msg;
  msg.printf("%5.2f dB", psnr);
  Edit1->Text = msg;
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
skyshine
一般會員


發表:1
回覆:2
積分:0
註冊:2004-10-26

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-04 09:45:40 IP:218.171.xxx.xxx 未訂閱
謝謝richtop大大~ 我已經完成去4bit和IGS壓縮法了 多虧你給我一些靈感~ 小弟才接觸BCB不久....請多多指教^^
bvd
一般會員


發表:9
回覆:12
積分:4
註冊:2006-10-31

發送簡訊給我
#6 引用回覆 回覆 發表時間:2006-11-07 23:43:07 IP:124.8.xxx.xxx 未訂閱

===================引 用 文 章===================
skyshine 您好: distortion就是您刪去的那四個bits,把它們取出並取平方後相加即是所有的distortion。
引言: 小弟寫了一個去後面4bit的壓縮法我想知道一張圖的品質如何.... MSE愈低愈好,則PSNR是愈高愈好 我寫的程式內容為
                        int z=240;
                        ptr[x]=(byte)(ptr[x]&z);
                        distortion  = (ptr[x] & 0x0f)*(ptr[x] & 0x0f);
               
請問richtop大大,上述的ptr[x]&z和ptr[x] & 0x0f)*(ptr[x] & 0x0f是什麼意思呢??
還有為什麼z會是240呢???
多謝指導~~!


------
加強磨鍊
系統時間:2024-05-03 13:31:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!