Git Product home page Git Product logo

imcmc's Introduction

imcmc

Build Status Coverage Status

It probably makes art.

imcmc (im-sea-em-sea) is a small library for turning 2d images into probability distributions and then sampling from them to create images and gifs. Right now it is best at logos and shape based images.

Installation

This is actually pip installable from git!

pip install git+https://github.com/ColCarroll/imcmc

Quickstart for logos and gifs

See imcmc.ipynb for a few working examples as well.

import imcmc


image = imcmc.load_image('python.png', 'L')

# This call is random -- rerun adjusting parameters until the image looks good
trace = imcmc.sample_grayscale(image, samples=1000, tune=500, nchains=6)

# Lots of plotting options!
imcmc.plot_multitrace(trace, image, marker='o', markersize=10,
                      colors=['#0000FF', '#FFFF00'], alpha=0.9);

# Save as a gif, with the same arguments as above, plus some more
imcmc.make_gif(trace, image, dpi=40, marker='o', markersize=10,
               colors=['#0000FF', '#FFFF00'], alpha=0.9,
               filename='example.gif')

Python

Quickstart for color images

See crosshatch.ipynb for a few working examples as well.

import matplotlib.pyplot as plt

from imcmc.color import (
    ImageLines,
    IntensityMCMCStrategy,
    UniformLinesStrategy,
    GibbsIntensityStrategy
)

pete = plt.imread('color/pete2.jpg')

ImageLines(pete, UniformStrategy()).plot()

pete

munchen = plt.imread('color/munchen.jpg')

ImageLines(munchen, IntensityMCMCStrategy(step_size=500)).plot(10_000)

munchen

beach = plt.imread('color/beach.jpg')

ImageLines(beach, UniformLinesStrategy()).plot(1500, linewidth=1)

beach

karwendel = plt.imread('color/karwendel.jpg')

ImageLines(karwendel, GibbsIntensityStrategy()).plot(1_000)

karwendel

Built with

Pillow does not have a logo, but the other tools do!

PyMC3

matplotlib

scipy

Python

Here's a tricky one whose support I appreciate

I get to do lots of open source work for The Center for Civic Media at MIT. Even better, they have a super multi-modal logo that I needed to use 98 chains to sample from!

Center for Civic Media

imcmc's People

Contributors

canyon289 avatar colcarroll avatar ericmjl avatar tgy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imcmc's Issues

Example code may be missing `if __name__ == '__main__'`

I stumbled upon a multiprocessing error when trying to run the example code and one of the warnings mentioned that could be because there was no if preventing the entry point code to run again and again after a fork.

Wrapping the example code around an if __name__ == '__main__' did the trick.

By the way, this is a very nice project. Thanks for sharing

Not working on my local notebook

Code:

import imcmc
image = imcmc.load_image('my_logo_blk.png', 'L')
trace = imcmc.sample_grayscale(image)

Output:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-1ad864fbcc0c> in <module>()
      4 image = imcmc.load_image('novartis_logo_pos_blk.png', 'L')
      5 
----> 6 trace = imcmc.sample_grayscale(image)

~/github/software/imcmc/imcmc/imcmc.py in sample_grayscale(image, samples, tune, nchains, threshold)
    114                           tune=tune,
    115                           chains=nchains, step=pm.Metropolis(),
--> 116                           start=[{'image': x} for x in start],
    117                          )
    118     return trace

~/anaconda/envs/imcmc/lib/python3.6/site-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain, njobs, tune, nuts_kwargs, step_kwargs, progressbar, model, random_seed, live_plot, discard_tuned_samples, live_plot_kwargs, **kwargs)
    283     discard = tune if discard_tuned_samples else 0
    284 
--> 285     return sample_func(**sample_args)[discard:]
    286 
    287 

~/anaconda/envs/imcmc/lib/python3.6/site-packages/pymc3/sampling.py in _sample(draws, step, start, trace, chain, tune, progressbar, model, random_seed, live_plot, live_plot_kwargs, **kwargs)
    330     try:
    331         strace = None
--> 332         for it, strace in enumerate(sampling):
    333             if live_plot:
    334                 if live_plot_kwargs is None:

~/anaconda/envs/imcmc/lib/python3.6/site-packages/tqdm/_tqdm.py in __iter__(self)
    951 """, fp_write=getattr(self.fp, 'write', sys.stderr.write))
    952 
--> 953             for obj in iterable:
    954                 yield obj
    955                 # Update and possibly print the progressbar.

~/anaconda/envs/imcmc/lib/python3.6/site-packages/pymc3/sampling.py in _iter_sample(draws, step, start, trace, chain, tune, model, random_seed)
    409         update_start_vals(start, strace.point(-1), model)
    410     else:
--> 411         update_start_vals(start, model.test_point, model)
    412 
    413     try:

~/anaconda/envs/imcmc/lib/python3.6/site-packages/pymc3/util.py in update_start_vals(a, b, model)
    143                             a[name], point=b).eval()
    144 
--> 145     a.update({k: v for k, v in b.items() if k not in a})
    146 
    147 

AttributeError: 'list' object has no attribute 'update'

Problem with pymc3 3.3

The last days I have been playing with pymc3, and found this error:
pymc-devs/pymc#3068

I had to install the latest version available in their repo to solve the issue (it's 3.4.1 available in master).

When I installed your package, pip installed pymc3 3.3 as required in requirements.txt. So my pymc3 was downgraded. When I run your getting started example, I got the error above again.

I have upgraded pymc3 again to the bleeding edge version, and I could run your example.

My suggestion is that you update the requirements.txt.

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.