作者ainigi (坚持)
看板C_and_CPP
标题Re: [问题] BCB影像处理杂讯
时间Sat Apr 11 10:37:48 2009
※ 引述《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