I'm attempting to plot a particular line over an original image (an array) that i have. Basically, I have an angle and offset (measured from the center of the image) that I want to plot the line over. The problem is, I'm not exactly sure how to do this. I can write a really complicated piece of code to do this, but I'm wondering if there's an easier way that I don't know of (maybe with matplotlib). Thanks.
A:
Assuming that your offset is actually a x, y coordinate of the center of the line, and that the line should be a fixed length, then it's a simple matter of trigonometry with matplotlib:
x = [offsetx-linelength*cos(angle), offsetx+linelength*cos(angle)]
y = [offsety-linelength*sin(angle), offsety+linelength*sin(angle)]
plot(x, y, '-')
Theran
2009-06-18 03:15:13
+1
A:
Use PIL and draw line, cricle, or another image over the original image
import Image, ImageDraw
im = Image.open("my.png")
draw = ImageDraw.Draw(im)
draw.line((0, 0, 100, 100), fill=128)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
Anurag Uniyal
2009-06-18 03:37:30