# Re: overlying an image and a contour plot

```
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
--------------------------------------------------------------------------

```