Git Product home page Git Product logo

halftone's Introduction

Halftone

This is a very simple python program that uses open cv to generate images using the halftone technique.

(If you like this repo, you may also like this one)

Command line usage

Put the source image in the same directory as halftone.py and call it like so:

python3 halftone.py woman.jpg

command-line-usage

You can also learn about the optional arguments, doing so: python3 halftone.py -h

Calling from another module

import halftone

halftone.halftone("woman.jpg")

Learn more about the methods' signature and behaviour with python3 -m pydoc halftone

Optional arguments

Side

The generated image is composed of squares with dots in them. This optional argument specifies how big each of these squares can be.

As you can see from the generated images below, when all other parameters are constant, as you increase size the image becomes more smooth (because each individual dot gets smoother). (below each output image is its corresponding size and dimensions)

side-variation

If you set side = 1, you won't get very good results (because each square will effectively be just one pixel).

If you set side = 2 each square will be 2 pixels wide and although you probably won't get a very clear image, you get a cool looking texture if you zoom in enough.

Values of side that are too large create big images that may take a while to generate.

The default side value is 20 pixels because from my experience playing with this variable, 20 gives you a nice equilibrium between image size and image smoothness.

Jump

The generated image is created from an input image which is scanned left to right, top to bottom. Instead of scanning the image pixel by pixel, the image is scanned in blocks, i.e. squares that are jump pixels wide. Each of these blocks will be converted into a dot in the output image.

As you can see from the images below, when all other parameters are constant, as you increase jump the image becomes less clear because bigger blocks are being condensed to the same space (size is constant). (below each output image is its corresponding jump and dimensions)

jump-variation

The higher the value of jump, the lower the number of dots in the output image will be (in fact, if you set this value high enough, the output picture will be a single dot).

If you set jump = 1, you're forcing the program to create a dot for each pixel in the original image (!) which will take forever and generate huge output images.

Colors

bg_color sets the background color of the output image.

fg_color sets the foreground color of the output image, i.e. the color of the dots.

Below are some examples of what you can achieve playing with these values.

colors

I recommend using a light color for the background and a dark color for the foreground; otherwise the image will look... weird. That's why the default color for bg_color is white, and default color for fg_color is black.

If you are calling the program using the command line interface, you have to specify the color like so: python3 halftone.py woman.jpg -fg '(255,0,0)' (using '' to delimit the rgb value).

If you are calling the program from another module, this optional argument is a tuple, so you specify it like so: halftone.halftone("woman.jpg", fg_color = (255,0,0)).

Alpha

Each dot is drawn in a side pixels wide square. If alpha = 1, each dot's radius will never be greater than side (i.e. at most, the dots are inscribed in their squares). When the dots' size is limited like this, the output image can look a bit faded, as you can see from the images below.

(below each output image is its corresponding alpha; the dimensions were omitted because changing alpha doesn't affect the image size)

alpha-variation

If you set alpha = 0, the output image will have no dots (their radius will all be 0).

Original image credits

The photo I've been using is called Woman in White Robe Smiling and you can see the original version here. Check out this photo's original photographer here.

License

This program is licensed under the MIT License - see the LICENSE file for details.

halftone's People

Contributors

gravo8 avatar

Stargazers

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

Watchers

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