【发布时间】:2011-11-18 23:02:27
【问题描述】:
我正在阅读 Gonzalez 和 Woods 的 DIP 第 2 版,并尝试使用 wxImage 用拉普拉斯面具(第 129 和 130 页)弄脏我的手。
float kernel [3][3]= {{1, 1, 1},{1,-8, 1},{1, 1, 1}};
这里是处理循环:
unsigned char r,g,b;
float rtotal, gtotal, btotal; rtotal = gtotal = btotal = 0.0;
//ignore the border pixel
for(int i = 1; i<imgWidth-1; i++)
{
for(int j = 1; j<imgHeight-1; j++)
{
rtotal = gtotal=btotal =0.0;
for(int y = -1; y<=1;y++)
{
for(int x = -1; x<=1;x++)
{
// get each channel pixel value
r = Image->GetRed(i+y,j+x);
g = Image->GetGreen(i+y,j+x);
b = Image->GetBlue(i+y,j+x);
// calculate each channel surrouding neighbour pixel value base
rtotal += r* kernel[y+1][x+1];
gtotal += g* kernel[y+1][x+1] ;
btotal += b* kernel[y+1][x+1];
}
}
//edit1: here is how to sharpen the image
// original pixel - (0.2 * the sum of pixel neighbour)
rtotal = loadedImage->GetRed(x,y) - 0.2*rtotal;
gtotal = loadedImage->GetGreen(x,y) - 0.2*gtotal;
btotal = loadedImage->GetBlue(x,y) - 0.2*btotal;
// range checking
if (rtotal >255) rtotal = 255;
else if (rtotal <0) rtotal = 0;
if(btotal>255) btotal = 255;
else if(btotal < 0) btotal = 0;
if(gtotal > 255) gtotal = 255;
else if (gtotal < 0 ) gtotal =0;
// commit new pixel value
Image->SetRGB(i,j, rtotal, gtotal, btotal);
我将其应用于北极图片(灰色图像),我得到的只是一团黑白像素!
任何想法我可能在 for 循环中遗漏了什么?
Edit1:在谷歌上环顾后终于得到了答案。这个dsp的东西肯定很棘手!我在上面的代码中添加了,它会锐化图像。
干杯
【问题讨论】:
-
这对 dsp.stackexchange.com 来说是个好问题
标签: c++ image-processing wxwidgets