[問題] 影像處理noise的問題
各位板友好
小弟最近開始學習影像處理
目前遇到了一些問題想請教各位
以下有Impulse、Gaussuan、Uniform三個雜訊程式段
想請問三個程式中for迴圈裡大概是在做什麼?
因為一直無法將理論和程式結合在一起
又不確定自己的想法到底有沒有錯誤
所以想問看看
不好意思麻煩各位了
(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;
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);
}
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);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.64.186.243
推
04/09 10:55, , 1F
04/09 10:55, 1F
→
04/09 11:22, , 2F
04/09 11:22, 2F
→
04/09 11:23, , 3F
04/09 11:23, 3F
→
04/09 11:23, , 4F
04/09 11:23, 4F
推
04/09 11:25, , 5F
04/09 11:25, 5F
→
04/09 11:27, , 6F
04/09 11:27, 6F
→
04/09 11:27, , 7F
04/09 11:27, 7F
推
04/09 11:48, , 8F
04/09 11:48, 8F
→
04/09 11:49, , 9F
04/09 11:49, 9F
→
04/09 11:50, , 10F
04/09 11:50, 10F
推
04/09 11:51, , 11F
04/09 11:51, 11F
→
04/09 11:52, , 12F
04/09 11:52, 12F
→
04/09 12:56, , 13F
04/09 12:56, 13F