int leftBoundary2 = Math.max(mXCenter + expectedXDistance - xDistanceRange, 0);
int rightBoundary2 = Math.min(mXCenter + expectedXDistance + xDistanceRange, (int) mImage.getWidth() - 1);
for (int x = leftBoundary2; x <= rightBoundary2; x++) {
brightnessSum2 += getBrightness(pixelReader.getColor(x, yCoord));
}
<BUG>double avgBrightness2 = brightnessSum2 / (2 * xDistanceRange + 1);
</BUG>
int leftCounter2 = 0;
int rightCounter2 = 0;
while (leftBoundary2 < rightBoundary2) {

int leftBoundary2 = Math.max(mXCenter + expectedXDistance - xDistanceRange, 0);
int rightBoundary2 = Math.min(mXCenter + expectedXDistance + xDistanceRange, (int) mImage.getWidth() - 1);
for (int x = leftBoundary2; x <= rightBoundary2; x++) {
brightnessSum2 += getBrightness(pixelReader.getColor(x, yCoord));
}
float avgBrightness2 = brightnessSum2 / (2 * xDistanceRange + 1);
int leftCounter2 = 0;
int rightCounter2 = 0;
while (leftBoundary2 < rightBoundary2) {
