int leftBoundary = Math.max(mXCenter - expectedXDistance - xDistanceRange, 0);
int rightBoundary = Math.min(mXCenter - expectedXDistance + xDistanceRange, (int) mImage.getWidth() - 1);
for (int x = leftBoundary; x <= rightBoundary; x++) {
brightnessSum += getBrightness(pixelReader.getColor(x, yCoord));
}
<BUG>double avgBrightness = brightnessSum / (2 * xDistanceRange + 1);
</BUG>
int leftCounter = 0;
int rightCounter = 0;
while (leftBoundary < rightBoundary) {

int leftBoundary = Math.max(mXCenter - expectedXDistance - xDistanceRange, 0);
int rightBoundary = Math.min(mXCenter - expectedXDistance + xDistanceRange, (int) mImage.getWidth() - 1);
for (int x = leftBoundary; x <= rightBoundary; x++) {
brightnessSum += getBrightness(pixelReader.getColor(x, yCoord));
}
float avgBrightness = brightnessSum / (2 * xDistanceRange + 1);
int leftCounter = 0;
int rightCounter = 0;
while (leftBoundary < rightBoundary) {
