Stereographic projection

(G'MIC staff) #1

Hello folks.

I’ve finished implementing a filter in G’MIC for stereographic projection. This is basically a method that projects image data defined on a sphere onto a plane (see wikipedia page for more details). In photography, one common use of such a filter is the generation of so-called Mini planets, from equirectangular panoramas.

So, this new G’MIC filter is available under ‘Deformations / Stereographic projection’.
Suppose you have an equirectangular panorama like the one below (taken from the awesome Flickr gallery of Alexandre Duret-Lutz)

The G’MIC filter ‘Stereographic projection’ looks like this.

It has a few controls to scale/rotate/dilate the result, as well as a cool option to blur left/right sides of your image, in case it is not perfectly periodic along the X-axis (avoiding visible seams/discontinuities in the resulting image)

Here is the obtained result (fortunately, it is close to what the preview shows :wink: ).

This kind of projection is way better than the simple ‘Euclidean to polar’ transform, as you don’t get a singular point at the projection center, and the mapping is conformal, meaning angles are preserved locally.

Here is a quick video showing the G’MIC filter in action, using GIMP (this works the same on Krita of course).

Finally, note that the back-projection method is also implemented, so you can retrieve an equi-rectangular image from a tiny planet image (at least most of it), as this is shown in the video.

Does it look good ? Any suggestion for improvement ?

(Tobias) #2

Nice one. I have one suggestion for improvement. If you make a Little Planet the horizon must be perfectly straight. Perhaps you can add a slider to rotate the input image.

Here is an example, what happens if it is not straight:

(G'MIC staff) #3

@Tobias, don’t you think this kind of processing should be done prior to the application of the filter, and has nothing to do with the deformation process itself ?
I mean, we could also want to correct colors, improve sharpening and lot of different things, but this is clearly something we’ll be able to do as a pre-processing step.

(Morgan Hardwood) #4

I agree with @David_Tschumperle, and the example equirectangular image with a non-straight horizon never happens in real life - the horizon on each end would line up, it would just be wavy in the middle.

(Tobias) #5

If you have a clear horizon it is simple to straiten it. I was thinking more of this little planet I made some time ago. It was not made from 180° panoramas and I had several rounds of rotating, Gimp polar coordinate filter, undo, rotate… A rotate parameter would have saved me some time by not doing this round trips.

Something different, if I set the “Boundary” parameter to transparent I get a little gap. I’m not sure if this is a bug or by design:

Btw. I like the results from your filter much better then the Gimp polar coordinate filter. Especially how the sky is extended to the edges.

(G'MIC staff) #6

Fair enough. I’ll try to add an extra ‘Horizon angle’ parameter or something like this, to see if that can be useful (any idea for a better name ?).

That is indeed normal, but totally useless, so I’ll force periodic boundary conditions for the direct projection (boundary conditions have only sense for the inverse transform).

(G'MIC staff) #7

I’ve added a parameter “Horizon rectification”, which allows to slightly change the rotation angle of the horizon. It actually appears to be a quite useful features for input images that are non-equirectangular.

Playing with this filter also made me realize that if you mirror the effect (option available in the filter), you can sometimes get very weird but interesting results, like the one below:

(Øyvind Kolås) #8

@Tobias, a better filter in GIMP to compare with that polar coordinates is also a stereographic projection, available under filters/map/panorama-projection if you tick the “little planet” check-box and set the tilt to 90degrees. Probably a bit too hidden away, should probably be split out as a separate menu entry.

(Tobias) #9

Cool, thanks. I think “Horizon rectification” is OK, but I’m not a native speaker.
One more thing. If I move the center point I would expect that the angel doesn’t change. (That the Angle point move relative to the center point.)

(Sebastien Guyader) #10

@David_Tschumperle How about “Horizon leveling” instead of “Horizon rectification”?
By the way, very nice addition!

(G'MIC staff) #11

That will be fixed in a few minutes :slight_smile:

Sounds good, I’ll make the change.

(Tobias) #12


  1. My little planets are definitive older then the panorama-projection filter. I think I even used the pre GEGL polar coordinate filter. :wink:

  2. Yes, I think this should be split into two filters. (At least in the UI.) The on canvas rotating is e.g. in the “Little Planet” mode totally useless.

  3. If you rework that filter, please add the “Horizon leveling” there too, its really useful.

  4. Welcome to the forum.

(Lyle Kroll) #13

Pretty cool stuff, David. :slight_smile:

(Karsten R) #14

David, really good addition!

Still your “system” programming (dense scripting) is worth some explanations for interested students in gmic script!
E.g. where is “_fx_project_stereographic” ever defined? It is uncommanded in the last line of your script.

(G'MIC staff) #15

It is defined somewhere at the beginning :

  m "_fx_project_stereographic_mirror : if {!$""1} mirror y elif {$""1==1} mirror xy elif {$""1==3} mirror x fi"

It is used to mirror the image if necessary, as a first step for the direct projection, and as a last step for the back-projection.