Metadata-Version: 2.4
Name: pixelsort-cli
Version: 1.0.1
Summary: A Python CLI tool for sorting pixels in images.
Author-email: Ferdinand Theil <f.p.theil@proton.me>
License: MIT License
        
        Copyright (c) 2023 Ferdinand Theil
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/Blotz/pixelsort-cli
Project-URL: Bug Tracker, https://github.com/Blotz/pixelsort-cli/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: opencv-python
Requires-Dist: filetype
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# pixelsort cli

[![tests](https://github.com/Blotz/pixelsort-cli/actions/workflows/python-package.yml/badge.svg)](https://github.com/Blotz/pixelsort-cli/actions/workflows/python-package.yml)
[![package](https://github.com/Blotz/pixelsort-cli/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Blotz/pixelsort-cli/actions/workflows/python-publish.yml)
[![CodeQL](https://github.com/Blotz/pixelsort-cli/actions/workflows/codeql.yml/badge.svg)](https://github.com/Blotz/pixelsort-cli/actions/workflows/codeql.yml)

A simple python command line tool for sort pixels in an image.
Based on the works of [Kim Asendorf](https://github.com/kimasendorf/ASDFPixelSort).

The script blocks pixels into dark and light areas using a contrast mask.
Then it sorts the pixels in a given direction via their luminance.

- You can increase/decrease the contrast by setting the threshold.
- You can also invert the mask to sort the light pixels instead of the dark ones.

## Usage

### Install

```bash
pip install git+https://github.com/Blotz/pixelsort-cli
```

or

```bash
pip install pixelsort-cli
```

## Examples

```bash
pixelsort --help
```

```bash
usage: pixelsort [-h] [--angle ANGLE] [--image_path IMAGE_PATH] [--threshold THRESHOLD | --template_path TEMPLATE_PATH]
                 [--sort_brightest SORT_BRIGHTEST] [--reverse_sorting REVERSE_SORTING] [--output OUTPUT] [--verbose | --quiet]
                 [stdin]

Command line tool for sorting pixels in images

positional arguments:
  stdin

options:
  -h, --help            show this help message and exit
  --angle ANGLE         angle that the image is sorted. 0° is up. [0, 360]
  --image_path IMAGE_PATH
                        path to image
  --threshold THRESHOLD
                        threshold for contrast. [-1.0, 1.0] Default: 1.0
  --template_path TEMPLATE_PATH
                        path to template image
  --sort_brightest SORT_BRIGHTEST
                        Sort the brightest area of the image. Default: True
  --reverse_sorting REVERSE_SORTING
                        Sorts the pixels from lightest to darkest instead of darkest to lightest. Default: False
  --output OUTPUT       path to output file
  --verbose             print debug messages
  --quiet               print less messages
```

```bash
pixelsort --image_path data/mountains.jpg --threshold 1.2 | display
```

![example 1](https://raw.githubusercontent.com/Blotz/pixelsort-cli/main/data/example1.png)

```bash
cat data/mountains.jpg | pixelsort --template_path data/pyramid_mask.png | display
```

![example 2](https://raw.githubusercontent.com/Blotz/pixelsort-cli/main/data/example2.png)

```bash
pixelsort --image_path data/mountains.jpg --angle 30 --threshold 1.2 --output example.png
```

![example 3](https://raw.githubusercontent.com/Blotz/pixelsort-cli/main/data/example3.png)

Use it with other tools like imagemagick
```bash
magick data/mountains.jpg -colorspace gray PNG:- | pixelsort | display
```

![example 4](https://raw.githubusercontent.com/Blotz/pixelsort-cli/main/data/example4.png)


---

## License

MIT Ferdinand Theil
