function getLeftmostPoint(y) local x1 = 0 while x1 < img.width and img.getInt(x1, y) >= 0xF00000 do x1 = x1+1 end return x1 end function getRightmostPoint(y) local x2 = img.width while x2 > 0 and img.getInt(x2-1, y) >= 0xF00000 do x2 = x2-1 end return x2 end function getWidth(y) local x2 = getRightmostPoint(y) local x1 = getLeftmostPoint(y) return math.max(0, x2-x1) end function getAverageWidth(y1, y2) local sum = 0 for y = y1, y2-1 do sum = sum+getWidth(y) end return sum/(y2-y1) end function upperWidthToLowerWidth() local upper = getAverageWidth(0, math.floor(img.height/3)) local lower = getAverageWidth(math.floor(img.height*2/3), img.height) return upper/lower end