0

I am trying to draw a line using Bresenham line algorithm, given starting (x1,y1) and ending (x2,y2) points. Every time when I try to draw the line, pixels are getting disconnected. I followed the Matlab solutions Matlab Bresenham 8-connected, Bresenham 4-connected, Bresenham any gradient and DDA too.

But every time I try to draw the steep lines, pixels getting disconnected. I am not sure whether it is an issue with Matlab imshow.

Image what I am getting (blue line).

Bresenham Result

What I want is something exact as:

Matlab Structuring Element

Please note that I used structuring element (strel function in Matlab to produce binary image).

Can someone please help me on this? I appreciate your time and efforts.

ViG
  • 1,848
  • 1
  • 11
  • 13
  • 1
    Bresenham requires the slope to be less than 1. If you have greater slopes, you need to use a different coordinate system, in which you have an appropriate slope (e.g. swap x/y). Btw, I really doubt that the blue line is the result of a Bresenham implementation. – Nico Schertler Mar 20 '18 at 18:15
  • See [this blog post](http://www.crisluengo.net/index.php/archives/400) for a trivial implementation and clear explanation. – Cris Luengo Mar 20 '18 at 19:45

1 Answers1

0

It is an issue with the screen resolution. On 13" MacBook Pro the blue line with steep gradient was disconnected. On high-resolution monitor like 22" (1920x1080) the steep blue lines are connecting well.

Connected Line