image manipulation with numpy
Project description
pierogis
image processing pipelines
pierogis is a framework for image processing.
Ingredients that describe image processing functions can be assembled
into recipes and executed.
pyrogis is a python library and cli tool implementing this framework.
pip install pyrogis
pyrogis chef input.png "sort; quantize"
features
- Lazy Rendering - Render a manipulation after constructing your pipeline
- Extendable - Easy to create custom manipulations
- CLI - Use the CLI to cook à la carte recipes, or provide a recipe in a document
- Numpy or Rust backend - Image processing functions use Numpy for (python relative) fast operations.
Some ingredients use compiled
Rustfor more speed.
install
install from a wheel with pip
pip install pyrogis
Depends on numpy and PIL. PIL requires some external C libraries for handling image files.
You probably don't have to worry about this. If you do, try a conda installation.
To build from source (either the repository or the sdist), you will need to install the rust stable toolchain and setuptools-rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
pip install setuptools-rust
python setup.py develop
# or
pip install .
usage
cli
pyrogis {recipe} {path} [-o output.png] [...recipe options]
The options for output file name and path are used for each menu item subcommand (sort, quantize, etc.).
A directory can be used for the path, in which case the program will try to cook each file in the directory.
An output can be provided as a directory and filenames will be the same as their input.
| arg | description | default | valid |
|---|---|---|---|
recipe |
menu item to cook | required |
sort, quantize, chef, threshold |
path |
path to input media | required |
dir, file |
-o,--output |
name of the output file | ./cooked |
str |
sort
sort pixels along an axis
pyrogis sort ./input.jpg -o output.png -l 50 -u 180 -t 1
| arg | description | default | valid |
|---|---|---|---|
-l, --lower-threshold |
pixels with intensity below this value serve as sort boundaries | 64 |
0-255 |
-u, --upper-threshold |
pixels with intensity above this value serve as sort boundaries | 180 |
0-255 |
-t, --turns |
number of clockwise turns from sorting bottom to top | 0 |
0-3 |
quantize
quantize an image to a smaller set of colors
pyrogis quantize ./input.jpg -o output.png -n 16 -r 3 -i 3
| arg | description | default | valid |
|---|---|---|---|
-n, --palette_size |
number of colors in the palette to cluster for | 8 |
int |
-r, --repeats |
number of times to repeat a temperature for DA | 1 |
int |
-i, --iterations |
number of times to repeat an iteration of a coarseness level | 1 |
int |
--initial_temp |
initial temp to use in DA for optimization | 1 |
float |
--final_temp |
final temp to use in DA for optimization | .001 |
float |
-d, --dithering_level |
relative dithering level (use .5-1.5) | .8 |
float |
(See more documentation on rscolorq)
chef
parse text for a recipe
txt files and quoted strings can describe a series of CLI recipes, piped from one to the next.
pyrogis chef ./input.jpg "sort -u 100; quantize" -o output.png
# or
pyrogis chef ./input.jpg recipe.txt -o output.png
recipe.txt
sort -u 100; quantize
| arg | description | default | valid |
|---|---|---|---|
| recipe | path to json or txt file to use as a recipe | recipe.txt |
str |
package
"pierogis is the name of the framework;
pyrogis is the name of the python package and cli tool"
- a wise man
from pyrogis import Pierogi, SpatialQuantize, Sort, Threshold, Dish, Recipe
A factory, called an Ingredient, has a prep method for receiving parameters,
and a cook method for operating on a numpy array to produce a programmatic output.
These two methods are usually called implicitly, prep on init and cook when rendering.
prep can be seen as parameterizing the manipulation while cook applies it (to an array).
pierogi
Pierogi is one of the simplest Ingredient types. It just loads its reference image.
pierogi = Pierogi(file="/Users/kyle/Desktop/image.jpg")
quantize
Quantize is another Ingredient.
When cooked, it will process an incoming numpy array and return an array
where every pixel has been quantized to the closest color in the palette.
Note how it is less static than a Pierogi, almost precooked.
When a pierogi is cooked, the "manipulation" that it applies
is just loading the picture on top.
Quantize, like many other Ingredient types, depends on a meaningful input
to cook to produce a meaningful output.
There is also the SpatialQuantize variant which is used for the cli tool.
palette = [
[0, 0, 0],
[127, 127, 127],
[255, 255, 255]
]
quantize = Quantize(palette=palette)
quantized_pixels = quantize.cook(pierogi.pixels)
This should produce a pixel for pixel quantized version of the input array.
As you can see above, an Ingredient has a pixels member.
This is the internal numpy pixel array of that Ingredient
with shape (width, height, 3).
Also consider how quantize.pixels doesn't really make sense compared to pierogi.pixels. This is related to the
relative "staticness" of Pierogi. More on that later.
Some other Ingredient types include: Threshold, Flip, and Rotate.
recipe
A typical flow allows you to create a pipeline of Ingredients
that sequentially apply their cook method on to
the previous array of pixels.
A pipeline in pierogis is called a Recipe. It is an Ingredient itself.
recipe = Recipe(ingredients=[pierogi, quantize])
recipe.cook()
recipe = Recipe(ingredients=[quantize])
recipe.cook(pierogi.pixels)
The two will produce the same result. But there's a better way.
dish
get to the point already - a wiser man
We could also use a Dish to serve this recipe. This is the recommended way to use Recipe.
dish = Dish(recipe=recipe)
ingredient = dish.serve()
The recipe gets cooked sequentially.
The output ingredient can be used like a pierogi now, precooked (with pixels member set).
The save and show methods of ingredient can be used as well.
seasoning
There is also a concept of seasonings
extending
If you want to create your own Ingredient type, you must subclass Ingredient and override the cook and prep
methods.
prep
Use prep to parameterize your manipulation.
This means any settings, constants, or inputs that configure the new functionality. Think about the palette used with
quantization.
def prep(self, brighten: int, scale: int, *args, **kwargs):
self.brighten = brighten
self.scale = scale
cook
Use cook to perform the manipulation.
This is the function that you are applying to each pixel. More specifically, this function has
a (width, height, 3) ndarray
and should return a 3d array that is also size 3 in the last dimension.
def cook(self, pixels: np.ndarray):
return (self.pixels + self.brighten) / self.scale
This function increases the r, g, and b of every pixel by self.brighten
then divides them each by self.scale.
Numpy operations can be pretty fast if you can keep them vectorized. This means try to avoid looping over the columns and rows of an array.
acknowledgements
The original python pixelsort package inspired this package. While the
underlying algorithm of that package and of sort in this one is
supposed to be functionally the same, details of the implementation differ, and it makes up just part of this package.
The quantizing algorithm used in this package is implemented by rscolorq, which
is a port of scolorq, itself an implementation
of Spatial Color Quantization.
changelog
v0.1.3
-
ingredients
- threshold default behavior change
- threshold now accepting exclude/include pixels as usize for windows support
-
chef
- menu items as separate classes from chef
-
package
- lots of formatting/lint fixes, notably subpackage imports
- documentation improvements
-
tests
- threshold tests added
v0.1.2
-
chef
- redo handling of input dir and unknown output name
- add quiet flag
-
documentation
- fix some typos in readme
v0.1.1
-
ingredients
- fix
Quantize.prepnot catching extra kwargs
- fix
-
documentation
- update readme to reflect changes in package name and quantize
-
deploy
- combine test pypi and normal pypi publish
v0.1.0
-
ingredients
Quantize(usingrscolorqor from palette)Sort(Numpy implementation)RecipeandDishquantize,sort, andchefCLI recipesThreshold(in both Numpy and Rust), andSeasoningFlipandRotate
-
deploy
- release on PyPi
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 pyrogis-0.1.3.tar.gz.
File metadata
- Download URL: pyrogis-0.1.3.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b393988f8fe7708773c6adc40849d753d5f8c6b761001f0d5f3fc968c2b6b61
|
|
| MD5 |
4243e06fc5cdc9b30b434cefce2646ac
|
|
| BLAKE2b-256 |
efc45ec233867ea517d2dd73e93f2db4c476504bc7e30a975748b570bd48cd62
|
File details
Details for the file pyrogis-0.1.3-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 218.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aad0c015d780f6bf2ebfd25347519934da024f52e58d56b3f6707c01a40b66bc
|
|
| MD5 |
609137904ac182fd9cf10538e9aadd58
|
|
| BLAKE2b-256 |
1976202c4e27a2a67cd8bb479095469815ade54f1c4c22ab41bf7dc0c67357af
|
File details
Details for the file pyrogis-0.1.3-cp39-cp39-win32.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp39-cp39-win32.whl
- Upload date:
- Size: 208.9 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a672adafd9ea387686e3001e0dad3efae11285101bfc0f65c6f300d639a9f70
|
|
| MD5 |
cb6b75fbee5fc980d80d1c856f31ab25
|
|
| BLAKE2b-256 |
b110e2cb99b555722d6e4c87bfa6e83aea26164e9a48ce05a41109e79fbb5dbd
|
File details
Details for the file pyrogis-0.1.3-cp39-cp39-manylinux2014_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55ee9116b860a3d7bdbafdffdc85a2fc4799ffc1a1f9e94aed970b005e6f5399
|
|
| MD5 |
33eb6dac5bc7919400c58119a7810e25
|
|
| BLAKE2b-256 |
3b4d887323227fad4b3b30a923bb42a4419fa964c673a6f94e845da8a620c27a
|
File details
Details for the file pyrogis-0.1.3-cp39-cp39-macosx_10_15_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 303.9 kB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ecaff6ad69c0f8f8454493ad59920ef1191071f8ae5924764a1dc3105321ade
|
|
| MD5 |
d2f33123fca938ba48481886d5691a88
|
|
| BLAKE2b-256 |
0643ae4f3b20a240d79c8fdde390c2eadc331800db6daac8210d485ec5b72558
|
File details
Details for the file pyrogis-0.1.3-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 218.7 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbc12e8d24c1993bedd615277376a713d2531e9df018ecac3dafed9f215ba503
|
|
| MD5 |
7f520b6efb1cc1e9272d71b216f8a935
|
|
| BLAKE2b-256 |
6c91d797e8a11937cb43e50199d00e78f5f99497d7bec4e37e65381c3aa19ca7
|
File details
Details for the file pyrogis-0.1.3-cp38-cp38-win32.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp38-cp38-win32.whl
- Upload date:
- Size: 209.2 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a75c7640b231f7d5cc2fa60c7b5cf117dc3e5de55da8dcce14d1f1a642d6f4db
|
|
| MD5 |
20d82463c72ec16541b0441c5a8eea39
|
|
| BLAKE2b-256 |
7a447acad61cc8c6c7314055fd5602a632db2c7f06447b3cb628b042aad95bd3
|
File details
Details for the file pyrogis-0.1.3-cp38-cp38-manylinux2014_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e1ca1d88bafc98b743b3c53b2181e4b39ac3e7d7c7d18d8f6943010ca9ec4f1
|
|
| MD5 |
720f0216200e385fb856a926a24e1108
|
|
| BLAKE2b-256 |
95b78f593cfe5fe4c948e53797f7dabc28cbfbbb3c0f2fe16e6a3f0aabf0b3fe
|
File details
Details for the file pyrogis-0.1.3-cp38-cp38-macosx_10_15_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 304.0 kB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39425dc4f9ac1819abf9e045e5a6e978f32fd684dfb355e0a4aba56cb8e41e55
|
|
| MD5 |
739acce87673dc1ea40680caac91ddb6
|
|
| BLAKE2b-256 |
38a615600e52454c4000993a54a14ea78c8f6455df2073d88a7267ae0a25a5ca
|
File details
Details for the file pyrogis-0.1.3-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 218.9 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8afaf045c3b5048b14784e77a52f749bfe5dd9c5dbf1f112d2410b83504a8e4
|
|
| MD5 |
d900ea021f1bd93858a8aa60e2e34413
|
|
| BLAKE2b-256 |
227061dcb63a3cf3e3da120b630ff259cb49d0f3addc3d5d58927e9c13bc9c4a
|
File details
Details for the file pyrogis-0.1.3-cp37-cp37m-win32.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp37-cp37m-win32.whl
- Upload date:
- Size: 209.4 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07b3983ac95aca5b0beeaa2a92fb7adc01251f884c79e4fe6afd12b20f3f1728
|
|
| MD5 |
d40f8fd9b37dc24235858ed8e3ab483e
|
|
| BLAKE2b-256 |
e91b3813a5e8e180fc74760b7d7e59e92f1b66416850888b0e447287024d9d8b
|
File details
Details for the file pyrogis-0.1.3-cp37-cp37m-manylinux2014_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa789791db8c9166c2742dddff62b17a0b75a31f817948ec43c63efa680d7fd1
|
|
| MD5 |
6b6c130909d9a7482976880a0e91bf8b
|
|
| BLAKE2b-256 |
1f6d21c41d3786d8b9d2b64b9bffc51546e5e4882662e36525654e68ca11b645
|
File details
Details for the file pyrogis-0.1.3-cp37-cp37m-macosx_10_15_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp37-cp37m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 304.0 kB
- Tags: CPython 3.7m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
941920ef499a3de4cf9ea8a8e416d0761f6b33c369f7da8d45747260ede51df9
|
|
| MD5 |
2aac2035daafa822f3fe677a805a35e9
|
|
| BLAKE2b-256 |
72474317f6ddf6c2797cfaad82137cc675f98a0c8ad4b6f5ad811c855f77cb0a
|
File details
Details for the file pyrogis-0.1.3-cp36-cp36m-win_amd64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 218.9 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4381c3e580db01adc5e0d85a31fc6422f5168596e0dba9acb479bfad19e4aeb9
|
|
| MD5 |
5a2bf0c746aab64985c30d0a7c31ebc0
|
|
| BLAKE2b-256 |
6556aa9522c0201a95010a5f5a475dd34cf35b7ad87e51e43036e7949e135a0c
|
File details
Details for the file pyrogis-0.1.3-cp36-cp36m-win32.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp36-cp36m-win32.whl
- Upload date:
- Size: 209.4 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42d7b5eb094b03fdcad370a40f2ecd27de35271b4e4facaaa79b447ac5762823
|
|
| MD5 |
fd9fe0d663433a6b9fb0eac54417b0eb
|
|
| BLAKE2b-256 |
ea9f68d4e096f49f6820b28c99556d352d9e177a75059f527362ea4a05251b92
|
File details
Details for the file pyrogis-0.1.3-cp36-cp36m-manylinux2014_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 983.3 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
600dc9edb7b31ae1b40128e760b15f134fcc22a054296b88ea46902d37665a84
|
|
| MD5 |
857e3201b94ce8b1b90392e336c429da
|
|
| BLAKE2b-256 |
bd8750b945f7eb23217499c707ef550e7922aa21c3f06b56df8c01201b32a538
|
File details
Details for the file pyrogis-0.1.3-cp36-cp36m-macosx_10_15_x86_64.whl.
File metadata
- Download URL: pyrogis-0.1.3-cp36-cp36m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 304.0 kB
- Tags: CPython 3.6m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95612ed4cb3882ddc6bd15dd2b3cd1b3f6c82c4574c7662a241695d0cfadd8de
|
|
| MD5 |
0076f09ade71ebe8b7d9e3d6d66747fd
|
|
| BLAKE2b-256 |
b61cffdf6a6f6a0fce02773b50b544001c7342bb2e791f9b5cb3137785c2da7c
|