필터 지우기
필터 지우기

How to draw line by changing the pixel color between two points?

조회 수: 1 (최근 30일)
saravanakumar D
saravanakumar D 2014년 1월 25일
답변: Walter Roberson 2014년 1월 25일
I want to draw the vertical line between two points and store that output image in some variable for further processing
I have done this line by changing pixel color of pixels between two points. we can done this by using for loop. But it takes more time.
Problem:
'% (548,493) (548,191)
x1=548;
y1=493;
x2=548;
y2=191;'
How to draw the line by changing the pixel color without using loop.

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 25일
The difficulty with a for loop is calculating the correct pixels to write into. There is a standard algorithm for this though: see Bresenham's Line Algorithm.
You could also be a bit lazy and use an existing tool.
You could use poly2mask and supply it with the endpoint coordinates and the array size. A logical mask would be output that is true at each location along the path. You would then set those locations to the desired color.
I was going to mention another possibility but I think the above is much easier.
If I recall there is also a routine in the Computer Vision Toolbox that can be used to draw a line inside an array.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by