Explanation Mercator filter

135 views
Skip to first unread message

DanielV

unread,
Aug 27, 2011, 10:08:19 AM8/27/11
to MathMap
I've recently stumbled upon mathmap. I'm not really into mathematics
and so I need some help. I've got a square map in the mercator
projection which I ultimately want to transform into winkel tripel or
robinson projection. I though mathmap might be a solution. But as a
start I don't understand how the original mercator formulas
http://mathworld.wolfram.com/MercatorProjection.html
including latitudes and longitudes can be converted into this:

filter mercator (image in)
in(xy * xy:[ cos(pi/2*y + t*2*pi), 1])
end

(why is ' t ' there in the first place, this is a time related
variable right?)
I thought i'll try to find an inverse mercator formula, but then i'm
still stuck as converting the robinson formula to a mathmap
equivalent.

Could anyone point me in the right direction, or shed some light on
the subject for me?

Edgar Bonet

unread,
Aug 29, 2011, 4:17:37 AM8/29/11
to mat...@googlegroups.com
Hello!

DanielV wrote:
> I've recently stumbled upon mathmap. I'm not really into mathematics
> and so I need some help. I've got a square map in the mercator
> projection which I ultimately want to transform into winkel tripel or
> robinson projection. I though mathmap might be a solution. But as a
> start I don't understand how the original mercator formulas
> http://mathworld.wolfram.com/MercatorProjection.html
> including latitudes and longitudes can be converted into this:
>
> filter mercator (image in)
> in(xy * xy:[ cos(pi/2*y + t*2*pi), 1])
> end
>

> [...] Could anyone point me in the right direction, or shed some light on
> the subject for me?

I don't know about the mathmap code you are talking about. I think it
may just be some demo code just intended to look like a Mercator map,
not necessarily be a real one. However, I wrote a mathmap filter to
convert fisheye images (from my Nikon equisolid angle 10.5 DX fisheye)
into panoramic Mercator projections. C.f.
http://groups.google.com/group/mathmap/browse_thread/thread/f5a2f60aa0bc7830
I don't use this filter anymore since I switched to a better one (look
for "Lambert conformal conic projection" in the list) that can output a
Mercator projection as a limit case.

Anyway, just to give an example, here is my old fish2mercator() filter:

----------------------------------------------------------------
filter fish2mercator(image in, float zoom: 0.7-1 (0.94))
f = 10.5/23.6*W;
long = x/f/zoom;
lat = atan(sinh(y/f/zoom));
xx = cos(lat) * sin(long);
yy = sin(lat);
phi = atan(yy, xx);
theta = asin(sqrt(xx*xx+yy*yy));
in(ra:[2*f*sin(theta/2), phi])
end
----------------------------------------------------------------

Here f is the lens' focal length converted to image units, long and lat
are the latitude and longitude, xx, yy and zz the cartesian coordinates
projected into the unit sphere (zz unused), theta and phi the spherical
coordinates relative to the optical axis, and 2*f*sin(theta/2) the
standard projection formula for an equisolid angle fisheye.

The formulas above that convert x and y into lat and long should look
familiar to you after lookin at the Wolfram site. Remember that you have
to go backwards: from the (x, y) coordinates on the final image, to the
coordinates on the initial image.

Hope this helps,

Edgar.

DanielV

unread,
Sep 5, 2011, 7:11:29 AM9/5/11
to MathMap
I'm a bit confused as to why you'd use the inverse mercator formula on
your fisheye photo.
lat = atan(sinh(y/zoom));
long = x/zoom;
Is this supposed to convert from MERCATOR to lat/long so I could throw
that into , for example, the Winkel Tripel forward projection formula.
e.g.

theta= acos(2/pi);
alfa = acos(cos(theta)*cos(long/2));

if x !=0 then
salpha = sin(alfa)/alfa;
else
salpha = 1;
end;

xnew = .5* ( long*cos(theta) + ( 2*cos(lat)*sin(long/2) ) /
salpha );
ynew = .5* ( lat + sin(lat)/salpha);

in(xy:[xnew,ynew])

Or am I doing something really silly here? What is the reason you
convert the lat/long to xx,yy,zz and use that to display the image in
polar coordinates. The way i'd have figured converting fish to
mercator would be just the opposite! I'd thing, ok, everything
basically comes from a 180deg dome, and thus we'd have to convert
these coordinates to xx,yy,zz next calculate lat/long next put that
into the forward mercator projection formula... Apparently this way of
thinking is wrong, i just wonder why :)

On Aug 29, 10:17 am, Edgar Bonet <goo...@edgar-bonet.org> wrote:
> Hello!
>
> DanielV wrote:
> > I've recently stumbled upon mathmap. I'm not really into mathematics
> > and so I need some help. I've got a square map in the mercator
> > projection which I ultimately want to transform into winkel tripel or
> > robinson projection. I though mathmap might be a solution. But as a
> > start I don't understand how the original mercator formulas
> >http://mathworld.wolfram.com/MercatorProjection.html
> > including latitudes and longitudes can be converted into this:
>
> > filter mercator (image in)
> >     in(xy *  xy:[ cos(pi/2*y + t*2*pi), 1])
> > end
>
> > [...] Could anyone point me in the right direction, or shed some light on
> > the subject for me?
>
> I don't know about the mathmap code you are talking about. I think it
> may just be some demo code just intended to look like a Mercator map,
> not necessarily be a real one. However, I wrote a mathmap filter to
> convert fisheye images (from my Nikon equisolid angle 10.5 DX fisheye)
> into panoramic Mercator projections. C.f.http://groups.google.com/group/mathmap/browse_thread/thread/f5a2f60aa...

Mark Probst

unread,
Sep 8, 2011, 6:27:48 PM9/8/11
to mat...@googlegroups.com
On Mon, Sep 5, 2011 at 1:11 PM, DanielV <dver...@gmail.com> wrote:
> Or am I doing something really silly here? What is the reason you
> convert the lat/long to xx,yy,zz and use that to display the image in
> polar coordinates. The way i'd have figured converting fish to
> mercator would be just the opposite! I'd thing, ok, everything
> basically comes from a 180deg dome, and thus we'd have to convert
> these coordinates to xx,yy,zz next calculate lat/long next put that
> into the forward mercator projection formula... Apparently this way of
> thinking is wrong, i just wonder why :)

I have explained why the mapping needs to be "inverse" in this thread:

http://groups.google.com/group/mathmap/browse_thread/thread/e55d227544bc213c/0a1ff4a0b151b6e4

Mark

Reply all
Reply to author
Forward
0 new messages