Module: imageFilters

Module to filter images. This module provides a set of image filters, each realized by calling the filter function, passing it an input image, a filter name, and optional filter options. The list of available filters is provided by the filters() function.

This implementation uses code by Jerry Huxtable, licensed under the Apache License, Version 2.0. The code is available at http://www.jhlabs.com/ip/filters.

The filters provided by this implementation include at least the ones listed below, with options in the sublist (if there are options).

FIXME: This list is incomplete. See $PTII/com/jhlabs/image for a complete list of filters.

  • Annotate: Annotate an image with an overlaid SVG graphic.
    • Graphic: The SVG graphic. Defaults to an empty string, which specifies to use GraphicURI.
    • GraphicURI: The location of the graphic. Defaults to an empty string, which specifies no graphic.
    • Rotation: A rotation to apply before translating.
    • Scale: A scaling to apply before translating.
    • XOffset: The horizontal offset (translation) for the graphic in pixels. Defaults to 0.
    • YOffset: The vertical offset (translation) for the graphic in pixels. Defaults to 0.
  • Average: Average the 3x3 neighbourhood of each pixel, providing a simple blur.
  • BicubicScale: Scale an image using bi-cubic interpolation.
    • Height: The height of the result image, in pixels. Defaults to 256.
    • Width: The width of the result image, in pixels. Defaults to 256.
  • Block: Pixellate an image.
    • BlockSize: The size of the blocks.
  • Border: Put a border around the image.
    • BorderColor: The color (see below) for the border. This defaults to white.
    • BottomBorder: The width of the bottom border, in pixels. This defaults to 10.
    • LeftBorder: The width of the left border, in pixels. This defaults to 10.
    • RightBorder: The width of the right border, in pixels. This defaults to 10.
    • TopBorder: The width of the top border, in pixels. This defaults to 10.
  • BoxBlur: Box blur the image.
    • HRadius: The horizontal radius, in pixels. This defaults to 10.
    • VRadius: The vertical radius, in pixels. This defaults to 10.
    • Iterations: The number of iterations. This defaults to 1, but larger integers will approximate Gaussian blur.
  • Bump: A simple embossing filter.
  • ChannelMix: Mix the red, green and blue channels of an image into each other. The default options are {"IntoR": 255, "IntoG": 255, "IntoB": 255, "BlueGreen": 127, "GreenRed": 127, "RedBlue": 127}, which inverts the colors while preserving the original brightness.
    • IntoB: How much of the blue in the output is taken from red and green. 255 means all of it, and 0 means none of it (all the original blue is preserved).
    • IntoG: How much of the green in the output is taken from red and blue. 255 means all of it, and 0 means none of it (all the original green is preserved).
    • IntoR: How much of the red in the output is taken from blue and green. 255 means all of it, and 0 means none of it (all the original red is preserved).
    • BlueGreen: Proportion of blue vs. green that goes into red. 0 means only blue and 255 means only green.
    • GreenRed: Proportion of green vs. red that goes into blue. 0 means only green and 255 means only red.
    • RedBlue: Proportion of red vs. blue that goes into green. 0 means only red and 255 means only green.
  • Chrome: Create a chrome effect on the image.
    • Amount: The amount of the effect. This ranges from 0.0 to 1.0 and defaults to 0.5.
    • Exposure: The exposure, ranging from 0.0 (black image) to 1.0 (maximum, the default).
  • Circle: Wrap an image around a circular arc.
    • Angle: The starting angle of the arc, in radians. This defaults to 0.0.
    • Height: The height of the arc, in pixels. This defaults to 200.
    • Radius: The radius of the inner arc, in pixels. This defaults to 100.
    • CentreX: The horizontal center of the arc, as a fraction of the width. This ranges from 0.0 to 1.0 and defaults to 0.5.
    • CentreY: The vertical center of the arc, as a fraction of the width. This ranges from 0.0 to 1.0 and defaults to 1.0.
    • SpreadAngle: The spread angle of the arc, in radians. This defaults to $PI.
  • ColorHalftone:
    • DotRadius: The size of the dots, in pixels. This defaults to 2.0.
    • CyanScreenAngle: The angle of the cyan screen, in radians. This defaults to 1.885 (108 degrees).
    • MagentaScreenAngle: The angle of the magenta screen, in radians. This defaults to 2.827 (162 degrees).
    • YellowScreenAngle: The angle of the yellow screen, in radians. This defaults to 1.571 (90 degrees).
  • Contour_: Draw contours on an image at given changes in brightness levels.
    • Levels: The number of levels into which to divide the image. This defaults to 5.
    • Scale: The scale factor to apply to the brightness before leveling. This defaults to 1.
    • Offset: An offset to apply to the brightness. This defaults to 0.
    • ContourColor: The color to use in drawing the contours. This defaults to "black" (see below for color specs).
  • Contrast: Change the brightness and contrast of an image.
    • Brightness: The brightness scale factor. This defaults to 1.0, which makes no change in brightness.
    • Contrast: The contrast scale factor. This defaults to 1.0, which makes no change in contrast.
  • Crop: Crop an image.
    • _X_: The starting horizontal position, in pixels. This defaults to 0.
    • _Y_: The starting vertical position, in pixels. This defaults to 0.
    • Width: The width, in pixels. This defaults to 128.
    • Height: The height, in pixels. This defaults to 128.
  • Crystallize: Apply a crystallizing effect to an image, by producing Voronoi cells filled with colours from the image.
    • Angle: Angle of the cells in radians. Defaults to 0.0.
    • EdgeColor: Color for the edge lines (see below). Defaults to black.
    • EdgeThickness: Thickness of the edges. Defaults to 0.4.
    • FadeEdges: Boolean indicating whether to fade edges. Defaults to false.
    • Scale: Size of the cells, in pixels. Defaults to 16.
    • Stretch: Vertical stretch of the cells. Defaults to 1.0, which does not stretch.
  • FIXME: Missing filters (alphabetically) here.
  • Gray: Gray out an image by averaging each pixel with white.
  • Invert: Invert the colors of an image.
  • LensBlur: Simulate a lens blur. Options:
    • Bloom: The bloom factor. This is an int that defaults to 2.
    • BloomThreshold: The bloom threshold. This is an int that defaults to 255, which disables bloom.
    • Radius: The radius, in pixels. This is an int that defaults to 10.
    • Sides: The number of sides of the aperture. This is an int that defaults to 5.
  • MotionDetector: Detect motion and indicate it on the image.
    • PixelThreshold: Intensity threshold whereby a pixel is deemed to different (an int 0 - 255, with default 25).
    • AreaThreshold: The percentage threshold of image that has different pixels for motion to be detected (a double 0-100, with default 0.2).
  • Solarize: Solarize an image.
  • Threshold: Threshold pixels in an image, based on their brightness. Options:
    • LowerThreshold: The threshold below which pixels become Black. This is an int that defaults to 127.
    • UpperThreshold: The threshold above which pixels become White. This is an int that defaults to 127.
    • Black: The color produced for pixels below LowerThreshold. This is color (see below) that defaults to black.
    • White: The color produced for pixels above UpperThreshold. This is color (see below) that defaults to white.

For options that specify a color, the color may be given as an integer where bits 24-31 represent alpha, bits 16-23 represent red, bits 8-15 represent green, and bits 0-7 represent blue. Alternatively, the color may be given as a string of the form of a hexadecimal number, e.g. "0xff0000" for red, a standard color name, e.g. "red", or a CSS-style color specification, e.g. "#FF0000" for red. The color names supported are black, blue, cyan, darkGray, gray, green, lightGray, magenta, orange, pink, red, white, and yellow.

Version:
  • $$Id$$
Author:
  • Edward A. Lee
Source:

Methods

(static) filter(image, filterName, options)

Invoke the named filter on the specified image with the specified options and return the result. Any unrecognized options are ignored. Note that previously applied options for a given filter will still be used, even if they are not set in this call.

Parameters:
Name Type Description
image

The image to filter.

filterName

The name of the filter.

options

An object whose fields specify filter options.

Source:
Returns:

The filtered image.

(static) filters()

Return an array of filter names for image filters currently available on the current host.

Source:
Returns:

An array of filter names.