# How to build Stellarium landscapes from photographs of your own (3/4)

## Establishing and checking the correct orientation of the panorama

Establishing the precisely correct orientation of the panorama is a step that involves a certain amount of mathematical effort, but that is absolutely essential for usability and realism of the stellarium landscape to be created. This is done in three steps:

- First of all, any remaining skew of the horizon, which corresponds to an axis inclination of the virtual observer from the vertical, is eliminated. This step must be carried out in Hugin.
- The remaining excess of the elevation angle, i.e. the effect of the panorama "swelling out" above the mathematical horizon line, is eliminated by corrective scaling in Y direction during post-processing of the panorama image file with GIMP.
- The correct azimuthal alignment of the panorama is performed at the very end when the created panorama is integrated in Stellarium by assigning the appropriate value to the
*angle_rotatez*parameter in the*landscape.ini*config file.

### Identifying, logging and evaluating landmarks

The prerequisite is the clear and reliable identification of several landmarks or landscape features both in reality and on the maps and satellite images from Google Maps / Google Earth. The landmarks should ideally be distributed azimuthally as evenly as possible and be located in a strip of up to 5° on both sides of the horizon. As a work tool for coordinatization, I recommend GPS Geoplaner on the website www.geoplaner.de (author: Martin Nathansen). However, because the sea level information displayed, taken from the Google Elevation Service, is not always correct or are sometimes not available, you should also consult maps with contour lines and use a GPS logger on site.

The relevant parameters of the selected landmarks, such as geographic coordinates, sea level and height above ground, as well as those of the recording location and your own eye height / lens height, are recorded in a table and initial calculations are carried out, for which you may also use an MS Excel / LO Calc - Can create a spreadsheet or a program / script. Such a table could look like this:

For the calculation of the azimuth and distance of the landmarks, online scripts from various websites for great-circle calculation such as on cactus2000.de or movable-type.co.uk can be used to 5 degree decimals!) and which output the true courses and the great-circle distance as the result. For the azimuth, the true course of the line of sight __at the observer__ is relevant. One converts arc minutes and seconds of this value into degrees decimals, rounds the total value to 4 decimal places and enters it for the azimuth of the landmark. The distance to the landmark should be noted in meters or kilometers with 4 digits.

The real altitude angle can now be computed from the height difference landmark-observer and the distance to the landmark. For distances up to 2 km one can neglect the curvature of the earth with an error <0.01° and use the altitude angle formula for the plane (do not forget your own height of eye/lens!):

Real altitude angle = arctan

Height difference landmark - observer |

Distance landmark - observer |

For greater distances, the curvature of the earth must be taken into account. For distances up to 100 km and object heights up to 10 km (Mount Everest!) a modified arctangent formula can be used as a very good approximation, again with an error <0.01° (mean earth radius = 6371.0 km):

