Code Monkey home page Code Monkey logo

imgen's Introduction

imgen

Personal playground for generating images in a functional style in Python. Not made to be fast...

Currently supports

  • Loading images
  • Convolution operations (blurs, sharpening, edge detection)
  • Masks
  • Radial gradients
  • Thresholding
  • Layering
  • Conversion to greyscale
  • Inverting images
  • ...and Stripes

Getting Started

Install Pillow

python3.7 -m pip install Pillow

Code Example

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:

Example Images

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.

Original

Edge Detection

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)

Sharpen

From demo_sharpen.py

Gaussian Blur

From demo_gaussian_blur.py

Mask

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")

Invert

From demo_inverse.py

Note on Coding Style

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)

TODO

  • 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.)

imgen's People

Stargazers

iairose avatar

Watchers

James Cloos avatar iairose avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.