The pixelscan library provides functions to scan pixels on a grid in a variety of spatial patterns. The library consists of scan generators and coordinate transformations. Scan generators are Python generators that return pixel coordinates in a particular spatial pattern. Coordinate transformations are iterators that apply spatial transformations to the coordinates created by the scan generators. Transformation can be chained to yield very generic transformations.
See the library API documentation here.
The typical calling syntax is
for x, y in transformation(generator(...), ...):
foo(x,y)
For example, the following scans pixels in a clockwise circular pattern from the origin up to a radius of one
for x, y in snap(circlescan(0, 0, 0, 1)):
print(x, y)
and will generate the following points
(0,0), (0,1), (1,1), (1,0), (1,-1), (0,-1), (-1,-1), (-1,0), (-1,1)
To skip every other pixel a skip transformation can be applied
for x, y in snap(skip(circlescan(0, 0, 0, 1), step=2)):
print(x, y)
which will generate the following points
(0,0), (1,1), (1,-1), (-1,-1), (-1,1)
The following are the currently available generators
The following are the currently available transformations
Name | Description |
---|---|
clip | Clips the coordinates at the given boundary |
Syntax: clip(scan,
minx = int,
maxx = int,
miny = int,
maxy = int,
predicate = function,
abort = bool) where scan = Pixel scan generator
minx = Minimum x-coordinate (default = -sys.maxint)
maxx = Maximum x-coordinate (default = sys.maxint)
miny = Minimum y-coordinate (default = -sys.maxint)
maxy = Maximum y-coordinate (default = sys.maxint)
predicate = Optional function that takes 2 arguments (x and y)
and returns true if coordinate should be kept
otherwise false (default = None)
abort = Abort iteration if boundary is crossed |
|
reflection | Reflects the coordinates along the x and/or y axis |
Syntax: reflection(scan, rx = bool, ry = bool) where scan = Pixel scan generator
rx = True if x-coordinate should be reflected (default=False)
ry = True if y-coordinate should be reflected (default=False) |
|
reservoir | Randomly samples the pixels using reservoir sampling |
Syntax: reservoir(scan, npoints = int) where scan = Pixel scan generator
npoints = Sample size |
|
rotation | Rotates the coordinates about the origin counter-clockwise |
Syntax: rotation(scan, angle = float) where scan = Pixel scan generator
angle = Counter-clockwise angle in degrees (default=0) |
|
sample | Randomly samples the pixels with a given probability |
Syntax: sample(scan, probability = float) where scan = Pixel scan generator
probability = Sampling probability in interval [0,1] (default=1) |
|
scale | Scales the coordinates with a given scale factors |
Syntax: scale(scan, sx = float, sy = float) where scan = Pixel scan generator
sx = x-coordinate scale factor (default=1)
sy = y-coordinate scale factor (default=1) |
|
skip | Skips the pixels with the given step size |
Syntax: skip(scan, start = int, stop = int, step = int) where scan = Pixel scan generator
start = Iteration starting 0-based index (default = 0)
stop = Iteration stopping 0-based index (default = sys.maxint)
step = Iteration step size (default = 1) |
|
snap | Snap the x and y coordinates to the nearest grid point |
Syntax: snap(scan) where scan = Pixel scan generator |
|
swap | Swap the x and y coordinates |
Syntax: swap(scan) where scan = Pixel scan generator |
|
translation | Translates the coordinates by the given offsets |
Syntax: translation(scan, tx = float, ty = float) where scan = Pixel scan generator
tx = x-coordinate translation offset (default = 0)
ty = y-coordinate translation offset (default = 0) |
Scan Generators such as circlescan and Coordinate Transformations such as rotation can yield non-grid points. They can be snapped to a grid point using the snap transformation.