Function Repository Resource:

SphericalImage

Source Notebook

Map an image onto a sphere to view it from the inside as a VR surrounding or from the outside as a globe

Contributed by: Markus van Almsick

ResourceFunction["SphericalImage"][image]

returns a Graphics3D expression that displays image on a sphere.

Details and Options

The image needs to exhibit an aspect ratio of 1/2 to cover the entire sphere.
The default ViewPoint is the center of the sphere.
A ViewPoint vector with a norm larger than one lets you view the spherical image from the outside.
ResourceFunction["SphericalImage"] accepts the same options as Graphics3D, with the following additions and changes:
PerformanceGoal"Quality"increase the number of polygons that form the sphere
“MirrorImage"Automaticflip the orientation of the projected image
The PerformanceGoal settings "Speed" and "Quality" respectively decrease or increase the number of polygons that form the sphere.
The default settting "MirrorImage" Automatic ensures the correct image orientation when seen from the inside or outside of the sphere.
Dragging with the mouse rotates the spherical image.

Examples

Basic Examples (1) 

View the night sky near the European Southern Observatory in Chile (the large image may take a while to download):

In[1]:=
img360 = Import["https://cdn.eso.org/images/large/nik7600p-cc-extended.jpg", ImageSize -> {3496, 1748}];
In[2]:=
ResourceFunction["SphericalImage"][img360, ImageSize -> 480]
Out[2]=

Scope (1) 

You can choose a ViewPoint outside the sphere:

In[3]:=
img360 = Import["https://cdn.eso.org/images/large/nik7600p-cc-extended.jpg", ImageSize -> {3496, 1748}];
In[4]:=
ResourceFunction["SphericalImage"][img360, ViewPoint -> {-3, 0, 0}]
Out[4]=

Options (2) 

PerformanceGoal (1) 

In[5]:=
map = Rasterize[
  GeoGraphics[GeoRange -> "World", GeoBackground -> "ReliefMap", GeoZoomLevel -> 3], RasterSize -> 2^3 {360, 180}]
Out[5]=

Use fewer polygons for the spherical geometry for faster interactive rendering:

In[6]:=
ResourceFunction["SphericalImage"][
 map,
 ViewPoint -> {0, -2, 0},
 PerformanceGoal -> "Speed"
 ]
Out[6]=
In[7]:=
ResourceFunction["SphericalImage"][
 map,
 ViewPoint -> {0, -2, 0},
 PerformanceGoal -> "Quality"
 ]
Out[7]=

MirrorImage (1) 

Flip the image to view the world map from the back inside out:

In[8]:=
map = Rasterize[
  GeoGraphics[GeoRange -> "World", GeoBackground -> "ReliefMap", GeoZoomLevel -> 3], RasterSize -> 2^3 {360, 180}]
Out[8]=
In[9]:=
ResourceFunction["SphericalImage"][
 map,
 "MirrorImage" -> True
 ]
Out[9]=

Applications (4) 

Create a stitched image on a spherical canvas:

In[10]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/da29b15b-55f6-4853-8c40-b420c2962fe8"]
In[11]:=
stitch = ImageStitch[imgs, "Sphere"]
Out[11]=

Pad the image to cover an entire sphere:

In[12]:=
focalLength = 873;(* in pixel per radians *)
In[13]:=
vrImage = RemoveAlphaChannel[
   ImageCrop[stitch, \[Pi] focalLength {2, 1}, Padding -> RGBColor[0, 0, 0, 0]], RGBColor[0, 0.49, 1]];

Create an interactive 360 ° viewer:

In[14]:=
Framed@ResourceFunction["SphericalImage"][vrImage, ViewAngle -> 0.5]
Out[14]=

View the spherical construct from the outside:

In[15]:=
ResourceFunction["SphericalImage"][vrImage, ViewPoint -> {0, -2, 0}]
Out[15]=

Version History

  • 1.1.0 – 07 June 2023
  • 1.0.0 – 15 February 2023

Source Metadata

Related Resources

License Information