开发者

get pixels of a line -:- MATLAB [duplicate]

This question already has answers here: Closed 10 years ago.

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 functi开发者_如何学运维on in MATLAB could help me in this code, and how can I use it ? .

thanks !


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