Personal playground for generating images in a functional style in Python. Not made to be fast...
- Loading images
- Convolution operations (blurs, sharpening, edge detection)
- Masks
- Radial gradients
- Thresholding
- Layering
- Conversion to greyscale
- Inverting images
- ...and Stripes
Install Pillow
python3.7 -m pip install Pillow
The following code snippet from demo_wallpaper_small.py
:
genImage(layer(constant(10, 10, 10, 255),
mask(radialGradient(240, 135, 160,
(60, 60, 60, 255),
(20, 20, 20, 255)),
pinStripe(1, 15, (255,255,255,255), (0,0,0,0)))),
480, 270, "out/wallpaper_small.png")
Outputs:
More examples can be found in this directory. All examples can be generated using demo.py
. Some of these demos can take a long time to execute.
From demo_edge_detect.py
def detectEdges(inputFile, outputFile):
width, height = Image.open(inputFile).size
genImage(conv(tex(inputFile, "RGB"), [[0, 1,0],
[1,-4,1],
[0, 1,0]]),
width, height, outputFile)
From demo_sharpen.py
From demo_gaussian_blur.py
From demo_mask.py
# Since shapes like circles aren't supported yet, we have to create them
# mathemagically by thresholding a radial gradient
circleMask = thresh(radialGradient(256, 256, 200, (255,255,255),
(0,0,0)),
(1,1,1), pos=(255,255,255,255), neg=(255,255,255,0))
genImage(layer(tex("ref/boat.png", mode="RGBA"),
mask(tex("ref/baboon.png", mode="RGBA"),
circleMask)),
512, 512, "out/mask2.png", mode="RGB")
From demo_inverse.py
Split lines follow the practice of indenting up to the start of the enclosing brace. This is similar in style to what I've seen in lisp. Spaces are absent in tuples containing only 0's and 255's since they add to visual noise - attention doesn't need to be drawn to (255,255,255,255)
- 3D transformations
- Rotation
- Scaling
- Interpolation of images when transformed
- Converting existing function to better accept floating point arguments
- Change color scale from 0-255 to 0.0-1.0
- Less hardcoding of transparency (IE make the alpha channel not an edge case)
- GIF output
- Polygons / Contours / Other Shapes
- Lines
- Linear Gradient
- More primitive functions (multiplication, subtraction, etc.)