Re: [問題] BCB影像處理雜訊

看板C_and_CPP作者 (堅持)時間16年前 (2009/04/11 02:37), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《yanqinru (髍鵀)》之銘言: : 各位板友好 : 小弟是剛學影像處理的新手 : 目前在研究雜訊程式碰到了許多問題 : 雖然有對照書本寫的雜訊公式來看 : 可是還是不知道以下三段程式是怎麼做加入雜訊運算 : 首先是Impulse noise的部份 : level值算是強度嗎?那麼它有特定範圍嗎? : 在這段程式裡有寫到pix = cp*x : cp是定義的色平面,那將它乘以x可以得到什麼? : 再者是Gaussian noise : _ : 書本寫高斯雜訊為p(z)=((1/2^0.5)*標準差)*e^(-(z-z)^2)/2*標準差^2 : 可是對照下面的程式 : 一開始定義的mean和sd是什麼? : 然後在程式裡的運算 : sqrt12和sqrt10是代表什麼?是要再另外定義它成為某個數字還是??? : 我真的不太清楚這樣的寫法跟書本的公式有什麼關聯性 : 如果有板友了解的話可以幫我解惑嗎 : 最後是Uniform Noise的部份 : 一樣是不清楚公式跟程式的關連性... : 雖然說mean和sd是要輸入的值 : 可是他們主要是代表控制什麼? : 然後在迴圈裡的ran到sum3=...應該是在計算p(z) : 可是我研究許久還是不懂到底程式是怎麼表達p(z)... : (Impulse Noise) : prob = StrToInt(Form11->Edit1->Text); : level = StrToInt(Form11->Edit2->Text); : randomize(); : for (int y = 0;y < nBitmap->Height;y++) : { : aptr = (Byte*)nBitmap->ScanLine[y]; : for (int x = 0;x < nBitmap->Width;x++) : if (random(100) <= prob) : { : pix1 = cp * x; x是座標,乘以cp,設為pix1,而pix1又把它當作新的x座標 所以很明顯,cp是位移的參數 這樣影像之後又會累加上level,所以你這張圖會一直被之後的座標影響,if cp>1 if cp<1 你的影像應該後面很容易全部變成255 : aptr[pix1] = (Byte)(aptr[pix1]+level); : aptr[pix1+1] = (Byte)(aptr[pix1+1]+level); : aptr[pix1+2] = (Byte)(aptr[pix1+2]+level); : } : } : (Gaussian Noise) : mean = StrToInt(Form11->Edit1->Text); : sd = StrToFloat(Form11->Edit2->Text); : //ShowMessage("Mean = "+IntToStr(mean)+",\nSD ="+FloatToStr(sd)+"."); : randomize(); : for (int y = 0;y < nBitmap->Height;y++) : { : aptr = (Byte*)nBitmap->ScanLine[y]; : for (int x = 0;x < nBitmap->Width;x++) : { : total = 0.0; : for (int k = 0;k < 10;k++) : { : ran = (float)(random(100)+1) / 100; : total += (float)sqrt12 * sd * (ran - 0.5); : } 這一段就是很無聊的加十次rand雜訊,所以你的sqrt12和sqrt10應該都只是權重質 srqt12越大且sqrt10越小,雜訊就越大 反之就越小 : total /= (float)sqrt10; : total += (float)mean; : pix1 = cp * x; : sum1 = total+(float)aptr[pix1]; : sum2 = total+(float)aptr[pix1+1]; : sum3 = total+(float)aptr[pix1+2]; : if (sum1 < 0.0) sum1 = 0.0; : if (sum2 < 0.0) sum2 = 0.0; : if (sum3 < 0.0) sum3 = 0.0; : aptr[pix1] = (Byte)(sum1); : aptr[pix1+1] = (Byte)(sum2); : aptr[pix1+2] = (Byte)(sum3); : } : } : (Uniform Noise) : mean = StrToInt(Form11->Edit1->Text); : sd = StrToFloat(Form11->Edit2->Text); : randomize(); : for (int y = 0;y < nBitmap->Height;y++) : { : aptr = (Byte*)nBitmap->ScanLine[y]; : for (int x = 0;x < nBitmap->Width;x++) : { : ran = (float)(random(100)+1) / 100; : total = ran - 0.5; : total *= (float)sqrt12; : total *= sd; : total += (float)mean; : pix1 = cp * x; 這個很明顯的就是前面兩招合在一起 給你自己去思考吧,這都很簡單,沒有很難 : sum1 = total+(float)aptr[pix1]; : sum2 = total+(float)aptr[pix1+1]; : sum3 = total+(float)aptr[pix1+2]; : if (sum1 < 0.0) sum1 = 0.0; : if (sum2 < 0.0) sum2 = 0.0; : if (sum3 < 0.0) sum3 = 0.0; : aptr[pix1] = (Byte)(sum1); : aptr[pix1+1] = (Byte)(sum2); : aptr[pix1+2] = (Byte)(sum3); : } : } : 以上幾個問題煩請板友幫小弟解惑 : 不好意思一次問太多問題了... : 小弟僅能盡量以微薄的P幣答謝回答問題的板友 : 感謝大家 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.236.164
文章代碼(AID): #19u09zUh (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
文章代碼(AID): #19u09zUh (C_and_CPP)