Transparent series of images with axis using cgImage [message #88115] |
Fri, 21 March 2014 06:01  |
Petros Syntelis
Messages: 32 Registered: June 2013
|
Member |
|
|
Hi everybody,
I am trying create three images with axis in a row, and overplot above them a transparent image.
I have a code like this that works fine in the 'X' window case
cgimage, im1 , xr=[..],yr=[..],/axis, /keep ,pos=pos
loadct,3
cgimage, im2 , xr=[..],yr=[..],/axis, /axis, transparent=transparent, /over,pos=pos
...
and is followed by two other similar sets of plots with different position vectors.
When i want to print this to ps. according to the instructions here
https://www.idlcoyote.com/ip_tips/transparentpng.php
, I have to provide a background image.
Now, if i do the trick described in the documentation, and write the code as
cgDisplay, /Pixmap
cgimage, im1 , xr=[..],yr=[..],/axis, /keep ,pos=pos
bgimage1 = cgSnapshot()
WDelete
...
for all three cases, and pass the bgimages to AlphaBackgroundImage, like
cgps_open ...
cgimage, im1 , xr=[..],yr=[..],/axis, /keep ,pos=pos
loadct,3
cgimage, im2 , xr=[..],yr=[..],/axis, /axis, transparent=transparent, /over,pos=pos, AlphaBackgroundImage=bgimage1
...
cgps_close
I have the following problems:
a) The background images does not match the size of the transparent images in the ps file.
b) The characters in the axis are different
which both of them arise i think from the fact that the window size does not match the ps window file.
Has anybody tried to create transparent images with axis and done it correctly?
Regards,
Petros
|
|
|
|
Re: Transparent series of images with axis using cgImage [message #88118 is a reply to message #88115] |
Fri, 21 March 2014 07:41   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Petros Syntelis writes:
> Has anybody tried to create transparent images with axis and done it correctly?
Not this way, no. :-)
Too much going on here for the hacking that has to take place in direct
graphics. I would do this a completely different way. I would write the
program like this:
;****************************************************
PRO Example, PS=ps
; Fake images.
im1 = cgDemoData(7)
im2 = cgDemoData(21)
im3 = cgDemoData(22)
im4 = cgDemoData(5)
; Build composite images.
cgDisplay, 400, 500, WID=2, /Pixmap
cgimage, im1
cgimage, im4, ctindex=33, $
AlphaFGPos=[0.0,0.25,1.0,0.75], transparent=50
snap1 = cgSnapShot()
cgimage, im2
cgimage, im4, ctindex=33, $
AlphaFGPos=[0.0, 0.25, 1.0, 0.75], transparent=50
snap2 = cgSnapShot()
cgimage, im3
cgimage, im4, ctindex=33, $
AlphaFGPos=[0.0, 0.25, 1.0, 0.75], transparent=50
snap3 = cgSnapShot()
; Delete the Pixmap.
WDelete, 2
; Set multimargin and character size values.
mm = 12
cs = 2.25
; Need a PostScript file?
IF Keyword_Set(ps) THEN BEGIN
cgPS_Open, 'example.ps'
mm = 8
cs = 1.75
ENDIF
; Display them.
cgDisplay, 1200, 500
!P.Multi=[0,3,1]
cgimage, snap1, multimargin=mm, /axes, $
OPosition=opos, axkey={charsize:cs}
yrange = opos[3] - opos[1]
p1 = opos[1] + yrange*0.25
p3 = opos[3] - yrange*0.25
cgPlot, [1], /NoData, /NoErase, Charsize=cs, $
Position=[opos[0], p1, opos[2], p3], AxisColor='red'
cgimage, snap2, multimargin=mm, /axes, $
OPosition=opos, axkey={charsize:cs}
yrange = opos[3] - opos[1]
p1 = opos[1] + yrange*0.25
p3 = opos[3] - yrange*0.25
cgPlot, [1], /NoData, /NoErase, Charsize=cs, $
Position=[opos[0], p1, opos[2], p3], AxisColor='red'
cgimage, snap3, multimargin=mm, /axes, OPosition=opos, $
axkey={charsize:cs}
yrange = opos[3] - opos[1]
p1 = opos[1] + yrange*0.25
p3 = opos[3] - yrange*0.25
cgPlot, [1], /NoData, /NoErase, Charsize=cs, $
Position=[opos[0], p1, opos[2], p3], AxisColor='red'
!P.Multi=0
IF Keyword_Set(PS) THEN BEGIN
cgPS_Close, /PNG
ENDIF
END
;****************************************************
To see it on the display:
IDL> Example
To see it in a PostScript and PNG file:
IDL> Example, /PS
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Transparent series of images with axis using cgImage [message #88120 is a reply to message #88118] |
Fri, 21 March 2014 09:41  |
Petros Syntelis
Messages: 32 Registered: June 2013
|
Member |
|
|
Thx David!
I'll study your example to sort it out!
Cheers,
Petros
On Friday, March 21, 2014 2:41:35 PM UTC, David Fanning wrote:
> Petros Syntelis writes:
>
>
>
>> Has anybody tried to create transparent images with axis and done it correctly?
>
>
>
> Not this way, no. :-)
>
>
>
> Too much going on here for the hacking that has to take place in direct
>
> graphics. I would do this a completely different way. I would write the
>
> program like this:
>
>
>
> ;****************************************************
>
> PRO Example, PS=ps
>
>
>
> ; Fake images.
>
> im1 = cgDemoData(7)
>
> im2 = cgDemoData(21)
>
> im3 = cgDemoData(22)
>
> im4 = cgDemoData(5)
>
>
>
> ; Build composite images.
>
> cgDisplay, 400, 500, WID=2, /Pixmap
>
> cgimage, im1
>
> cgimage, im4, ctindex=33, $
>
> AlphaFGPos=[0.0,0.25,1.0,0.75], transparent=50
>
> snap1 = cgSnapShot()
>
>
>
> cgimage, im2
>
> cgimage, im4, ctindex=33, $
>
> AlphaFGPos=[0.0, 0.25, 1.0, 0.75], transparent=50
>
> snap2 = cgSnapShot()
>
>
>
> cgimage, im3
>
> cgimage, im4, ctindex=33, $
>
> AlphaFGPos=[0.0, 0.25, 1.0, 0.75], transparent=50
>
> snap3 = cgSnapShot()
>
>
>
> ; Delete the Pixmap.
>
> WDelete, 2
>
>
>
> ; Set multimargin and character size values.
>
> mm = 12
>
> cs = 2.25
>
>
>
> ; Need a PostScript file?
>
> IF Keyword_Set(ps) THEN BEGIN
>
> cgPS_Open, 'example.ps'
>
> mm = 8
>
> cs = 1.75
>
> ENDIF
>
>
>
> ; Display them.
>
> cgDisplay, 1200, 500
>
>
>
> !P.Multi=[0,3,1]
>
> cgimage, snap1, multimargin=mm, /axes, $
>
> OPosition=opos, axkey={charsize:cs}
>
> yrange = opos[3] - opos[1]
>
> p1 = opos[1] + yrange*0.25
>
> p3 = opos[3] - yrange*0.25
>
> cgPlot, [1], /NoData, /NoErase, Charsize=cs, $
>
> Position=[opos[0], p1, opos[2], p3], AxisColor='red'
>
>
>
> cgimage, snap2, multimargin=mm, /axes, $
>
> OPosition=opos, axkey={charsize:cs}
>
> yrange = opos[3] - opos[1]
>
> p1 = opos[1] + yrange*0.25
>
> p3 = opos[3] - yrange*0.25
>
> cgPlot, [1], /NoData, /NoErase, Charsize=cs, $
>
> Position=[opos[0], p1, opos[2], p3], AxisColor='red'
>
>
>
> cgimage, snap3, multimargin=mm, /axes, OPosition=opos, $
>
> axkey={charsize:cs}
>
> yrange = opos[3] - opos[1]
>
> p1 = opos[1] + yrange*0.25
>
> p3 = opos[3] - yrange*0.25
>
> cgPlot, [1], /NoData, /NoErase, Charsize=cs, $
>
> Position=[opos[0], p1, opos[2], p3], AxisColor='red'
>
>
>
> !P.Multi=0
>
>
>
> IF Keyword_Set(PS) THEN BEGIN
>
> cgPS_Close, /PNG
>
> ENDIF
>
>
>
> END
>
> ;****************************************************
>
>
>
> To see it on the display:
>
>
>
> IDL> Example
>
>
>
> To see it in a PostScript and PNG file:
>
>
>
> IDL> Example, /PS
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|