Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Placing images in the coordinate system?

312 views
Skip to first unread message

Dave

unread,
Oct 3, 2009, 9:04:00 AM10/3/09
to
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

David Park

unread,
Oct 4, 2009, 5:38:06 AM10/4/09
to
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 DrawingTransform on
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}, ycoordinate]],
Text labels placed on the piece of paper},
Options...]


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

pfalloon

unread,
Oct 7, 2009, 7:04:54 AM10/7/09
to
On Oct 4, 8:38 pm, "David Park" <djmp...@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...@comcast.nethttp://home.comcast.net/~djmpark/
>
> From: Dave [mailto:uber.da...@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.

Dave

unread,
Oct 13, 2009, 11:19:25 PM10/13/09
to
On Oct 7, 4:04 am, pfalloon <pfall...@gmail.com> wrote:
> On Oct 4, 8:38 pm, "David Park" <djmp...@comcast.net> wrote:
>
>
>
> > djmp...@comcast.nethttp://home.comcast.net/~djmpark/
>
> > From: Dave [mailto:uber.da...@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 twoimages.
> > (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.

Thanks for your replies everyone! In the end, I went with the
following solution suggested by Maxim:

Transform the Image into a "Raster", which allows specifying a
coordinate rectangle:

image = Import["D:/images/pictures/moon.jpg"];
raster = Raster[Reverse@ImageData[image], {{-180, -90}, {180, 90}}];

ContourPlot[..., Prolog->raster]


Cheers,
Dave

0 new messages