POV-Ray : Newsgroups : povray.general : Map Mollweide projection (elliptical) onto sphere Server Time
1 Nov 2024 13:20:30 EDT (-0400)
  Map Mollweide projection (elliptical) onto sphere (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: Adrian
Subject: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 05:55:01
Message: <web.4eb7b7752242f00631dc6fa00@news.povray.org>
I have an image [1] of a spherical surface that I want to map onto a sphere, but
it is a Mollweide projection. I tried to convert it to a rectangular Mercator
projection (is that even the right one?) with Mathematica [2], but it doesn't
really work. I do get a rectangular image which kind of looks right, but when I
use the texture in Povray with

pigment { image_map { png "text.png" map_type 1 } }

the edges don't seem to match up and the texture looks distorted around the
poles. In the end, I want to create something similar to this [3]. What can I
do?

Adrian




[1] http://map.gsfc.nasa.gov/media/101080/101080_7yrFullSky_WMAP_1280B.png (I
cropped it properly, of course)

[2] invmerc[{x_, y_}] := {ArcTan[Sinh[y]], x};
theta2[phi_] := theta2[phi] =
   FindRoot[2 th + Sin[2 th] == Pi Sin[phi], {th, 0}][[1, 2]];
moll[{phi_, lambda_}] := {2 Sqrt[2] lambda Cos[theta2[phi]]/Pi,
   Sqrt[2] Sin[theta2[phi]]};
merc2moll[p_] := moll[invmerc[p]];
result = ImageTransformation[Import["text.png"], merc2moll,
   DataRange -> Sqrt[2] {{-2, 2}, {-1, 1}}];
Export["text-merc.png", result];

[3] http://particle.physics.ucdavis.edu/Graphics/rotate/wmap_movie.gif


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 08:36:40
Message: <4eb7dee8$1@news.povray.org>
Adrian wrote:

> pigment { image_map { png "text.png" map_type 1 } }

I think Mercator is cylindrical so you could try map_type 2.



Post a reply to this message

From: Adrian
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 10:10:00
Message: <web.4eb7f3e85ab24bf331dc6fa00@news.povray.org>
Christian Froeschlin <chr### [at] chrfrde> wrote:
> Adrian wrote:
>
> > pigment { image_map { png "text.png" map_type 1 } }
>
> I think Mercator is cylindrical so you could try map_type 2.

Unfortunately, that doesn't help, even after I adjust the scale and translate
the sphere such that it goes from y=0 to y=1, as required by map_type 2. The
distortions are still present.



Yes, I am not entirely sure that this is the case. My Mathematica implementation
of the conversion may be faulty (even though I followed mathworld [1]), is there
a standard way to deal with this? Some UNIX tool or even a built-in feature of
povray?


Adrian




[1] http://mathworld.wolfram.com/MercatorProjection.html
http://mathworld.wolfram.com/MollweideProjection.html


Post a reply to this message

From: clipka
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 12:09:18
Message: <4eb810be$1@news.povray.org>
Am 07.11.2011 11:49, schrieb Adrian:
> I have an image [1] of a spherical surface that I want to map onto a sphere, but
> it is a Mollweide projection. I tried to convert it to a rectangular Mercator
> projection (is that even the right one?) with Mathematica [2], but it doesn't
> really work. I do get a rectangular image which kind of looks right, but when I
> use the texture in Povray with
>
> pigment { image_map { png "text.png" map_type 1 } }
>
> the edges don't seem to match up and the texture looks distorted around the
> poles. In the end, I want to create something similar to this [3]. What can I
> do?

