我正在尝试为图像卷积实现4 nieghbour laplacian:
我处于运动的最基本阶段,并试图建立关于
如何处理图像。我的问题很基本,但我很困惑。
4个邻居拉普拉斯人:
0 -1 0
-1 4 -1
0 -1 0
当我运行此问题时,有人会因为我找不到错误而导致错误,最后
给我以下价值观。和图像保持不变。
(507,503)[r = 55 | g = 55 | b = 55]
(507,504)[r = 59 | g = 59 | b = 59]
(507,505)[r = 4e | g = 4e | b = 4e]
(507,506)[r = 45 | g = 45 | b = 45]
(507,507)[r = 4 | g = 4 | b = 4]
(507,508)[r = 0 | g = 0 | b = 0]
(507,509)[r = 0 | g = 0 | b = 0]
(507,510)[r = 0 | g = 0 | b = 0]
(507,511)[r = 0 | g = 0 | b = 0]
(508,0)[r = 0 | g = 0 | b = 0]
(508,1)[r = 0 | g = 0 | b = 0]
(508,2)[r = 0 | g = 0 | b = 0]
(508,3)[r = 0 | g = 0 | b = 0]
(508,4)[r = 0 | g = 0 | b = 0]
void MyFrame::OnTestingImage(wxCommandEvent & event)
{
printf("Testing...");
free(loadedImage);
loadedImage = new wxImage(bitmap.ConvertToImage());
float kernel[3][3]= {{0, -1, 0},{-1,4, -1},{0, -1, 0}};
int r,g,b;
float intensity;
float sum = 0;
for( int i=0;i<imgWidth;i++)
for(int j=0;j<imgWidth;j++){
for(int r = -1;r<2;r++)
for(int t = -1;t<2;t++)
{
if(r+i<0 || r+i>imgWidth || j+t < 0||j+t>imgHeight )
intensity = 0;
else
intensity = loadedImage->(GetRed(i + kernel[r][t], j + kernel[r][t]));
sum += intensity *((float)kernel[r][t]);
}
sum = (int)intensity;
r = g = b = sum;
printf("(%d,%d) [r = %x | g = %x | b = %x] \n",i,j,r,g,b);
loadedImage->SetRGB(i,j,r,g,b);
}
printf(" Finished Testing.\n");
Refresh();
}
最佳答案
我认为应该
intensity = loadedImage->(GetRed(i + r, j + t));