linepix

package module
v0.0.0-...-2281e01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2021 License: MIT Imports: 10 Imported by: 0

README

linepix

Create artistic images using only straight lines

Linepix creates stylized drawings from images by using only straight lines that cross the whole image. Each line touches two different edges of the image. It can also create a video of the image generation process.

Linepix is written in Go. For image generation it doesn't have any dependencies. However, to generate video of the process ffmpeg must be installed.

Demo Gif

Installation

go get github.com/hbostann/linepix

Examples

Simple
# Use default values
linepix -i input.jpg -o output.png
Change size
# Make output's width 1024px, aspect ratio is preserved
linepix -i input.jpg -o output.png -w 1024

# Make output's height 600px, aspect ratio is preserved
linepix -i input.png -o output.png -h 600

# Don't resize output. Make it same size as input
linepix -i input.jpg -o output.png -w 0 -h 0
Custom line count
# Draw 7000 lines on the output image.
linepix -i input.png -o output.png -w 1024 -l 7000

# Draw ~3x7000 lines on the output image (since it's color).
linepix -i input.jpg -o output.png -w 1024 -l 7000 --color
Generate video
# Draw 10000 lines on the output image and generate a video
# with 2000 fps and freeze the last frame for 5 seconds.
# Resulting video length will be NumberOfLines/fps + freeze time
# 10000/2000 + 5 = 10 seconds of video will be generated.
linepix -i input.jpg -o output.png -l 10000 -v -f 2000 -s 5

For more detail use the --help flag.

How does it work?

Linepix, first finds the darkest pixel in the image. Then it generates lines that go through the darkes pixel with random slopes. It computes the average pixel value along each line and selects the line with the darkest value to be drawn. The value of the selected line is subtracted from the image. After the selected line is drawn on the output image whole process is repeated until the given number of lines are drawn. This process is performed on the grayscale version of the image if the output is not a color image. For color images the input is split into red, green, blue channels and each channel is treated as a grayscale image. Number of lines to draw on each channel is also adjusted by the intensities of each channel. Thus, nearly 3x more lines are drawn on color images.

License

The MIT License (MIT) - see LICENSE for more details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateChannelRatios

func CalculateChannelRatios(redLum, greenLum, blueLum uint64, length int) (float64, float64, float64)

func DrawLine

func DrawLine(img image.Image, line Line, color bool)

func GenerateLines

func GenerateLines(img *image.Gray, lineCount, precision, lineWeight int, channel ColorChannel, out chan Line)

func MakeGrayscale

func MakeGrayscale(img image.Image) *image.Gray

func MakeRGBA

func MakeRGBA(img image.Image) *image.RGBA

func ReadImage

func ReadImage(imageName string) image.Image

func ResizeImage

func ResizeImage(img image.Image, width, height uint) image.Image

func SaveImage

func SaveImage(fileName string, img image.Image) error

func SetupFFMPEG

func SetupFFMPEG(output string, width, height, fps, freeze int) (*exec.Cmd, io.WriteCloser, error)

func SplitImage

func SplitImage(img *image.RGBA) (*image.Gray, *image.Gray, *image.Gray)

func TotalLuminosity

func TotalLuminosity(img *image.Gray) uint64

Types

type ColorChannel

type ColorChannel int
const (
	RedChannel ColorChannel = iota
	GreenChannel
	BlueChannel
	AllChannels
)

type Line

type Line struct {
	Points  []image.Point
	Weight  int
	Channel ColorChannel
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL