Skip to main content

randimage - create random images in python

randimage example

This package comes out of frustration: I could not find a simple way to generate random profile pictures for users of my app riffandmatch.

Now it's as simple as

from randimage import get_random_image, show_array
img_size = (128,128)
img = get_random_image(img_size)  #returns numpy array
show_array(img) #shows the image

To save the image you can use matplotlib:

import matplotlib
matplotlib.image.imsave("randimage.png", img)

In examples.py you can find slightly more detailed code showing for example how to manually choose and combine the masks and path finding procedures.

Installation

pip install randimage

How it works

You can read this post on my blog for a full explanation of how the procedure works.

The basic idea is to generate a random region-filling path for the image, then pick a colormap from matplotlib and use it to progressively color the pixels in the image as ordered by the path.

To generate the path we start from a random gray-valued mask (of which you can find several examples in masks.py) of the same size of the final image and apply to it either the EPWT (Easy Path Wavelet Transform) [1] path-finding procedure or a novel probabilistic path finding.

In both cases the starting point is chosen randomly and for each point a neigborhood is considered, which does not include points that are already part of the path. For the EPWT, each subsequent point in the path is chosen in this neighborhood as the one whose gray value is closest in absolute value to the current point. For the probabilistic path instead, a random point in the neighborhood is chosen using the gray values as probability weights.

In the future I would like to try and use the path finding procedure of the RBEPWT (Region Based Easy Path Wavelet Transform) [2] and experiment with rule-based cellular automata to construct paths with greater self-similarity.

[1] Gerlind Plonka. The easy path wavelet transform: A new adaptive wavelet transform for sparse representation of two-dimensional data. Multiscale Modeling & Simulation, 7(3):1474–1496, 2008.

[2] Budinich, R. (2017). A region-based easy-path wavelet transform for sparse image representation. International Journal of Wavelets, Multiresolution and Information Processing, 15(05), 1750045.

Metadata

Release files for randimage 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for randimage 1.2
File Size Uploaded
randimage-1.2.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for randimage 1.2
File Interpreter ABI Platform
randimage-1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / randimage-1.2.tar.gz

Download URL randimage-1.2.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2bf72ea0aaf3274fbe1057c8be0da199c892fd684f49375f740baf16cb2afa1b
BLAKE2b-256 checksum
How to use checksums
7a85d9fca69c66ce0f1ec6ce1cd3efee3033c26e92837225de1f0ea661f40bf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release files / randimage-1.2-py3-none-any.whl

Download URL randimage-1.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1b080d4cbbdec5feba5711bc530f67e8b5bd595911914dda73ca4b0d0715a6b
BLAKE2b-256 checksum
How to use checksums
049d41022cfa3a7cf7766c3cc45b8a86167c9317030908c8eb843de214838b10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page