pixelscan.pixelscan module

Various patterns to scan pixels on a grid. Rectangular patterns are scanned first along the x-coordinate then the y-coordinate. Radial patterns are scanned clockwise. Transformation filters are available to apply standard transformations (e.g., rotation, scale, translation) on the coordinates.

pixelscan.pixelscan.chebyshev(point1, point2)

Computes distance between 2D points using chebyshev metric

Parameters:
  • point1 (list) – 1st point
  • point2 (list) – 2nd point
Returns:

Distance between point1 and point2

Return type:

float

pixelscan.pixelscan.circlescan(x0, y0, r1, r2)

Scan pixels in a circle pattern around a center point

Parameters:
  • x0 (float) – Center x-coordinate
  • y0 (float) – Center y-coordinate
  • r1 (float) – Initial radius
  • r2 (float) – Final radius
Returns:

Coordinate generator

Return type:

function

class pixelscan.pixelscan.clip(scan, minx=-2147483647, maxx=2147483647, miny=-2147483647, maxy=2147483647, predicate=None, abort=False)

Bases: object

Clip coordinates that exceed boundary

Parameters:
  • scan (function) – Pixel scan generator
  • minx (int) – Minimum x-coordinate (default = -sys.maxint)
  • maxx (int) – Maximum x-coordinate (default = sys.maxint)
  • miny (int) – Minimum y-coordinate (default = -sys.maxint)
  • maxy (int) – Maximum y-coordinate (default = sys.maxint)
  • predicate (function) – Optional function that takes 2 arguments (x and y) and returns true if coordinate should be kept otherwise false (default = None)
  • abort (bool) – Abort iteration if boundary is crossed
next()

Next point in iteration

pixelscan.pixelscan.gridscan(xi, yi, xf, yf, stepx=1, stepy=1)

Scan pixels in a grid pattern along the x-coordinate then y-coordinate

Parameters:
  • xi (int) – Initial x-coordinate
  • yi (int) – Initial y-coordinate
  • xf (int) – Final x-coordinate
  • yf (int) – Final y-coordinate
  • stepx (int) – Step size in x-coordinate
  • stepy (int) – Step size in y-coordinate
Returns:

Coordinate generator

Return type:

function

pixelscan.pixelscan.hilbertrot(n, x, y, rx, ry)

Rotates and flips a quadrant appropriately for the Hilbert scan generator. See https://en.wikipedia.org/wiki/Hilbert_curve.

pixelscan.pixelscan.hilbertscan(size, distance)

Scan pixels in a Hilbert curve pattern in the first quadrant. Modified algorithm from https://en.wikipedia.org/wiki/Hilbert_curve.

Parameters:
  • size (int) – Size of enclosing square
  • distance (int) – Distance along curve (Must be smaller than size**2 - 1)
Returns:

Coordinate generator

Return type:

function

pixelscan.pixelscan.manhattan(point1, point2)

Computes distance between 2D points using manhattan metric

Parameters:
  • point1 (list) – 1st point
  • point2 (list) – 2nd point
Returns:

Distance between point1 and point2

Return type:

float

class pixelscan.pixelscan.reflection(scan, rx=False, ry=False)

Bases: object

Reflect coordinates about x and y axes

Parameters:
  • scan (function) – Pixel scan generator
  • rx (bool) – True if x-coordinate should be reflected (default=False)
  • ry (bool) – True if y-coordinate should be reflected (default=False)
next()

Next point in iteration

class pixelscan.pixelscan.reservoir(scan, npoints)

Bases: object

Randomly sample points using the reservoir sampling method. This is only useful if you need exactly ‘npoints’ sampled. Otherwise use the ‘sample’ transformation to randomly sample at a given rate. This method requires storing ‘npoints’ in memory and precomputing the random selection so it may be slower than ‘sample’.

Parameters:
  • scan (function) – Pixel scan generator
  • npoints (int) – Sample size
next()

Next point in iteration

pixelscan.pixelscan.ringscan(x0, y0, r1, r2, metric=<function chebyshev at 0x000000000428F0B8>)

Scan pixels in a ring pattern around a center point clockwise

Parameters:
  • x0 (int) – Center x-coordinate
  • y0 (int) – Center y-coordinate
  • r1 (int) – Initial radius
  • r2 (int) – Final radius
  • metric (function) – Distance metric
Returns:

Coordinate generator

Return type:

function

class pixelscan.pixelscan.rotation(scan, angle=0)

Bases: object

Rotate coordinates by given angle. If the final transformation axes do not align with the x and y axes then it may yield duplicate coordinates during scanning.

Parameters:
  • scan (function) – Pixel scan generator
  • angle (float) – Counter-clockwise angle in degrees (default=0)
next()

Next point in iteration

class pixelscan.pixelscan.sample(scan, probability=1)

Bases: object

Randomly sample points at the given probability.

Parameters:
  • scan (function) – Pixel scan generator
  • probability (float) – Sampling probability in interval [0,1] (default=1)
next()

Next point in iteration

class pixelscan.pixelscan.scale(scan, sx=1, sy=1)

Bases: object

Scale coordinates by given factor

Parameters:
  • scan (function) – Pixel scan generator
  • sx (float) – x-coordinate scale factor (default=1)
  • sy (float) – y-coordinate scale factor (default=1)
next()

Next point in iteration

class pixelscan.pixelscan.skip(scan, start=0, stop=2147483647, step=1)

Bases: object

Skip points at the given step size

Parameters:
  • scan (function) – Pixel scan generator
  • start (int) – Iteration starting 0-based index (default = 0)
  • stop (int) – Iteration stopping 0-based index (default = sys.maxint)
  • step (int) – Iteration step size (default = 1)
next()

Next point in iteration

pixelscan.pixelscan.snakescan(xi, yi, xf, yf)

Scan pixels in a snake pattern along the x-coordinate then y-coordinate

Parameters:
  • xi (int) – Initial x-coordinate
  • yi (int) – Initial y-coordinate
  • xf (int) – Final x-coordinate
  • yf (int) – Final y-coordinate
Returns:

Coordinate generator

Return type:

function

class pixelscan.pixelscan.snap(scan)

Bases: object

Snap x and y coordinates to a grid point

Parameters:scan (function) – Pixel scan generator
next()

Next point in iteration

class pixelscan.pixelscan.swap(scan)

Bases: object

Swap x and y coordinates

Parameters:scan (function) – Pixel scan generator
next()

Next point in iteration

class pixelscan.pixelscan.translation(scan, tx=0, ty=0)

Bases: object

Translate coordinates by given offset

Parameters:
  • scan (function) – Pixel scan generator
  • sx (float) – x-coordinate translation offset (default = 0)
  • sy (float) – y-coordinate translaation offset (default = 0)
next()

Next point in iteration

pixelscan.pixelscan.walkscan(x0, y0, xn=0.25, xp=0.25, yn=0.25, yp=0.25)

Scan pixels in a random walk pattern with given step probabilities. The random walk will continue indefinitely unless a skip transformation is used with the ‘stop’ parameter set or a clip transformation is used with the ‘abort’ parameter set to True. The probabilities are normalized to sum to 1.

Parameters:
  • x0 (int) – Initial x-coordinate
  • y0 (int) – Initial y-coordinate
  • xn (float) – Probability of moving in the negative x direction
  • xp (float) – Probability of moving in the positive x direction
  • yn (float) – Probability of moving in the negative y direction
  • yp (float) – Probability of moving in the positive y direction