You want to convert the image to an "equirectangular projection" (see 
http://en.wikipedia.org/wiki/Equirectangular_projection); that'll allow 
you to use map type 1.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 12:17:24
Message: <4eb812a4@news.povray.org>
Adrian wrote:

> Yes, I am not entirely sure that this is the case. My Mathematica implementation
> of the conversion may be faulty (even though I followed mathworld [1]), is there
> a standard way to deal with this? Some UNIX tool or even a built-in feature of
> povray?

There appears to be a unix tool at

http://www.users.globalnet.co.uk/~arcus/mmps/

I think the unprojected latlong format will be the
correct one for map_type 1.

Regarding the WMAP data it seems they already provide it in latlong
format for the "Science on a Sphere" 3d visualization system, so you
might be able to simply use these:

http://lambda.gsfc.nasa.gov/product/map/current/sos/7year/


Post a reply to this message

From: Adrian
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 10 Nov 2011 09:55:01
Message: <web.4ebbe3485ab24bf331dc6fa00@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 07.11.2011 11:49, schrieb Adrian:
> > I have an image [1] of a spherical surface that I want to map onto a sphere, but
> > it is a Mollweide projection. I tried to convert it to a rectangular Mercator
> > projection (is that even the right one?) with Mathematica [2], but it doesn't
> > really work. I do get a rectangular image which kind of looks right, but when
> You want to convert the image to an "equirectangular projection" (see
> http://en.wikipedia.org/wiki/Equirectangular_projection); that'll allow
> you to use map type 1.

Thanks, I guess I was over-complicating things! Also thanks to Christian for the
hint at Matthew's "project". Unfortunately it yields a wrong result for my case.
I am considering letting him know about it, because that would have been a great
tool otherwise. I appreciate the hint at the WMAP data as well, but I was
curious on how to handle this for future projects as well.

For the record, since Mathematica didn't yield a satisfactory result for
whatever reason, I wrote a small Python script using SciPy that takes a cropped
*ppm Mollweide projection and converts it to plate carree, which can be mapped
onto a sphere by Povray just fine. Of course, it is much slower than a C/C++
solution, but it's fast enough for my purposes (around 2m on my PC for a
2048x1024 image). If anyone wants to use it, see below for the source.

Adrian




#!/usr/bin/python

import numpy as np
from scipy import misc
import sys

infile = "wmap.ppm"
outfile = "wmap2.ppm"

arr = misc.imread(infile)
result = np.empty(arr.shape)
height, width, depth = arr.shape # Backwards but correct
print "Dimensions: %ix%i" % (width, height)

class memoized(object):
   def __init__(self, func):
      self.func = func
      self.cache = {}
   def __call__(self, *args):
      try:
         return self.cache[args]
      except KeyError:
         value = self.func(*args)
         self.cache[args] = value
         return value

@memoized #Improves runtime by factor of 2 easily
def theta(phi):
    # First guess for newton method
    xn = 0
    old = xn + 1.
    while abs(xn - old)>1e-6:
        old = xn
        xn = xn - (xn + np.sin(xn) - np.pi * np.sin(phi)) / (1 + np.cos(xn))
    return xn / 2.

def mollweide(x, y):
    th = theta(y)
    return np.sqrt(8) * x * np.cos(th) / np.pi, np.sqrt(2) * np.sin(th)

def img2coord(a, b):
    return (a * 1. / width - .5) * 2 * np.pi, (b * 1. / height - .5) * np.pi

def coord2img(x, y):
    # Try to stay inside ellipse to minimize background effects
    xround = yround = np.floor
    if x<0: xround = lambda z: -np.floor(-z)
    if y<0: yround = lambda z: -np.floor(-z)
    return (xround((x / (2 * np.sqrt(8)) + .5) * width),
            yround((y / (2 * np.sqrt(2)) + .5) * height))

for a in range(width):
    sys.stdout.write("\r%i%%" % ( 100 * a / width ))
    sys.stdout.flush()
    for b in range(height):
        x, y = img2coord(a, b)
        x, y = mollweide(x, y)
        x, y = coord2img(x, y)
        result[b, a] = arr[y-1, x-1]

misc.imsave(outfile, result)
sys.stdout.write("\nDone\n")


Post a reply to this message

From: Stephen Mather
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 16 Dec 2011 16:55:01
Message: <web.4eebbd2c5ab24bf32cf1bdcc0@news.povray.org>
Nice solution.  You could also use GDAL utilities to handle this-- which are
written in C++ (and also have APIs for Python, etc).

Best,
Steve


"Adrian" <nomail@nomail> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> > Am 07.11.2011 11:49, schrieb Adrian:
> > > I have an image [1] of a spherical surface that I want to map onto a sphere, but
> > > it is a Mollweide projection. I tried to convert it to a rectangular Mercator
> > > projection (is that even the right one?) with Mathematica [2], but it doesn't
> > > really work. I do get a rectangular image which kind of looks right, but when
> > You want to convert the image to an "equirectangular projection" (see
> > http://en.wikipedia.org/wiki/Equirectangular_projection); that'll allow
> > you to use map type 1.
>
> Thanks, I guess I was over-complicating things! Also thanks to Christian for the
> hint at Matthew's "project". Unfortunately it yields a wrong result for my case.
> I am considering letting him know about it, because that would have been a great
> tool otherwise. I appreciate the hint at the WMAP data as well, but I was
> curious on how to handle this for future projects as well.
>
> For the record, since Mathematica didn't yield a satisfactory result for
> whatever reason, I wrote a small Python script using SciPy that takes a cropped
> *ppm Mollweide projection and converts it to plate carree, which can be mapped
> onto a sphere by Povray just fine. Of course, it is much slower than a C/C++
> solution, but it's fast enough for my purposes (around 2m on my PC for a
> 2048x1024 image). If anyone wants to use it, see below for the source.
>
> Adrian
>
>
>
>
> #!/usr/bin/python
>
> import numpy as np
> from scipy import misc
> import sys
>
> infile = "wmap.ppm"
> outfile = "wmap2.ppm"
>
> arr = misc.imread(infile)
> result = np.empty(arr.shape)
> height, width, depth = arr.shape # Backwards but correct
> print "Dimensions: %ix%i" % (width, height)
>
> class memoized(object):
>    def __init__(self, func):
>       self.func = func
>       self.cache = {}
>    def __call__(self, *args):
>       try:
>          return self.cache[args]
>       except KeyError:
>          value = self.func(*args)
>          self.cache[args] = value
>          return value
>
> @memoized #Improves runtime by factor of 2 easily
> def theta(phi):
>     # First guess for newton method
>     xn = 0
>     old = xn + 1.
>     while abs(xn - old)>1e-6:
>         old = xn
>         xn = xn - (xn + np.sin(xn) - np.pi * np.sin(phi)) / (1 + np.cos(xn))
>     return xn / 2.
>
> def mollweide(x, y):
>     th = theta(y)
>     return np.sqrt(8) * x * np.cos(th) / np.pi, np.sqrt(2) * np.sin(th)
>
> def img2coord(a, b):
>     return (a * 1. / width - .5) * 2 * np.pi, (b * 1. / height - .5) * np.pi
>
> def coord2img(x, y):
>     # Try to stay inside ellipse to minimize background effects
>     xround = yround = np.floor
>     if x<0: xround = lambda z: -np.floor(-z)
>     if y<0: yround = lambda z: -np.floor(-z)
>     return (xround((x / (2 * np.sqrt(8)) + .5) * width),
>             yround((y / (2 * np.sqrt(2)) + .5) * height))
>
> for a in range(width):
>     sys.stdout.write("\r%i%%" % ( 100 * a / width ))
>     sys.stdout.flush()
>     for b in range(height):
>         x, y = img2coord(a, b)
>         x, y = mollweide(x, y)
>         x, y = coord2img(x, y)
>         result[b, a] = arr[y-1, x-1]
>
> misc.imsave(outfile, result)
> sys.stdout.write("\nDone\n")


Post a reply to this message

From: Yukterez Enabled Io
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 22 Apr 2013 16:20:05
Message: <web.51759aac5ab24bf3c83525700@news.povray.org>
The problem is, the python script does not work on my PC. Is there anything I
need to modify in the source code, for example, if the width is 2000px and the
height 1000px, or is the code ready to use? I get a synatx error when I run the
script 1 to 1: http://img28.imageshack.us/img28/1204/screenshotj.gif


Post a reply to this message

From: "Jérôme M. Berger"
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 22 Apr 2013 17:59:44
Message: <5175b2d0$1@news.povray.org>
Yukterez_Enabled_Io wrote:
> The problem is, the python script does not work on my PC. Is there anyt
hing I
> need to modify in the source code, for example, if the width is 2000px 
and the
> height 1000px, or is the code ready to use? I get a synatx error when I
 run the
> script 1 to 1: http://img28.imageshack.us/img28/1204/screenshotj.gif
> 
> 
	That's a Python 2 script and you're trying to run it on a Python 3
install. They are not compatible...

		Jerome
-- 
mailto:jeb### [at] freefr
http://jeberger.free.fr
Jabber: jeb### [at] jabberfr


Post a reply to this message


Attachments:
Download 'us-ascii' (1 KB)

From: Yukterez Enabled Io
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 23 Apr 2013 15:00:01
Message: <web.5176d9135ab24bf3593487030@news.povray.org>
I now installed Python 2.6 and the numpy, scipy and imread modules from
http://www.lfd.uci.edu/~gohlke/pythonlibs
but it still says

Traceback (most recent call last):
  File "C:\Users\Yukterez\Documents\pythonscriptcmb.py", line 9, in <module>
    arr = misc.imread(infile)
AttributeError: 'module' object has no attribute 'imread'

why?


Post a reply to this message

Goto Latest 10 Messages Next 3 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.