Real altitude angle = arctan(

Height difference landmark - observer |

Distance landmark - observer |

Earth radius |

Earth radius + Total height ASL of landmark |

Distance landmark - observer |

2 · Earth radius |

Now the pixel coordinates of the landmarks in the TIFF panorama image file are converted into altitude angle (corresponds to the pitch parameter) and "proto-azimuth" values (corresponds to the yaw parameter) and compared with the corresponding real altitude angles. Since panoramas of the "Equirectangular" type correspond to the plane charts of atlas cartography (plate carrée projection), the conversion is very easy:

Pano proto-azimuth (yaw) = −180° +

X coordinate of landmark + 0.5 |

Total pano width in pixels |

Pano altitude angle (pitch) = 90° −

Y coordinate of landmark + 0.5 |

Total pano width in pixels |

For this step, too, the data and calculation results required for the landmarks and finally the altitude angle deviation are logged in a table:

The altitude angle deviations can ideally be broken down into two parts, namely into

- a first component which is the same for all yaw / azimuth values and describes the
__altitude excess angle__of the panorama, i.e. the overflow of the panorama over the mathematical horizon line upwards, and - a second component with an average of zero, which varies sinusoidally with the yaw angle and whose amplitude indicates the
__skewness of the horizon__or the inclination of the virtual observer's axis of the panorama from the vertical.

As in the example table, the first part is simply calculated as the average of the altitude angle deviations of all landmarks and interpreted as an altitude excess angle, the correction of which is initially postponed but performed later as part of a corrective scaling in GIMP. To determine the second component, this altitude excess is subtracted from the calculated altitude angle deviations, which makes it clear that this remaining second component automatically is of zero average over all landmarks. In the ideal case, this second component has the form of a simple sinusoidal wave over all yaw angles - if not, it should be approximated as closely as possible by such a sinusoidal wave with a certain amplitude.

After finding such a sine approximation, it is important to determine the size of the amplitude and to record the yaw angle at which the approximation is reaching its positive amplitude (i.e. its maximum value). Since the sine is very flat in the vicinity of its extremes, it is recommended to indirectly determine this yaw angle by determining the zeros (the maximum must occur 90° before or after a zero). If the sine amplitude and the yaw angle of the maximum are known, the corresponding correction of the skewed horizon can be performed in the Move/Drag tab of Hugin's Fast Panorama Preview.

To do this, the yaw position parameter is first set to the relevant yaw angle and the Apply button is clicked, shifting the corresponding part of the panorama into the center. The yaw parameter is then immediately set to zero again and the determined sine amplitude is now entered for the pitch parameter, but with a minus sign. Clicking the Apply button again corrects the skewed horizon and thus the inclination of the virtual observer axis from the vertical. Finally, the yaw shift should be reversed to bring the anchor image back to a yaw value of zero.

### Eliminating the skewness of the horizon by performing a trigonometrical regression

A convenient procedure for determining the necessary values is to perform a trigonometric regression as it is possible e.g. with the graphing or CAS pocket calculators from CASIO used in German "gymnasium" schools today. For this purpose, the value pairs (Yaw | elevation angle deviation) of at least three landmarks in degrees are required from the last table. With a CASIO fx-CG50, for example, these value pairs are entered in a statistics table, repeated once with yaw values increased by 360° (to force a 360° period of the regression function) and then are submitted to a trigonometric regression in order to determine an approximation function of type f(x) = a * sin(bx + c) + d. Here d is the altitude angle excess, a>0 the amplitude of the horizon skewness, b always ≈ π/180° and -c/b the sine zero with a positive slope, so that for a yaw value of -c/b+90° the sine approximation takes on its maximum value.

**Alternative:** The dynamic math software GeoGebra, which is available for all common PC platforms and as a WebApp, is also able to perform regressions. With the *TrendSin[{(x1, y1), (x2, y2), ...}]* command, the specified value pairs are submitted to a trigonometric regression, the result of which is displayed as a functional equation. In order to use the result, it is important to increase the number of decimal places displayed in GeoGebra beforehand.

In the above example the result is d = 0.7082° as altitude excess angle (for later use), a = 0.3083° as horizon skew and -c/b+90° = 263.6344° or -96.3656° for the yaw value of the maximum upward deviation of the horizon. The following measures must now be carried out under the Move/Drag tab:

- Set yaw position parameter to +96.3656° (change sign!), press Apply button
- Enter zero for yaw and -0.3083° (minus sign!) for pitch, press the Apply button, then immediately enter zero again for pitch (don't forget!)
- Switch briefly to the Images tab and note the displayed yaw value for the anchor photo (must be approximately 96.3656°),

back to the Move / Drag tab and enter the additive inverse of this value for yaw, press Apply

This completes the elimination of the horizontal skewness of the panorama.

After this processing, save the panorama file with versioning! The last status of the panorama can then be output as a TIFF image file and the altitude angles in the panorama and their deviation from reality are calculated again for control purposes. If the result is unsatisfactory, the procedure described must be repeated.

## Scaling, post-processing, and finish of the panorama with GIMP

Once the artifacts have been eliminated as far as possible and the skewed horizon corrected, the further processing of the panorama in GIMP takes place, which includes very different measures:

- Scaling to a Stellarium-compatible target resolution
- Elimination of the altitude excess
- Optimization in terms of brightness and color saturation
- Removing the photographic sky
*Dehazing**Blending similar panoramas to remove the last artifacts*

The steps in italics are not necessary in many cases; however, the remaining steps are indispensable.

### Corrective scaling of the created panorama to a Stellarium-compatible resolution

The TIFF panorama image file created by Hugin and checked for correctness is now loaded into GIMP and __down__scaled to one of the Stellarium-compatible target resolutions (2048x1024, 4096x2048, 8192x4096, 16384x8192 etc.) using [Image / Scale Image ...] (__never up__scale!) and the result is saved in XCF format. The format suitable for your equipment can be found in the list under "What you need in order to start work" at the beginning of this manual. Remember that the horizontal and vertical number of pixels in Stellarium landscapes must __necessarily__ be a natural power of 2.

The ascertained altitude excess angle is then corrected with the following steps:

- Calculation of the corrected vertical expansion (for the target format 4096x2048, for example, the total panorama height = 2048):

Corrected vertical extent = Total pano height in pixels ·

90° |

90° + altitude excess |

- Vertical scaling of the panorama to the corrected vertical extent with [Image / Scale Image ...]
__in Y-direction only__- for achieving this, X- and Y-scaling have to be__unlinked__by clicking on the chain symbol! The height (Y dimension) of the panorama is set to the corrected vertical dimension just calculated, while the width (X dimension) of the panorama must remain unchanged.

In the case of a 4096x2048 panorama with an altitude excess of 0.7149°, this step results in a vertical shrinkage of the panorama by 16 pixel lines to 2032 pixel lines. - Compensation of the pixel lines "lost" by the vertical scaling by adding the same number of transparent pixel lines at the top of the panorama and thus restoring the target total height of the panorama - for this purpose set the height (Y-dimension) of the panorama with [Image / Canvas Size] back to the target total height and set the Y offset to the maximal possible value by clicking the "up" arrow (must correspond exactly to the number of "lost" pixel lines), so that the layer with the panorama will be pushed to the lower edge of the canvas. Finally, use [Layer / Layer to Image Size] to extend this layer to the entire canvas.

Save the result in XCF format.

### Optimization in terms of brightness and color saturation

In general, no color saturation correction is required for panoramas taken in full sunlight. But panoramas that have been taken when the sky is overcast (when the sun is high) are remarkably colorful, so that in most cases only a slight upward color saturation correction is required. To do this, invoke [Colors / Hue-Saturation ...] in GIMP, enter a value from 5 to a maximum of 10 for Saturation, confirm with OK and save.

However, even after exposure correction in Hugin, panoramas are usually too bright for use with Stellarium, which is particularly evident when simulating twilight and night. It is usually advisable to reduce the brightness by invoking [Colors / Levels ...] in GIMP and reducing the gamma value from 1.00 to 0.80, 0.70 or even 0.60 (for extremely bright panoramas). If necessary, you can create panorama image files with different gamma values and use them to simulate daylight, twilight, moonless night and full moon night in Stellarium in order to find the right setting for the gamma value. Light pollution parameters can be set to 2 (the second darkest setting).

### Removing the sky

The essential part of post-processing with GIMP is cutting the photographic sky out of the panorama as precisely as possible, because the sky generated by Stellarium later only appears in the transparent part of the panorama area, and the better the cutting out of the photographic sky from the panorama, the better The overall impression of the Stellarium-Panorama combination is more realistic.

The following GIMP tools are particularly suitable for this purpose:

- Rectangle Select Tool & Free Select Tool - for cutting off large parts of the sky
- Fuzzy Select Tool (alternative: Select by Color Tool) - for color-oriented cutting away of parts of the sky to the limits of filigree structures
- Paintbrush Tool / Color Erase Mode / Brush 2.Hardness 075 - for fine processing of the filigree structures in the border area to the sky

Before starting, check whether the panorama layer has an alpha channel (important!) - if not, create it.

For __rough processing__, select larger contiguous areas of the sky with the Rectangle Select Tool and cut them off. The Free Select Tool can also be used to select large and small areas and cut them off the sky.

With the Fuzzy Select Tool you can capture similarly colored areas of the sky, such as clouds, and then cut them off. Make sure that the selected area does not cover the horizon and its filigree structures (tree tops, antennas, etc.) - use the undo function if necessary and lower the threshold parameter before making a new selection. The representation (view) of the panorama on your screen may have to be enlarged accordingly for processing (recommendation: 400%).

With the help of these tools, the sky should be cut away down to an approximately 3 pixel wide border at the edge of the horizon and its filigree structures. This hem is now in the __Fine-tuning__ removed:

Enlarge panorama display (View) to 800% to 1600%. Select the paintbrush tool and switch to Color Erase Mode, select Brush "2. Hardness 075" with pixel width 2 or 3 and select the color for the Color Erase Mode locally from the area of the sky to be erased - select again and again at intervals as the Sky color is not the same everywhere! This is especially true if clouds appear in this area.

Now carefully erase the sky in the area of tree tops, branches, foliage, building edges and other filigree structures of the horizon. The resulting semi-transparency in the area of branches and foliage best reproduces the visual impression of a sky that is translucent through branches and foliage.

Edit all of the horizon line in this way. Make sure not to erase into definitely non-transparent areas (e.g. walls). Also pay attention to whether lightening in the area of branches and foliage is caused by the translucent sky (delete!) or by reflections (do not delete!). Attention: The outermost left and right edges of the panorama must be processed at the same Y-coordinates using exactly the same method, so that no artifacts occur at the seam with the 360° ring closure (read the displayed coordinates carefully!).

**Alternative:** In contrast to the Fuzzy Select Tool, which only selects the connected component of the clicked pixel, with the Select by Color Tool all color-matching areas of the panorama can be selected regardless of context and thus also isolated sky areas between the branches of trees and in other filigree structures automatically select. However, I recommend sticking to the Fuzzy Select Tool and working on the filigree structures with the Paintbrush Tool as described.

Regularly save the panorama with versioning while work continues, so that you have a fallback position in the event of errors and problems.

When the processing of the panorama in the target format is finished, it is exported in PNG format. The created panorama is now ready for integration into Stellarium.