Copyright | (c) 2015 Christopher Chalmers |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | c.chalmers@me.com |
Safe Haskell | None |
Language | Haskell2010 |
Trace bitmap images into vector paths using the potrace library. This module also provides helpers for turning any JuicyPixels image to a bitmap.
- trace :: Bitmap -> [Curve]
- trace' :: Parameters -> Bitmap -> [Curve]
- traceForest :: Bitmap -> Forest Curve
- traceForest' :: Parameters -> Bitmap -> Forest Curve
- data Curve = Curve !P2 [Segment]
- data Segment
- data P2 = P2 !Double !Double
- data Bitmap
- generate :: Int -> Int -> (Int -> Int -> Bool) -> Bitmap
- fromImage :: Pixel a => Image a -> (a -> Bool) -> Bitmap
- toImage :: Pixel a => Bitmap -> a -> a -> Image a
- lumaThreshold :: DynamicImage -> Double -> Bitmap
- data Parameters = Parameters {}
- data TurnPolicy
- = BlackTP
- | WhiteTP
- | LeftTP
- | RightTP
- | MinorityTP
- | MajorityTP
- | RandomTP
- type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s
- turdSize :: Lens' Parameters Int
- turnPolicy :: Lens' Parameters TurnPolicy
- alphaMax :: Lens' Parameters Double
- optTolerance :: Lens' Parameters (Maybe Double)
Tracing
trace :: Bitmap -> [Curve] Source
Trace the bitmap image to a list of curves using potrace with def
parameters.
trace' :: Parameters -> Bitmap -> [Curve] Source
Trace the bitmap image to a list of curves using potrace with given parameters.
traceForest :: Bitmap -> Forest Curve Source
Trace the bitmap image as a forest of curves using potrace with def
parameters. Each child curve is completely contained in it's
parent.
traceForest' :: Parameters -> Bitmap -> Forest Curve Source
Trace the bitmap image as a forest of curves using potrace with given parameters parameters. Each child curve is completely contained in it's parent.
Path type
A curve is a list of segments. The starting point is provided for convenience but this is just the final point of the last segment.
Data type representing a 2D point were the origin is at the bottom left.
Bitmaps
generate :: Int -> Int -> (Int -> Int -> Bool) -> Bitmap Source
Given an image and a predicate for whether a pixel is on or off, create a bit-packed image suitable for passing to potrace.
fromImage :: Pixel a => Image a -> (a -> Bool) -> Bitmap Source
Generate a bitmap by apply the predicate function to each pixel of
JuicyPixels image. True
corresponds to a black pixel, False
corresponds to white.
lumaThreshold :: DynamicImage -> Double -> Bitmap Source
Generate a bitmap choosing pixels according to their luma plane for a threshold given between 0 and 1. Anything below the threshold is white. Anything above the threshold is black. Throws an error for CMYK images.
Parameters
data Parameters Source
Parameters to control the tracing operation of potrace. The default parameters are
Parameters {turdSize
= 2 ,turnPolicy
=MinorityTP
,alphaMax
= 1.0 ,optTolerance
=Just
0.2 }
Parameters | |
|
data TurnPolicy Source
How to resolve ambiguities during decomposition of bitmaps into paths.
BlackTP | Prefers to connect black (foreground) components |
WhiteTP | Prefers to connect white (background) components. |
LeftTP | Always take a left turn. |
RightTP | Always take a right turn. |
MinorityTP | Prefers to connect the color (black or white) that occurs least frequently in a local neighborhood of the current position. |
MajorityTP | Prefers to connect the color (black or white) that occurs most frequently in a local neighborhood of the current position. (default) |
RandomTP | Choose pseudo-randomly |
Lenses
type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s Source
A van Laarhoven lens, compatible with various lens libraries.
turdSize :: Lens' Parameters Int Source
The turdSize
parameter can be used to “despeckle” the bitmap to
be traced, by removing all curves whose enclosed area is below the
given threshold.
Default is 2
.
turnPolicy :: Lens' Parameters TurnPolicy Source
The TurnPolicy
parameter determines how to resolve ambiguities
during decomposition of bitmaps into paths.
Default is MinorityTP
.
alphaMax :: Lens' Parameters Double Source
The alphamax
parameter is a threshold for the detection of
corners. It controls the smoothness of the traced curve.The useful
range of this parameter is from 0.0 (polygon) to 1.3334 (no
corners).
Default is 1.0
.
optTolerance :: Lens' Parameters (Maybe Double) Source
The optTolerance
parameter defines the amount of error allowed in
this simplification. Larger values tend to decrease the number of
segments, at the expense of less accuracy. The useful range is from
0 to infinity, although in practice one would hardly choose values
greater than 1 or so. For most purposes, the default value is a
good trade off between space and accuracy. Nothing
turns
simplification off.
Default is
.Just
1.0