PDA

View Full Version : Placing Text on an image



green12
05-23-2009, 01:22 PM
Anyone know how to place text on an image?

For example I will TV and array and would like to put text next to this displayed array and eventually output it.

donb
05-25-2009, 03:22 PM
XYOUTS is used to place text. If you only TV an image then no data coordinate system has been defined. You'll have to add either the /Norm or /Device keywords for the x, y location of the text in either normalized or device coordinates (data coordinates is the default).

Use the same technique when you change to your hardcopy device - TV the image and then XYOUTS the text.

Hope this helps,

Don B.

green12
05-26-2009, 10:10 AM
This is how I am outputting my images right now. I am not sure how XYOUTS would fit into this scheme. Your ideas? Thanks again! :D



temp=BYTSCL(apdEven, min=m) ;scales from 0 - 256 for display purpose
WSET, outputmap
TVLCT, r, g, b, /Get ; save the colors from the colortable
c_map=BYTARR(3, 256) ; store the colors into a colormap
c_map(0,*)=r
c_map(1,*)=g
c_map(2,*)=b
image = IMAGE_CREATE(temp, File_name=filename + '.jpg', Colormodel=1, Colormap = c_map, File_type = 'jpg')
stat= IMAGE_WRITE('C:\Documents and Settings\Administrator\Desktop\' + filename + '.jpg', image)

totallyunimodular
05-26-2009, 11:07 AM
XYOUTS would be called right after your graphics call. In your example, you have a byte array to save as a JPEG file, but you need to actually display that byte array to the screen, then use XYOUTS to write text to the displayed image, and then use TVRD to capture the displayed image as a new byte array, and you'll pass this array to IMAGE_CREATE. For example,



WINDOW, /Free, Xsize=500, Ysize=500
LOADCT, 18
TVSCL, DIST(500)
XYOUTS, 0.25, 0.75, "Hello World", /Normal, Font=0
; Get the r,g,b vectors associated with the current colormap...
TVLCT, r, g, b, /Get
;Load the black and white colortable prior to screen capture...
LOADCT, 0
;Save the currently displayed image as a 3D byte array...
img = TVRD(True=3)
;Reload the previous colortable
TVLCT, r,g,b
;Save the byte array as a JPEG
image = IMAGE_CREATE(img, File_type = 'jpg')
status= IMAGE_WRITE('C:\'+ 'ForumsTest.jpg', image)


You might want to check out the Visual Numerics white paper 8-bit and 24-bit Color Graphics in PV-WAVE (http://www.vni.com/company/whitepapers/#pvwave), which explains a lot of the issues you might face when dealing with colormaps and displaying and saving images consistently across platforms.

Hope this helps

green12
05-29-2009, 10:32 AM
totallyunimodular-

Your code does not work or at least not for me. I copied your code directly like the following changing only the filename and loadct color and I do not get the desired output. Any ideas?

Here is my code:



PRO TEST
WINDOW, /Free, Xsize=500, Ysize=500
LOADCT, 4
TVSCL, DIST(500)
XYOUTS, 0.25, 0.75, "Hello World", /Normal, Font=0
; Get the r,g,b vectors associated with the current colormap...
TVLCT, l, m, n, /Get
;Load the black and white colortable prior to screen capture...
LOADCT, 0
;Save the currently displayed image as a 3D byte array...
img = TVRD(True=3)
;Reload the previous colortable
TVLCT, l,m,n
;Save the byte array as a JPEG
image = IMAGE_CREATE(img, File_type = 'jpg')
status= IMAGE_WRITE('C:\Documents and Settings\Administrator\Desktop\test.jpg', image)
END

green12
05-29-2009, 11:51 AM
after looking farther into TVRD and taking out loadct, 0 i have gotten it to work.

totallyunimodular
05-29-2009, 01:49 PM
Glad to hear. With respect to the LOADCT call, are you on a Unix system, or are you running 8-bit as opposed to 24-bit graphics?