Re: Placing images in the coordinate system?

*To*: mathgroup at smc.vnet.net*Subject*: [mg103815] Re: Placing images in the coordinate system?*From*: pfalloon <pfalloon at gmail.com>*Date*: Wed, 7 Oct 2009 07:03:20 -0400 (EDT)*References*: <33341602.1254576310852.JavaMail.root@n11> <ha9qdu$7pb$1@smc.vnet.net>

On Oct 4, 8:38 pm, "David Park" <djmp... at comcast.net> wrote: > Dave, > > As usual, I would do try this with the Presentations package, but you could > probably do it without the package with a little more work and perhaps less > intuitively. > > I would draw everything on a "piece of paper" and not use an Axis or Frame > as it is difficult to control the overall image dimensions with them. > > Then you would need a mapping from your {long, lat} coordinates to {x,y} on > the piece of paper. You would have to have some map projection for the 2D > image of the moon surface. It might be difficult to find what the projection > was for the image you have. > > Presentations has a routine DrawingTransform that will transform any > graphics you draw, say in the {long, lat} coordinates, to the {x,y} > coordinates. It also has free standing scales, XTickLine and YTickLine that > you can place on the piece of paper, say just outside the boundaries of the > moon map. That way you get your axes. You could also use DrawingTransformon > these so they would give {long,lat} coordinates on the {x,y} plot. > > So assuming we can either Rasterize the moon image, or use Inset, to place > it at specific coordinates and scale on the piece of paper, the plotting > statement would look something like this: > > Draw2D[ > {moonimage, > {your graphics, XTickLine[...], YTickLine[...]} > /. DrawingTransform[Function[{long,lat}, xcoordinate], > Function[{long,lat}, ycoo= rdinate]], > Text labels placed on the piece of paper}, > Options...] > > David Park > djmp... at comcast.nethttp://home.comcast.net/~djmpark/ > > From: Dave [mailto:uber.da... at gmail.com] > > Hello, > > Using Mathematica 7.0, how can I take an image and give it a position > and scale, so that it can be combined with other graphics? > > Here's what I am trying to do: I would like to have an image map of > the moon as the background for my plot or contour plot. I want to be > able to plot points by their lat,lon positions and have them appear at > the correct points on the map. > > I came up with a hack to do this by rasterizing the plot using Image[] > so that it is the same resolution as the moon image, and then > combining the two images. > (I found a similar technique here:http://mathgis.blogspot.com/2007/12/fun-with-image-overlay.html) > > The problem is this does not work if the plot has Axes->True, because > some space is used for the axes, so the coordinate systems don't match > exactly anymore. > > I really would like to have both Axes and the image together. Is there > a good way to do this? > > Thanks, > Dave What about just importing the image as a Graphics object: img = Import["image.gif", "Graphics"]; Show[img, Frame->True] The x,y values correspond to the pixels, so if you can work out the transform from pixel position to latitude/longitude (e.g. interactively hover over the graphic while holding down the "." key) you could overlay points etc as an Epilog. Similarly, if you want to display the actual lat/long ticks on the axes you can use the inverse of this map. This is still a little fiddly, but the important step of getting the image unambiguously positioned w.r.t. the axes is handled properly so that things won't go awry when you add axes, padding etc. Cheers, Peter.