4

Possible Duplicate:
detect if a pixel in RGB image belong to a line between two other pixels (MATLAB)

I want to detect two pixel in an image and get all pixel of plotted line between them .

I do not want to plot the line, I just want to get all pixels positions [as (x,y) in the image] of virtually line between the two pixels .

which function in MATLAB could help me in this code, and how can I use it ? .

thanks !

Community
  • 1
  • 1
user504363
  • 541
  • 2
  • 11
  • 25
  • And a few more related questions: [Get all pixel coordinates of a vector inside a image](http://stackoverflow.com/questions/1429210/get-all-pixel-coordinates-of-a-vector-inside-a-image), [MATLAB: Drawing a line over a black and white image](http://stackoverflow.com/questions/2464637/matlab-drawing-a-line-over-a-black-and-white-image) – gnovice Dec 16 '10 at 17:30

3 Answers3

5

You need something like Bresenham's line algorithm. I don't know of a Matlab function for this, but now that you know what you are looking for, your search may be more fruitful. And it's not very difficult to implement in Matlab.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
1

If I understood your question correctly, you have two questions here.

(1) How to detect two pixels in an image --- This would largely depend on other things that you did not mention in your question, their properties, such as their colors, locations in the image (they are together or apart), the relative proportion of those two pixels with respect to the entire image size (to design an efficient detection method.)

(2) How to display pixels without lines between them --- I suppose you could give a 0.5 shift to all of the pixel positions, and use 'pcolor' to display the image. Then, you could type as follows:

p = pcolor (X,Y,C);

set(p, 'EdgeColor','none'); % This will remove the lines between pixels.

Good Luck.

Community
  • 1
  • 1
Y.T.
  • 200
  • 3
0

Solving the simple y = m*x + b linear equation (or its parametric form) and then checking which pixels that line goes through may also be sufficient. It really depends on how precise you want your line to be. Bresenham's line algorithm will give more accurate results (thinner, prettier line), of course.

mpenkov
  • 21,621
  • 10
  • 84
  • 126
  • y = m*x + b .......... I do not think it may do what I want correctly, as many lines in the same scale have the same slope and I handle pixels that have an area (not absolut point ) and may some pixels do not achieve the line equation exactly ........ I will try to use Bresenham's line algorithm ... thanks all – user504363 Dec 16 '10 at 13:51