Created
August 4, 2025 13:28
-
-
Save zabop/80994d1dcb381e36a587cb9aa278a16c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "e29a24bd", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Input file size is 4, 5\n", | |
| "0...10...20...30...40...50...60...70...80...90...100 - done.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "from PIL import Image\n", | |
| "import numpy as np\n", | |
| "\n", | |
| "arr = np.array([\n", | |
| " [1, 0.2, 0, 1],\n", | |
| " [0.2, 0.4, 0.6, 0.4], \n", | |
| " [0.4, 0.6, 0.8, 0.8], \n", | |
| " [0.6, 0.8, 0.6, 0.4], \n", | |
| " [0.8, 0.6, 1, 1], \n", | |
| " ])\n", | |
| "arr *= 255\n", | |
| "\n", | |
| "im = Image.fromarray(arr.astype(np.uint8))\n", | |
| "im.save(\"example.png\", format=\"PNG\", compress_level=0)\n", | |
| "\n", | |
| "ulx, uly = 935764.3,6668575.4\n", | |
| "\n", | |
| "pixelsize = 250\n", | |
| "lrx, lry = ulx + pixelsize * arr.shape[1], uly - pixelsize * arr.shape[0]\n", | |
| "\n", | |
| "!rm -f georeferenced_mock_small.tif\n", | |
| "!gdal_translate \\\n", | |
| " -a_srs EPSG:25831 \\\n", | |
| " -a_ullr {ulx} {uly} {lrx} {lry} \\\n", | |
| " -a_nodata 255 \\\n", | |
| " \"example.png\" \"example.tif\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "1ab468e8", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "!open ." | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "venv (3.13.2)", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.13.2" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment