overlying an image and a contour plot [message #17876] |
Fri, 12 November 1999 00:00  |
tebbens
Messages: 1 Registered: November 1999
|
Junior Member |
|
|
We are trying to overlay an image and a contour
plot, but can't get a perfect match in position
and size.
On the contour plot, the x axis is 652 values and
the y axis is 5048 values. We want to fit the
image exactly into the contour plot.
The following commands are used:
position=[.6,.05,r,.95]
tv, image, .6, .05, $
xsize=position(2)-position(0), $
ysize=position(3)-position(1), /normal
xvalue = 652.
yvalue = 5048.
; r should be the length of the x-axis in the
; normal coordinate system (x and y window
; size=1)
r= 10./7.*(.9 * xvalue/yvalue) + .6
contour, xstyle=1, ystyle=1, /iso, $
position=[.6,.05,r,.95], /noerase
The image and contour overlay, but the x-axis of
the image is too long to fit the contour plot.
When the command tvimage is used instead of tv,
the images are the same size, but are offset in
both x and y direction by a few pixels.
We think the problem is with the r value, but
we don't know why the simple commands above
don't work.
Any suggestions to get these to overlay?
Thanks in advance.
Sent via Deja.com http://www.deja.com/
Before you buy.
|
|
|
Re: overlying an image and a contour plot [message #17888 is a reply to message #17876] |
Wed, 17 November 1999 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
> Silly me. For some reason I hardcoded the image position in
> PLOTIMAGE, which prevents !P.MULTI from working. I have a fixed
> version on my web page with the following entry under MODIFICATIONS:
>
> ; Correct behavior with no POSITION keyword, 17 Nov 1999, CM
>
> Now !p.multi works fine.
Let's see, ... the woes of software distribution. Now,
where were we? :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: overlying an image and a contour plot [message #17889 is a reply to message #17876] |
Wed, 17 November 1999 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Craig Markwardt <craigmnet@cow.physics.wisc.edu> writes:
>
> To solve these problems I use the PLOTIMAGE procedure available from
> my web page (listed below). It makes putting images on the screen or
> Postscript page easy -- especially aligning everything.
>
Silly me. For some reason I hardcoded the image position in
PLOTIMAGE, which prevents !P.MULTI from working. I have a fixed
version on my web page with the following entry under MODIFICATIONS:
; Correct behavior with no POSITION keyword, 17 Nov 1999, CM
Now !p.multi works fine.
Craig
http://cow.physics.wisc.edu/~craigm/idl/idl.html
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: overlying an image and a contour plot [message #17917 is a reply to message #17876] |
Tue, 16 November 1999 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
davidf@dfanning.com (David Fanning) writes:
>
> Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
>
>> P.S. PLOTIMAGE uses parts of TVIMAGE. The good parts. Thanks David!
>
> Uh, I think the reason TVImage works so well for me
> is that I have the Congrid routine I downloaded
> from you in my Path. Thanks, Craig!
>
Maybe. :-) You really only notice it when you have an image with just
a few pixels. PLOTIMAGE is fully self-contained, including a correct
interpolation routine instead of the buggy CONGRID.
After looking at my download logs I realized that people just weren't
getting the additional required programs for things like PLOTIMAGE.
Since then I've made a concerted effort to keep the programs
self-contained, which usually means including a few small functions or
subroutines.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
|
Re: overlying an image and a contour plot [message #17921 is a reply to message #17876] |
Tue, 16 November 1999 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Getting the right pixel alignment can be a problem. I also totally
agree with Mr. Bennett's suggestion that you may need to "add" an
extra half-pixel on either side.
I like to think about it this way: CONTOUR applies to data at the
pixel *centers*, but when displaying an image you want to show every
pixel out to its edges, and that's where the two half pixels comes
from. I would also like to point out that TVIMAGE uses CONGRID, which
has a bug in the way it interpolates, which *guarantees* that you will
be off by at least a half a pixel. Not good.
To solve these problems I use the PLOTIMAGE procedure available from
my web page (listed below). It makes putting images on the screen or
Postscript page easy -- especially aligning everything.
Here's how it works. This little script assumes you have an image,
and your X and Y values:
;; Usually you want to BYTSCL your image first - I like this algorithm
IDL> b = bytscl(image, min=-100, max=100, top=!d.n_colors-3b)+1b
;; Then you compute your image boundaries. Remember those half-pixels!
IDL> dx = x(1) - x(0) & dy = y(1) - y(0)
IDL> imgxrange = [min(x)-0.5*dx, max(x)+0.5*dx]
IDL> imgyrange = [min(y)-0.5*dy, max(y)+0.5*dy]
;; Finally, plot the image and overlay the contours
IDL> PLOTIMAGE, b, imgxrange=imgxrange, imgyrange=imgyrange
IDL> CONTOUR, image, x, y, ...
You see, most of it is a little bookkeeping. PLOTIMAGE is nice
because you can specify an XRANGE and YRANGE independent of the image
boundaries, meaning that you can zoom in to a sub image for example.
And for astronomers, it will automatically reverse the image if
needed!
Good luck,
Craig
http://cow.physics.wisc.edu/~craigm/idl/idl.html
P.S. PLOTIMAGE uses parts of TVIMAGE. The good parts. Thanks David!
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|