Skip to main content

Creates random images

Project description

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.

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

randimage-1.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

randimage-1.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file randimage-1.2.tar.gz.

File metadata

  • Download URL: randimage-1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for randimage-1.2.tar.gz
Algorithm Hash digest
SHA256 2bf72ea0aaf3274fbe1057c8be0da199c892fd684f49375f740baf16cb2afa1b
MD5 1342593d02023278ecec519d2de179a0
BLAKE2b-256 7a85d9fca69c66ce0f1ec6ce1cd3efee3033c26e92837225de1f0ea661f40bf6

See more details on using hashes here.

File details

Details for the file randimage-1.2-py3-none-any.whl.

File metadata

  • Download URL: randimage-1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for randimage-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1b080d4cbbdec5feba5711bc530f67e8b5bd595911914dda73ca4b0d0715a6b
MD5 91515aa30a175347a9dc1f1c509e27bb
BLAKE2b-256 049d41022cfa3a7cf7766c3cc45b8a86167c9317030908c8eb843de214838b10

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page