Skip to content

Python implementation of [Manson, Josiah, and Scott Schaefer. "Wavelet rasterization." Computer Graphics Forum. Vol. 30. No. 2. Blackwell Publishing Ltd, 2011].

License

Notifications You must be signed in to change notification settings

ufoym/wavelet-rasterization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wavelet Rasterization

Introduction

Wavelet rasterization is a method for analytically calculating an anti-aliased rasterization of arbitrary polygons or shape bounded by Bezier curves. For more details, please read the following paper:

Manson, Josiah, and Scott Schaefer. "Wavelet rasterization." Computer Graphics Forum. Vol. 30. No. 2. Blackwell Publishing Ltd, 2011.

This is a python implementation of the algorithm. Currently it supports three types of contours:

  • Polygon
  • Quadratic Bezier Contour
  • Cubic Bezier Contour

Usage

Rasterizing these contours are very simple:

  1. create a specific Contour object (Line.Contour, QuadraticBezier.Contour, or CubicBezier.Contour)
  2. use this contour to construct a Rasterizer object
  3. call the method get() of the Rasterizer object, you get an array of pixels, each of which has a value range from 0 to 1 that indicates the local transparent of the shape.

Example

An example session could like:

import cv2, numpy as np             # for image IO
from contour import *
from rasterizer import Rasterizer

## rasterize a polyline
contour = Line.Contour([(4,4), (30,6), (10,14)])
raster = Rasterizer(contour, 32, 32).get()
raster = np.array(np.asarray(raster)*255+0.5, np.uint8)
cv2.imwrite('var/Line.png', raster)

Assuming everything is working OK, the examples should generate the following image:

line

You can also rasterize a quadratic bezier contour:

contour = QuadraticBezier.Contour([(4,4), (28,4), (28,28), (4,28)])
raster = Rasterizer(contour, 32, 32).get()
raster = np.array(np.asarray(raster)*255+0.5, np.uint8)
cv2.imwrite('var/QuadraticBezier.png', raster)

quadraticbezier

or a cubic bezier contour:

## rasterize a cubic bezier contour
contour = CubicBezier.Contour([(4,4),(12,4),(28,12),(28,28),(12,28),(4,12)])
raster = Rasterizer(contour, 32, 32).get()
raster = np.array(np.asarray(raster)*255+0.5, np.uint8)
cv2.imwrite('var/CubicBezier.png', raster)

cubicbezier

About

Python implementation of [Manson, Josiah, and Scott Schaefer. "Wavelet rasterization." Computer Graphics Forum. Vol. 30. No. 2. Blackwell Publishing Ltd, 2011].

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published