This page is maintained in the package's
This is a Chicken Scheme egg with various image processing
Note that a few of these functions call ImageMagick.
These are exposed in case we want to switch to 16-bit grayscale or
Various color space conversions. Colors are vectors of values.
- (rgb->hsv rgb)
- (hsv->rgb hsv)
- (rgb->cd rgb)
- (rgb->cmyk rgb)
- (rgb->uv-hsv c)
Convert to l*ab. Colors are vectors of values. This is space in which
Euclidean distance is similar to human perceputal distance. These
implement a 2 degree observer and the D65 illuminant.
- (rgb->xyz c)
- (xyz->rgb c)
- (xyz->l*ab c)
- (l*ab->xyz c)
- (rgb->l*ab c)
- (l*ab->rgb c)
Not really a color space conversion, covert an rgb color to an HTML
- (rgb->html c)
Three image formats are supported. PBMs are binary images, PGMs are
greyscale and PPMs are tri-plane (nominally RGB) images. All planes
are stored as scheme matrices. Together all of these formats are
called PNM. This is a standard format that many tools (such browser
and ImageMagick) can read and write. PNMs can be serialized as either
raw packed binaries or ascii text files. Note that we are unable to
read or write raw PBMs.
- (define-structure pbm raw? bitmap)
- (define-structure pgm raw? maxval grey)
- (define-structure ppm raw? maxval red green blue)
- (pnm? m)
Index into an PNM image or into a matrix. This is like indexing into a
matrix except that the arguments are reversed. A matrix-ref takes
the row and then the column, image-ref takes a point which is an (x,y)
- (image-ref i p)
Ensure that the PBM image is in ascii. We are unable to read or write
- (pbm-ascii pbm)
The resulting image will not share any data with the original.
- (pnm-copy pnm)
Read a PNM. We determine the kind of image (PBM, PGM, PPM see above)
from the file header.
- (read-pnm pathname)
Write a PNM. If don't provide an extension an appropriate one will be
appended to your pathname.
- (write-pnm pnm pathname)
Create constant images.
- (pbm-constant width height bit)
- (pgm-constant width height grey)
- (ppm-constant width height red green blue)
Create a black vertical stripe on a white image.
- (pbm-left-vertical-stripe width height left)
Crop an image and return a new image of the given size.
- (crop-image pnm x y width height)
Convert any image format to a color or greyscale image
- (pnm->ppm pnm)
- (pnm->pgm pnm)
Various image conversions.
- (pbm->pgm pbm)
- (pgm->ppm pgm)
- (pbm->ppm pbm)
- (ppm->pgm ppm)
Convert a color or greyscale image to a binary image with the provided
- (pgm->pbm pgm threshold)
- (ppm->pbm ppm threshold)
Basic image information
Basic image information.
- (pnm-width pnm)
- (pnm-height pnm)
Creates a greyscale image representing one of the HSV channels from a
- (ppm-hue ppm)
- (ppm-saturation ppm)
- (ppm-value ppm)
Compute the mean or covariance of an image. These take an optional
- (ppm-mean image colour-transform)
- (ppm-covariance image colour-transform)
- (pgm-mean image)
- (pgm-variance image)
Logical and morphological operations
Basic logical operations on binary images.
- (pbm-and pbm1 pbm2)
- (pbm-or pbm1 pbm2)
- (pbm-not pbm)
- (pbm-xor pbm1 pbm2)
Compute the difference between two greyscale images.
- (pgm-absolute-difference pgm1 pgm2)
Is this image empty?
- (empty-pnm? pnm)
Bloat or skeletonize a binary image.
- (pbm-skeletonize pbm)
- (pbm-bloat pbm n)
Floor fill a binary image.
- (pbm-flood pbm point)
A PNM movie is a sequence of PNMs on disk.
- (pnm-movie-frame-pathname pathname i)
- (pnm-movie-length pathname)
- (read-pnm-movie pathname)
- (write-pnm-movie pnm-movie pathname)
The white pixels in the pbm become white in the resulting image.
- (overlay-pbm-on-pnm pbm pnm)
Draw white or black windows on an image.
- (pnm-black-window pnm upper-left lower-right)
- (pnm-white-window pnm upper-left lower-right)
Black pixels in the PBM become black pixels in the result.
- (pbm-ppm-and pbm ppm)
- (pgm-and-pbm pgm pbm)
Shift an image down and rightward by the give number of pixels.
- (pnm-shift pnm delta)
Smooth a greyscale image with the given variance.
- (pgm-smooth pgm sigma)
Cluster white pixels in the binary image with the given distance
- (pbm-proximity-clusterer pbm threshold)
Rotate (transpose) an image or flip (mirror) an image.
- (pnm-rotate pnm)
- (pnm-flip pnm)
Burn the ppm with the given mask and color.
- (ppm-burn base mask colour)
Compute normalized flow between two pairs of greyscale images.
- (normal-flow-magnitude pgm1 pgm2 epsilon sigma sensitivity)
- (threshold-normal-flow-magnitude pgm1 pgm2 epsilon sigma threshold)
Returns a single matrix from a tri-plane PPM. This maps
colour-transform over the image.
- (flatten-ppm ppm colour-transform)
Threshold a greyscale image.
- (binary-threshold pgm threshold)
Otsu's Method to find an optional threshold and apply it.
- (find-threshold-otsu pgm)
- (binary-threshold-optimal pgm)
Method of Successive Means to find an optimal threshold and apply it.
- (find-threshold-means pgm)
- (binary-threshold-means pgm)
Map colour-tx over an region of a color image.
- (sample-image ppm colour-tx window-centre window-size)
Binary threshold a colour image by sampling a region around the given
point and thresholding all values that are within the given distance
threshold of the mean color of that region.
- (binary-threshold-colour ppm colour-tx point threshold)
Binary threshold a colour image with the given mean and variance. The
mahalanobis-distance between each pixel and the given mean and
variance will be computed and compared to the threshold.
- (colour-threshold ppm colour-tx mu isigma threshold)
Equalize a greyscale image.
- (histogram-equalise pgm)
Given a matrix compute an integral matrix which can provide the mean
value of a rectangular region in O(1).
- (make-integral-matrix matrix)
This computes the mean and variance of a square of size w in the given
- (compute-integral-matrix-mu integral-matrix x y w)
- (compute-integral-matrix-sigma squared-integral-matrix mu x y w)
Compute an adaptive threshold on the given integral matrix.
- (compute-adaptive-threshold integral-matrix squared-integral-matrix x y w)
Compute an adaptive threshold for a greyscale image with a given
- (adaptive-threshold pgm winsize)
Map f over a matrix passing it square submatrices of the given
size. At the edges f is passed #f.
- (slide-window m f size)
Count number of true values in a matrix.
- (count-pixels a)
Create a binary image from a color image where points are either white
or black depending on which is closer to the given means and
- (ppm->label-closest ppm mu1 sigma1 mu2 sigma2 #!optional colour-transform)
Compute histograms from a matrix.
- (find-histogram pixmap maxval)
- (histogram-mean histogram i)
- (histogram-variance histogram mu i)
- (normalised-histogram histogram val)
- (weighted-histogram histogram)
- (cumulative-histogram histogram)
- (find-between-class-variances omegas mus mu-total)
Rendering Line Segments
Compute the midpoint of a line segment.
- (midpoint l)
Compute the orientation of a vector.
- (orientation v)
Compute the orientation of a line segment.
- (line-segment-orientation l)
Convert between points and line semgents.
- (line-segment->points l)
- (line-segments->points ls)
- (points->line-segments ps)
Points and bounding boxes
Take the list of points and create a binay image of the given size
where those points are white.
- (points->pbm-of-size points height width)
Computing a bounding box for a set of points.
- (points-bounding-box points)
Compute the size of a bounding box
- (bounding-box-size bb)
Recompute the coordinates of the given points relative to the top-left
corner of the bounding box.
- (points->points-bounding-box points bb)
Convert points to a list of points on the bounding box of those
- (points->bounding-box-points points)
Normalize the cooredinates of these points to their bounding box. Or
to the bounding box of the given points.
- (normalize-to-bounding-box ps)
- (normalize-to-other-bounding-box points ps)
- (points->target-bounding-box points target-bb)
- (points->other-target-bounding-box points ps target-bb)
Bloat a bounding box.
- (bounding-box-bloat bb p)
Crop a bounding box out of an image.
- (bounding-box-crop bb image)
Convert a binary image to a set of points or vice versa.
- (pbm->points pbm)
- (points->pbm points height width)
Quantize coordinates, points or line segments.
- (quantize-coordinate x)
- (quantize-point p)
- (quantize-points ps)
- (quantize-line-segment l)
- (quantize-line-segments ls)
Define and compute basic properties of ellipses.
- (define-structure ellipse x0 y0 t0 a b)
- (ellipse-center ellipse)
- (ellipse-area ellipse)
- (ellipse-eccentricity ellipse)
The radial distance between two angles.
- (radial-distance theta phi)
Compute if a point is on an ellipse.
- (point-on-ellipse? p ellipse tolerance)
Place an ellipse around a line segment
- (line-segment->ellipse l)
Sample n points on an ellipse.
- (ellipse->points e #!optional (n 360))
Resize an image. This is quite slow as it writes the image out and
calls imagemagick to resize it.
- (resize-image w h i)
Subsample a pbm by a factor of 2.
- (subsample-pbm pbm)
Scale a pbm by a factor of 2 or 4.
- (scale-ppm ppm scale)
Compute connected components of a binary image with distance thershold
delta and size threshold threshold.x
- (connected-component-filter pbm delta threshold)
These are defined private for now as they need to be renamed.
- (define-private-structure vertex pixels vertex edges)
- (define-private-structure edge u v)
- (define-private-structure graph vertices edges)
Convert a binary image to a graph where pixels within delta of
each other are connected.
- (pbm->graph pbm delta)
- (labeling->graph labeling delta)
Compute the connect components of a graph.
- (dereference-vertex u)
- (connected-components g)
Convert a graph or list of vertices to a pbm.
- (vertices->pbm vertices height width)
- (graph->pbm g height width)
Convert a binary image to a list of chains, pixels that are connected
to each other.
- (pbm->chains pbm)
Convert a list of chains to a pbm.
- (chains->pbm chains height width)
Filters chains below a certain length.
- (chain-filter pbm threshold)
Break chains below a certain length.
- (break-chain chain l)
- (break-chains chains l)
Fill in missing values in pairs of frames.
- (conjure pbms delta span threshold1 threshold2)
Compute the Manhattan distance transform for a binary image and
reference into that distance transform.
- (distance-transform pbm)
- (closest-transform-ref closest-transform p)
Compute a generalized squared-euclidean distance transform on the
given vector or matrix. The -vals version also returns a map of
the closest points.
- (euclidean-1d-dt v)
- (euclidean-2d-dt m)
- (euclidean-1d-dt-vals v)
- (euclidean-2d-dt-vals m)
A mechanism to store raw image pointers.
- (define-structure pnm-buffer buffer width height pixfmt storage type)
Misc raw image buffer operations.
- (pnm->pixfmt p p4?)
- (pixfmt->stride pixfmt)
- (image-type->pixfmt t p4?)
- (image-type->storage-size t p4?)
- (pnm->image-type p)
- (pnm->storage p)
- (pixfmt->red pixfmt)
- (pixfmt->green pixfmt)
- (pixfmt->blue pixfmt)
- (pnm-buffer-size p p4?)
- (pnm->pnm-buffer! p . p4?)
- (pnm-fill-buffer! p b pixfmt)
- (free-pnm-buffer! p)
Convert between PPMs and Imlib images. PGMs and PBMs must first be
converted to PPMs because Imlib only handles RGB images.
- (imlib-image->pnm-buffer! image)
- (imlib-image->ppm image)
- (ppm->imlib-image ppm)
Convert a raw image buffer to a scheme image.
- (pnm-buffer->pnm b)
- (pnm-buffer->pbm p)
- (pnm-buffer->pgm p)
- (pnm-buffer->ppm p)
Convert any image to a raw image buffer.
- (image->pnm-buffer! image)
Compute the absolute difference between two color images.
- (ppm-absolute-difference ppm1 ppm2)
Set a pixel in a color image to a given value (a 3-vector).
- (set-ppm-pixel! ppm x y value)
Is this a valid position in the given image?
- (pnm-pixel? i x y)
Map f on each component of each pixel in the image.
- (map-ppm-values ppm f)
- (pbm-stack-vertical pbm1 pbm2)
- (pbm-stack-horizontal pbm1 pbm2)
- (ppm-stack-vertical ppm1 ppm2)
- (ppm-stack-horizontal ppm1 ppm2)
Misc operation on angles.
- (degrees->radians angle)
- (radians->degrees angle)
- (normalize-rotation rotation)
- (rotation+ x y)
- (rotation- x y)
- (angle-separation x y)
- (mean-angle angles)
Produce the 2D rotation matrix for the given angle.
- (rotation-matrix-2d theta)
Display an image. This invokes feh.
- (show i)
Written by the
[[Center for the Computational Study of Cognition, Control, and Perception|http://upplysingaoflun.ecn.purdue.edu/~qobi/cccp/]].
Maintainer: Andrei Barbu, email@example.com
Copyright 1993-1995 University of Toronto. All rights reserved.
Copyright 1996 Technion. All rights reserved.
Copyright 1996 and 1997 University of Vermont. All rights reserved.
Copyright 1997-2001 NEC Research Institute, Inc. All rights reserved.
Copyright 2002-2013 Purdue University. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see http://www.gnu.org/licenses.