Code Monkey home page Code Monkey logo

magic-texture's Introduction

magic-texture

Generates psychedelic color textures in the spirit of Blender's magic texture shader using Python/Numpy.

Usage

The above plot is generated by

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid

import magictex as mtex


def main():
    rng = np.random.default_rng(seed=123)
    fig = plt.figure(figsize=(12, 9))
    grid = ImageGrid(fig, 111, nrows_ncols=(3, 4), axes_pad=0.1)

    # Create canonical coordinates for 1024x1024 image
    coords = mtex.coordinate_grid((1024, 1024))
    for ax in grid:
        # Transform coordinates, distort and generate texture
        tex = mtex.magic(
            mtex.random_transform(coords, rng),
            depth=rng.integers(1, 5),
            distortion=rng.uniform(2, 3),
            rng=rng,
        )
        # Plot
        ax.get_yaxis().set_ticks([])
        ax.get_xaxis().set_ticks([])
        ax.imshow(tex)
    plt.show()

if __name__ == "__main__":
    main()

Tip for best performance generate coordinates once and reuse them for multiple textures.

Install

pip install git+https://github.com/cheind/magic-texture

Why?

In domain randomization, many aspects controlling the visual scene appearance are massively randomized to synthesize training data for deep learning models. In this respect, magic textures have served us quite well in the recent past (blendtorch2020).

Benchmark

For different image sizes with depth=3

(256, 256): coords 0.001 sec/image, magic 0.006 sec/image
(512, 512): coords 0.002 sec/image, magic 0.028 sec/image
(1024, 1024): coords 0.007 sec/image, magic 0.112 sec/image
(2048, 2048): coords 0.029 sec/image, magic 0.450 sec/image

See benchmark.py for details.

References

@inproceedings{blendtorch2020,
    author = {Christoph Heindl, Lukas Brunner, Sebastian Zambal and Josef Scharinger},
    title = {BlendTorch: A Real-Time, Adaptive Domain Randomization Library},
    booktitle = {
        1st Workshop on Industrial Machine Learning 
        at International Conference on Pattern Recognition (ICPR2020)
    },
    year = {2020},
}

magic-texture's People

Contributors

cheind avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  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.