Pixel Rearrangement Tool — Keyboard-Navigated Terminal UI
Project description
Pixelification
A terminal tool that rearranges pixels from a source image to approximate a target image using optimal transport via color sorting — then animates each pixel physically sliding to its new position.
No new pixels are created. Every pixel in the output comes from the source image, just rearranged.
How it works
flowchart LR
A[Source Image] --> C[Color sort<br/>lexsort by<br/>lum→hue→sat]
B[Target Image] --> D[Color sort<br/>lexsort by<br/>lum→hue→sat]
C --> E["s_order[i]"]
D --> F["t_order[i]"]
E --> G["forward[s_order] = t_order"]
F --> G
G --> H[Per-pixel<br/>position lerp]
H --> I[Scatter render<br/>np.add.at]
I --> J[60 frames<br/>slide animation]
-
Sort by colour — every pixel in both images is sorted by luminance, then hue, then saturation. The darkest source pixel gets rank 0, the lightest gets rank N−1. Same for the target.
-
Map by rank — a source pixel with rank i maps to the target position with rank i. This is the optimal transport: the ith darkest pixel in the source ends up where the ith darkest pixel was in the target.
Source pixels (sorted) Target positions (sorted)
┌─────────────────────┐ ┌─────────────────────┐
│ rank 0 (darkest) │──────→│ rank 0 │
│ rank 1 │──────→│ rank 1 │
│ rank 2 │──────→│ rank 2 │
│ ... │ │ ... │
│ rank N−1 (lightest)│──────→│ rank N−1 │
└─────────────────────┘ └─────────────────────┘
- Animate — each pixel slides from its original position to its mapped position over 60 frames using linear interpolation. All pixels move simultaneously. When multiple pixels land on the same display cell, their colours are averaged.
Frame 0 Frame 30 Frame 60
┌────────┐ ┌────────┐ ┌────────┐
│• • │ │ •• │ │ •• │
│ •• │ ───────→ │ • •• │ ───────→ │ •• │
│ • • │ lerp │ • • │ lerp │ • • │
└────────┘ └────────┘ └────────┘
source positions midway target positions
Usage
python rearrange_pixels_tui.py
A keyboard-navigated terminal interface opens. Use arrow keys to select images, press Enter to run.
↑↓ navigate • Enter select • 1-4 shortcut • q quit
An OpenCV window opens with three panels:
| Source | Target | Reconstruction |
|---|---|---|
| Your image | Layout to approximate | Pixels sliding into place |
Press ESC or q during the animation to quit.
Requirements
- Python 3.10+
- OpenCV (
cv2) - NumPy
prompt_toolkit
pip install opencv-python numpy prompt_toolkit
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pixelification-0.1.0.tar.gz.
File metadata
- Download URL: pixelification-0.1.0.tar.gz
- Upload date:
- Size: 43.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5fece9ea8b9cfb54f4e88d198dccfe65de54c5b12d0ad5c7d5082df6e2f5da8
|
|
| MD5 |
6b888c6193da36c8b9cc492425f95932
|
|
| BLAKE2b-256 |
3eefdb529373a35d2511e45b59317aae661f5aac608e2a1e26b6802eddad8e24
|
File details
Details for the file pixelification-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pixelification-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b7def591e026abec8e3f492394d7f629ecab711de9acb7bca104b864361c67a
|
|
| MD5 |
2d6279db51dcc3c96261ddb9a5514fcd
|
|
| BLAKE2b-256 |
c8aa3e3505bac60c3313dcc1a99a9201db1f1ecc2817ae405732f0ac898b1611
|