All Projects → lucashadfield → Speck

lucashadfield / Speck

Licence: gpl-3.0
line art image renderer

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Speck

Quantum-Computing-Collection-Of-Resources
A Well Maintained Repository On Quantum Computing Resources [Code+Theory] Updated Regularly During My Time At IBM, Qubit x Qubit And The Coding School's Introduction To Quantum Computing Course '21
Stars: ✭ 183 (-44.71%)
Mutual labels:  matplotlib
Brokenaxes
Create matplotlib plots with broken axes
Stars: ✭ 266 (-19.64%)
Mutual labels:  matplotlib
Ai Learn
人工智能学习路线图,整理近200个实战案例与项目,免费提供配套教材,零基础入门,就业实战!包括:Python,数学,机器学习,数据分析,深度学习,计算机视觉,自然语言处理,PyTorch tensorflow machine-learning,deep-learning data-analysis data-mining mathematics data-science artificial-intelligence python tensorflow tensorflow2 caffe keras pytorch algorithm numpy pandas matplotlib seaborn nlp cv等热门领域
Stars: ✭ 4,387 (+1225.38%)
Mutual labels:  matplotlib
weekplot
Visualize your weekly schedule.
Stars: ✭ 40 (-87.92%)
Mutual labels:  matplotlib
Matplotlib Venn
Area-weighted venn-diagrams for Python/matplotlib
Stars: ✭ 260 (-21.45%)
Mutual labels:  matplotlib
Audio Spectrum Analyzer In Python
A series of Jupyter notebooks and python files which stream audio from a microphone using pyaudio, then processes it.
Stars: ✭ 273 (-17.52%)
Mutual labels:  matplotlib
The-Data-Visualization-Workshop
A New, Interactive Approach to Learning Data Visualization
Stars: ✭ 59 (-82.18%)
Mutual labels:  matplotlib
Joypy
Joyplots in Python with matplotlib & pandas 📈
Stars: ✭ 322 (-2.72%)
Mutual labels:  matplotlib
Geopython
Notebooks and libraries for spatial/geo Python explorations
Stars: ✭ 268 (-19.03%)
Mutual labels:  matplotlib
Yellowbrick
Visual analysis and diagnostic tools to facilitate machine learning model selection.
Stars: ✭ 3,439 (+938.97%)
Mutual labels:  matplotlib
python3-docker-devenv
Docker Start Guide with Python Development Environment
Stars: ✭ 13 (-96.07%)
Mutual labels:  matplotlib
psychrochart
A Python 3 library to make psychrometric charts and overlay information on them.
Stars: ✭ 57 (-82.78%)
Mutual labels:  matplotlib
Tensorflow Plot
📈 TensorFlow + Matplotlib as TF ops
Stars: ✭ 285 (-13.9%)
Mutual labels:  matplotlib
p3ui
C++ & Python User Interface Library
Stars: ✭ 21 (-93.66%)
Mutual labels:  matplotlib
Finger Detection And Tracking
Finger Detection and Tracking using OpenCV and Python
Stars: ✭ 317 (-4.23%)
Mutual labels:  matplotlib
nodeplotlib
NodeJS plotting library for JavaScript and TypeScript. On top of plotly.js. Inspired by matplotlib.
Stars: ✭ 115 (-65.26%)
Mutual labels:  matplotlib
Python web crawler da ml dl
python从最基础的语法历经网络基础、前端基础、后端基础和爬虫与数据基础走向机器学习
Stars: ✭ 272 (-17.82%)
Mutual labels:  matplotlib
Cheatsheets
Official Matplotlib cheat sheets
Stars: ✭ 5,749 (+1636.86%)
Mutual labels:  matplotlib
Python for data analysis 2nd chinese version
《利用Python进行数据分析·第2版》
Stars: ✭ 4,049 (+1123.26%)
Mutual labels:  matplotlib
Lantern
Data exploration glue
Stars: ✭ 292 (-11.78%)
Mutual labels:  matplotlib

speck

Python 3.6 Code style: black

Render images as a set of continuous lines representing each horizontal (or vertical) line of pixels:

  • Line weights vary with greyscale pixel darkness.
  • Set line weight range and clipping.
  • Add noise profiles to introduce randomness.
  • Add colour profiles to vary line colours.
  • Use ipywidget to tweak outputs interactively

Try it out

Note: This colab notebook contains the basic configuration options. For more advanced outputs, see "Other Examples" below.

Install

pip install git+https://github.com/lucashadfield/speck.git

Examples

Note: Large images can take a long time to process and might raise a MemoryError. This is because the image is scaled up substantially. The resize argument to SpeckPlot will scale down the image before processing. It supports both passing a tuple of dimensions and a single dimension int that the long edge will be scaled to and that maintains the original aspect ratio. I suggest starting with resize=100.
For example, an image resized to (100, 100) with upscale=10 (default) will be 1000x1000 pixels when saved.

Basic Example:

from speck import SpeckPlot, SineNoise, CmapColour

s = SpeckPlot.from_path(path='...', resize=100)

s.draw(
    weights=(0.2, 0.6),
    noise=SineNoise(scale=0.7),
    colour=CmapColour('Oranges')
)

s.save(path='...')

Example

Other Examples:

import speck
import numpy as np

s = speck.SpeckPlot.from_url('https://i.imgur.com/JLhMo6E.jpg', upscale=8)

# 1. Inverted weights and single line colour
s.draw(weights=(0.8, 0.1), noise=speck.SineNoise(scale=0.7), colour='#434343')
s.save('1.png')

