Код: Выделить всё
for (int y = 0; y < src.GetHeight() - 1; y++) {
for (int x = 0; x < src.GetWidth() - 1; x++) {
float src00 = src.GetPixelStart(x, y)[0];
float src10 = src.GetPixelStart(x + 1, y)[0];
float src01 = src.GetPixelStart(x, y + 1)[0];
float src11 = src.GetPixelStart(x + 1, y + 1)[0];
float dst00 = dst.GetPixelStart(x, y)[0];
float dst10 = dst.GetPixelStart(x + 1, y)[0];
float dst01 = dst.GetPixelStart(x, y + 1)[0];
float dst11 = dst.GetPixelStart(x + 1, y + 1)[0];
float srcVal = src10 - src00 + src11 - src01;
float dstVal = dst10 - dst00 + dst11 - dst01;
dFx.SetValue(0.25 * (srcVal + dstVal), 0, x, y);
//------
srcVal = src01 - src00 + src11 - src10;
dstVal = dst01 - dst00 + dst11 - dst10;
dFy.SetValue(0.25 * (srcVal + dstVal), 0, x, y);
//------
dFt.SetValue(0.25 * (dst00 + dst10 + dst01 + dst11 - src00 - src10 - src01 - src11), 0, x, y);
}
}
Однако я пытался использовать оператор Собеля в X (
Код: Выделить всё
ConvolutionFilterSeparable({ -1, 0, 1 }, { 1, 2, 1 }) и Y (ConvolutionFilterSeparable({ 1, 2, 1 }, { -1, 0, 1 })
Код: Выделить всё
Image2d dFx = (derivatorA.dx + derivatorB.dx);
Image2d dFy = (derivatorA.dy + derivatorB.dy);
Image2d dFt = (dst - src);
Почему упрощенный расчет работает лучше?
Подробнее здесь: https://stackoverflow.com/questions/786 ... alculation