Small Python prototypes for two sensor-model building blocks:
- Coordinate transformations for a camera and for GPS positions.
- Image georeferencing of a PNG from supplied ground-control points (GCPs).
This repository is a collection of runnable, configuration-by-editing scripts. It is not a Python package, command-line tool, or complete end-to-end sensor-model pipeline.
Coordinate Transformation/TransVect.py provides gps_to_ecef(lat, lon, alt).
- Accepts geodetic latitude and longitude in degrees and altitude in metres.
- Uses hard-coded WGS84 semi-major-axis and eccentricity constants.
- Returns Earth-centred, Earth-fixed (ECEF)
X,Y, andZcoordinates in metres. - Demonstrates the calculation for one satellite location and one ground-control-point location.
- Computes an ECEF translation vector by subtracting the GCP position from the satellite position.
Coordinate Transformation/RotMatrix.py contains the matrix construction for rotations about the X, Y, and Z axes and combines them as:
R = R_z @ R_y @ R_xThis represents a Z–Y–X (yaw, pitch, roll) composition. The script expects roll_angle, pitch_angle, and yaw_angle to be defined before it is run.
Coordinate Transformation/CoordTrans.py demonstrates the pinhole-camera projection:
image_homogeneous = K × [R | T] × world_homogeneous
pixel = image_homogeneous[:2] / image_homogeneous[2]
The script currently:
- Defines a 3×3 intrinsic camera matrix from focal lengths and principal-point offsets.
- Defines a calibrated 3×3 rotation matrix and 3-element translation vector.
- Builds the 3×4 extrinsic matrix
[R | T]. - Uses one point on a planar 25 mm checkerboard and prints its projected 2D image coordinate.
The calibration values and sample checkerboard point are embedded in the script; they are not estimated from images.
Georeferencing/Georefrencing_PNG_Full.py uses Rasterio and GeoPandas to associate image pixels with geographic coordinates.
- Accepts Rasterio
GroundControlPointobjects expressed as pixel row/column plus longitude/latitude. - Derives an affine transform from those GCPs using
rasterio.transform.from_gcps. - Uses EPSG:4326 as the coordinate reference system.
- Writes a GeoTIFF named
salt_flat_with_gcps.tiffinto a chosen output directory. - Converts non-zero raster regions into vector geometries and writes them as
salt_flat_with_gcps.geojson. - Includes four example GCPs and
Georeferencing/testdata.pngas a demonstration input.
Coordinate Transformation/
CoordTrans.py # fixed-parameter 3D-to-image projection example
RotMatrix.py # roll, pitch, yaw rotation-matrix construction
TransVect.py # WGS84 GPS-to-ECEF conversion and example translation
Georeferencing/
Georefrencing_PNG_Full.py # GCP-based PNG to GeoTIFF/GeoJSON workflow
testdata.png # example raster input
notebooks/notebook.ipynb # empty starter notebook
The project metadata targets Python 3.10 and Poetry:
poetry installThe coordinate-transformation scripts require NumPy. The georeferencing script also imports Rasterio and GeoPandas, which are used by the source but are not currently declared in pyproject.toml. Install them in the same environment before running that workflow:
poetry run pip install rasterio geopandasRun the coordinate examples from the repository root:
poetry run python "Coordinate Transformation/TransVect.py"
poetry run python "Coordinate Transformation/CoordTrans.py"Before running the rotation example, define numeric angles (in degrees) at the top of RotMatrix.py, for example:
roll_angle = 0.0
pitch_angle = 0.0
yaw_angle = 0.0Then run:
poetry run python "Coordinate Transformation/RotMatrix.py"For the supplied georeferencing example, run it from its directory because the script resolves testdata.png relative to the current working directory. Create the output directory first:
cd Georeferencing
mkdir -p output
poetry run python Georefrencing_PNG_Full.pyThis produces:
Georeferencing/output/salt_flat_with_gcps.tiff
Georeferencing/output/salt_flat_with_gcps.geojson
To georeference another image, update the input image path, output directory, and the GCP list in Georefrencing_PNG_Full.py. GCP longitude/latitude order and pixel coordinates must match the image being processed.
This example demonstrates georeferencing using an affine coordinate transformation. Given a set of GCPs, the transformation maps image pixel coordinates
Six GCPs are selected from identifiable features in the image whose geographic coordinates can be estimated using mapping software such as Google Maps. Rasterio uses the corresponding image and geographic coordinates to calculate an affine transformation, yielding the following equations:
The diagram below shows the six GCPs as circles and additional test points as triangles. The test points were not used to estimate the transformation parameters. Instead, they provide a visual check of how well the resulting transformation aligns other locations in the image with their corresponding geographic positions.
The repository does not currently provide:
- Automatic camera calibration or calibration-target detection.
- Estimation of intrinsic/extrinsic parameters from sensor data.
- A reusable sensor-model API, package entry point, or command-line interface.
- Automated tests for transformation or georeferencing behaviour.
- Validation of GCP quality, georeferencing accuracy, or output products.
- Orthorectification, terrain correction, image mosaicking, or satellite ephemeris/attitude ingestion.
- A complete satellite-image-to-map workflow.
The repository includes Poetry, pre-commit, linting, type-checking, and pytest configuration inherited from a Python project template. The executable functionality currently lives in the standalone scripts above.
This repository is released under the Unlicense.
