How to find pixel coordinates of a line between two points on an image?

3 views (last 30 days)
Hello,
If I have two pixels in an image, let's say (x1, y1) and (x2, y2) and i want to draw a line between them.
I was using line() to do this, but I don't know how many pixels does that line have, or their position and value.
Is there a way of finding out maybe not all of them but a subset of them to which i can perform some verifications?
And if so, how can I get their coordinates?
Thanks a lot.
  2 Comments
bkpdilau
bkpdilau on 17 May 2022
Unfortunately improfile wants you to manually sellect points. I have the end of the line coords, and i want to get some in between points.

Sign in to comment.

Accepted Answer

bkpdilau
bkpdilau on 17 May 2022
Edited: bkpdilau on 17 May 2022
I used an implementation of Bresenham's algorithm and it seems to be working.
You can find it here:
https://www.mathworks.com/matlabcentral/fileexchange/28190-bresenham-optimized-for-matlab
  1 Comment
Casian Filigean
Casian Filigean on 17 May 2022
Thank you, this is a very elegant implementation, you must have thought really hard to get such a good and optimised option

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!