Hi,
ich habe gerade etwas Schwierigkeiten meine Fehler in meinem Code zu finden.
Das Resultat Bild ist deutlich zu dunkel.
hier der Code:
Code
private void gradientenBetrag(int[] srcPixels, int[] dstPixels, int width, int height, double gradientenBetrag) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pos = y * width + x;
counter = 0;
for (int yK = -1; yK <= 1; yK++) {
for (int xK = -1; xK <= 1; xK++) {
if (yK + y < 0 || yK + y > height - 1 || xK + x < 0 || xK + x > width - 1) {
sobelXTemp[counter] = srcPixels[pos] & 0xff;
counter++;
} else {
kernelPos = (y + yK) * width + x + xK;
sobelXTemp[counter] = srcPixels[kernelPos] & 0xff;
counter++;
}
}
}
// sobel X
// ergebnis= ((b-a)+(d-c)+(f-e))/6
int resultX = getSobelGradient(sobelXTemp[2], sobelXTemp[0], sobelXTemp[5], sobelXTemp[3],
sobelXTemp[8], sobelXTemp[6], 0);
int resultY = getSobelGradient(sobelYTemp[6], sobelYTemp[0], sobelYTemp[7], sobelYTemp[1],
sobelYTemp[8], sobelYTemp[2], 0);
int result = Math.abs(resultX)+ Math.abs(resultY);
//≈
//int result = (int) Math.sqrt((resultX*resultX)+(resultY*resultY));
dstPixels[pos] = (0xFF << 24) | (result << 16) | (result << 8) | result;
}
}
}
Alles anzeigen