colidr

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 10 Imported by: 0

README

colidr (Coherent Line Drawing)

license release

Golang implementation of 'Coherent Line Drawing' algorithm developed by Kang et al, NPAR 2007.

sample

Requirements

  • Go 1.10 or higher, but it should work even with a lower version
  • OpenCV 3
  • gocv (bundled into the project, since it was extended with missing OpenCV functions needed for the implementation)
  • potrace - for transforming the bitmap into smooth, scalable image (however this is optional)

Installation

$ go get -u github.com/esimov/colidr/
$ go install

Another option is cloning the repository and running the make file.

$ git clone https://github.com/esimov/colidr
$ cd colidr
$ make

This will generate the binary file.

Usage

$ colidr -h

┌─┐┌─┐┬  ┬┌┬┐┬─┐
│  │ ││  │ ││├┬┘
└─┘└─┘┴─┘┴─┴┘┴└─

Coherent Line Drawing CLI
    Version: 1.0.1

  -aa
    	Anti aliasing
  -bl int
    	Blur size (default 3)
  -di int
    	Number of FDoG iteration
  -ei int
    	Number of Etf iteration (default 1)
  -in string
    	Source image
  -k int
    	Etf kernel (default 3)
  -out string
    	Destination image
  -pt
    	Use potrace to smooth edges (default true)
  -rho float
    	Rho (default 0.98)
  -sc float
    	SigmaC (default 1)
  -sm float
    	SigmaM (default 3)
  -sr float
    	SigmaR (default 2.6)
  -tau float
    	Tau (default 0.98)
  -ve
    	Visualize Etf
  -vr
    	Visualize end result

You can play with the command line arguments to modify the visual output of the generated (non-photorealistically rendered) image. To obtain higher fidelity results you need to increase the kernel value and also the ETF iteration number. Different combinations produces completely different output. The -di, -ei, -k flags are mostly used for fine tuning, on the other hand -rho and -tau flags could change dramatically the rendered output.

You can also visualize the edge tangent flow if you enable the -ve flag. Below is the process illustrated:

Original image Edge tangent flow Coherent line drawing (final output)
original flowfield output

Using the -pt flag you can trace the generated bitmap into a smooth scalabe image. You need to have potrace installed on your machine for this scope.

Below is an example whith and without the potrace flag activated.

Normal output Smoothed out
normal smooth

The above image was ganareted with the following command:

colidr -in ~/Desktop/patio.jpg -out ~/Desktop/patio_scene.png -k=1 -sr=2.5 -sm=3.2 -tau=0.9975 -di=1 -aa=1 -ve=1 -vr=0 -pt=1 -ei=1

Sample images

Rasterized bitmap Vectorized image
great_wave_of_kanagawa great_wave_of_kanagawa
starry_night starry_night
people people
tiger tiger

Todo

  • GUI support

Author

License

Copyright © 2019 Endre Simo

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sobel

func Sobel(img *image.NRGBA, threshold float64) *image.NRGBA

Sobel detect object edges of the provided image. It applies the sobel operator over the image and returns a new image.

Types

type Cld

type Cld struct {
	Image gocv.Mat

	Options
	// contains filtered or unexported fields
}

Cld is the main entry struct for the Coherent Line Drawing operations.

func NewCLD

func NewCLD(imgFile string, cldOpts Options) (*Cld, error)

NewCLD is the constructor method which require the source image and the CLD options as parameters.

func (*Cld) GenerateCld

func (c *Cld) GenerateCld() []byte

GenerateCld is the entry method for generating the coherent line drawing output. It triggers the generate method in iterative manner and returns the resulting byte array.

type Etf

type Etf struct {
	// contains filtered or unexported fields
}

Etf is the main entry struct for the edge tangent flow computation. It encompass the basic operational entities needed for the matrix operations.

func NewETF

func NewETF() *Etf

NewETF is a constructor method which initializes an Etf struct.

func (*Etf) Init

func (etf *Etf) Init(rows, cols int)

Init initializes the ETF matrices.

func (*Etf) InitDefaultEtf

func (etf *Etf) InitDefaultEtf(file string, size image.Point) error

InitDefaultEtf computes the gradientField matrix by setting up the pixel values from original image on which a sobel threshold has been applied.

func (*Etf) RefineEtf

func (etf *Etf) RefineEtf(kernel int)

RefineEtf will compute the refined edge tangent flow based on the formulas from the original paper.

type Options

type Options struct {
	SigmaR        float64
	SigmaM        float64
	SigmaC        float64
	Rho           float64
	Tau           float32
	BlurSize      int
	EtfKernel     int
	EtfIteration  int
	FDogIteration int
	AntiAlias     bool
	VisEtf        bool
	VisResult     bool
}

Options struct contains all the options currently supported by Cld, exposed by the main CLI application.

type PostProcessing

type PostProcessing struct {
	Etf
	// contains filtered or unexported fields
}

PostProcessing is a basic struct used for post processing operations

func NewPostProcessing

func NewPostProcessing(blurSize int) *PostProcessing

NewPostProcessing is a constructor method which initialize a PostProcessing struct.

func (*PostProcessing) AntiAlias

func (pp *PostProcessing) AntiAlias(src, dst gocv.Mat)

AntiAlias smooths out the destination matrix.

func (*PostProcessing) VizEtf

func (pp *PostProcessing) VizEtf(flowField, dst *gocv.Mat)

VizEtf visualize the edge tangent flow flowfield.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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