1

Is there an easy way to add an oriented stripe to an image that writes over the pixel values rather than just using plot?

I want to have any image, pick a column pixel at the bottom of the image, specify an angle and a width and draw a stripe in that direction - for example the (quite excellent) picture below:

enter image description here

I pick a pixel (blue cross) and an angle (red) and draw a line with a width specified.

I had a google around with matlab functions but could only find things like plot. Many thanks!

Mike Miller
  • 253
  • 6
  • 18
  • You are going to have to be more specific in your question. How is your image displayed? How do you intend to enter your angle? What line width do you desire? And how is it specified? – Juderb Aug 17 '15 at 16:39
  • @Juderb well it was more a question to see if there was a general function like this that could write a line of certain value over matrix values - image display isn't important here. I was trying to avoid writing a whole function myself. – Mike Miller Aug 17 '15 at 16:45

2 Answers2

1

Assuming you have a 2-d image, it's a 2-d matrix and you want to change values. You are looking for Bresenham's line-drawing algorithm. It is the classic algorithm for drawing lines on 2-d graphics displays, and should work nicely for this situation. A MATLAB implementation claims to be here, but the site is down for maintenance as I type this. Here is another implementation I found via Google.

cxw
  • 16,685
  • 2
  • 45
  • 81
1

Just in case anyone else is looking for help on this type of question, as well as cxw's answer, I'd like to point out gnovice's answer here. Both implementations are a great solution to this question.

Community
  • 1
  • 1
Mike Miller
  • 253
  • 6
  • 18