You can search not between a and b, but between points on the same line, but outside the borders of the image. You can make them simply overlay vector (ba) as many times as necessary on side and on side b. And use your Bresenham line algorithm.
For more specific answers, ask a better question, please. Do you think pixels are dots or squares or circles? What is a pixel on line in your terms? What width is your line? Are you looking for a line with a maximum number of pixels per cm length or within a rectangle? Among the lines you are looking for?
source share