PDA

View Full Version : Draw line over image



hcrisp
04-14-2011, 02:57 PM
What is the easiest way to draw a line over an image? For example I have a 100x 100 pixel image called image.jpg. I can load it and display it, but I haven't found a way to draw a line based on normalized pixel locations on top of the image in the window. How can I do this?



img = 'image.jpg'
image = IMAGE_READ(img, FILE_TYPE='JPG', QUIET=2)
IMAGE_DISPLAY, image, /QUIET, TITLE='My Image'
; How to draw a line over the image either before or after displaying it?
; Line should go from x1y1 = (0.25, 0.75) to x2y2 = (0.75, 0.25)

donb
04-15-2011, 12:06 PM
Display the image first, then add the line using PLOTS.


WINDOW, 2, Xsize=400, Ysize=400
TV, DIST(400)
PLOTS, [.25,.75], [.75,.25], /Normal, Thick=3


You can also use pixel locations in PLOTS if that's easier; use the /Device keyword instead of the /Normal keyword.

Hope this helps,

Don B.

hcrisp
04-18-2011, 12:06 PM
Thanks, that works great. I don't suppose there is an easy way to animate successive line plot calls over the image? I looked at WgAnimateTool, but it requires creation of all the frames prior to use. For my purposes, that would result in excessive memory.

donb
04-20-2011, 10:44 AM
For this type of 'animation' technique, you can implement succesive redraws, which is not memory intensive, and does not require creation and then storing each image for the animation as needed by WzAnimationTool.

The concept is to display the image, overlay whatever you want, and then redraw the image and overlay the next thing (a re-positioned line in this case).

Here's some EXAMPLE code.

PRO TEST
WINDOW, 2, Xsize=400, Ysize=400
x1 = .1 & y1 = .9 & x2 = .9 & y2 = .1
FOR i = 0, 8 DO BEGIN
TV, DIST(400)
PLOTS, [x1, x2], [y1, y2], /Normal, Thick=2
y1 = y1 - .1 & y2 = y2 + .1
WAIT, 1
END
ENDThe WAIT command is there so you have time to see the changes. If you're doing this in within a PV-WAVE Widget application I'd change that to add a delay timer (WwTimer).

Hope this helps,

Don B.