# 2. No noise and alternating line colours
s.draw(weights=(0.4, 0.6), noise=None, colour=['#3b4252', '#d08770'])
s.save('2.png')

# 3. Extreme noise
s.draw(weights=(0.2, 0.8), noise=speck.SineNoise(scale=1.2), colour='#88c0d0')
s.save('3.png')

# 4. Equal noise on each line and custom colour gradient
s.draw(
    weights=(0.2, 0.8),
    noise=speck.SineNoise(
        scale=1.2, wave_count=1, freq_factor=(1, 1), phase_offset_range=(0, 0)
    ),
    colour=speck.GradientColour(['red', 'blue', 'black']),
)
s.save('4.png')

# 5. Skip every second line, and set background colour
s.draw(
    weights=(0.2, 0.8),
    noise=speck.SineNoise(scale=0.5),
    skip=1,
    background='#ebcb8b',
    colour='white',
)
s.save('5.png')

# 6. Colour each line based on its average greyscale value
s.draw(weights=(0.2, 0.8), colour=speck.GreyscaleMeanColour(s))
s.save('6.png')

# 7. Noise increasing along length of line
s.draw(
    weights=(0.1, 0.4),
    noise=speck.SineNoise(scale=list(np.linspace(0.5, 1.5, s.w * s.inter))),
    colour='#bf616a',
)
s.save('7.png')

# 8 .Vertical lines
s = speck.SpeckPlot.from_url('https://i.imgur.com/JLhMo6E.jpg', upscale=8, horizontal=False)
s.draw(weights=(0.1, 0.8), noise=speck.SineNoise(scale=0.7), colour='#434343')
s.save('8.png')

# 9. first 10 lines are 1 unit thick, next 10 are 2 units thick, last 10 are 3 units thick
s = speck.SpeckPlot.from_url('https://i.imgur.com/JLhMo6E.jpg', upscale=8)
thicknesses = [1] * 10 + [2] * 10 + [3] * 10
s.draw(
    weights=(0.3, 1),
    modifiers=[speck.LineUnionModifier(thicknesses)],
    colour=speck.CmapColour('GnBu'),
)
s.save('9.png')

Other Examples

Interactive Widget

# ipywidget that runs in jupyter notebook
from speck import SpeckPlot, SpeckWidget
s = SpeckPlot.from_path('...', resize=(60, 56), upscale=5)
SpeckWidget(s).interact()

ipywdiget

Configuration Parameters

Constructor options: Can be passed to the constructors: SpeckPlot, SpeckPlot.from_path and SpeckPlot.from_url

  • upscale: the pixel scaling factor, each input pixel maps to upscale output pixels (default: 10)
  • resize: dimensions to resize to or a single value to set the long edge to and keep the input aspect ratio (default: None)
  • horizontal: use horizontal lines to render the image (default: True)

Basic options: Output is configured based on the arguments passed to the draw method of SpeckPlot

  • weights: min and max line widths

      eg. weights = (0.2, 0.9) =
          0.2 units of line weight mapped from <= min weight clipping 
              (if weight_clipping is (0, 1), white is 0.2 units thick)
          0.9 units of line weight mapped from >= max weight clipping 
              (if weight_clipping is (0, 1), black is 0.9 units thick)
    
  • weight_clipping: proportion of greys that map to min and max weights.

      eg. weight_clipping = (0.1, 0.8) =
          <=10% grey maps to min weight
          >=80% grey maps to max weight
    
  • noise: Noise object that is called and added onto thickness values (see below)

  • colour: colour or list of colours or Colour object that is called and applied to lines (see below)

  • skip: number of lines of pixels to skip for each plotted line

  • background: background colour of output plot

  • modifiers: list of Modifier objects that are iteratively applied to the output x, y, noise and colour data (see below)

  • seed: random seed value

  • ax: optional Axis object to plot on to

Colour Profile options:

  • GradientColour: Colours each line according to a generated colour between the provided checkpoint colours.
  • CmapColour: Colours each line according to pre-defined matplotlib cmap.
  • KMeansColour: Clusters each horizontal line of pixel colour values into k groups using k-means to determine the dominant colour of that row, and then sets the line colour to that.
  • GreyscaleMeanColour: Takes the mean greyscale colour of each row of pixels and makes the line that colour.
  • Create your own by inheriting from Colour.

Noise Profile options:
Each noise profile can be created with profile='parallel', profile='reflect' or profile='independent' which either applies the same noise on either edge of each line, the opposite noise on each edge of each line or independent random noise on each edge of each line, respectively.

  • SineNoise: Random smooth noise based on the product of multiple random sine waves.
  • RandomNoise: Random static noise with some averaging. (slow)
  • Create your own by inheriting from Noise.

Modifier Profile options:

  • LineUnionModifier: Combines multiple rendered lines together to allow for building more complex line weight profiles.
  • Create your own by inheriting from Modifier

Other SpeckPlot methods:

  • .set_k(k=10): sets the logistic growth rate on pixel boundaries. Higher k will result in steeper boundaries. Set to 10 by default. (see https://en.wikipedia.org/wiki/Logistic_function)
  • .cache_clear(): clears the lru_cache of x, y and noise data.

Tests

Run all tests. Tests generate output images and compare them to tests/baselines/*. From speck directory, run:

python -m pytest tests --mpl

To generate new baseline images:

python -m pytest tests --mpl-generate-path=baseline_temp

All tests will be skipped. This will instead generate test images into a newly created baseline_temp directory. Copy images from there to baseline to add them to the test suite.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].