Can you post your input image here? Is it a black line drawn on a white bg(or vice-versa)?
Also from my understanding of your problem formulation, you’re trying to estimate m and b values given an input image. If that’s the case, this doesn’t seem to be a correct/intuitive function mapping.