Applies an adaptive threshold to an image.
This algorithm compares each pixel's brightness with the average brightness of the pixels in the (2 * block_radius + 1) square block centered on it. If the pixel if at least as bright as the threshold then it will have a value of 255 in the output image, otherwise 0.
Adjust the contrast of this image. contrast is the amount to adjust the contrast by. Negative values decrease the contrast and positive values increase the contrast.
Performs a Gaussian blur on this image. sigma is a measure of how much to blur by.
Convolves an 8bpp grayscale image with a kernel of width (2 * x_radius
+ 1)
and height (2 * y_radius
+ 1) whose entries are equal and
sum to one. i.e. each output pixel is the unweighted mean of
a rectangular region surrounding its corresponding input pixel.
We handle locations where the kernel would extend past the image's boundary by treating the image as if its boundary pixels were repeated indefinitely.
Brighten the pixels of this image. value is the amount to brighten each pixel by. Negative values decrease the brightness and positive values increase it.
Runs the canny edge detection algorithm.
Returns a binary image where edge pixels have a value of 255 and non-edge pixels a value of 0.
Low threshold for the hysteresis procedure. Edges with a strength higher than the low threshold will appear in the output image, if there are strong edges nearby.
High threshold for the hysteresis procedure. Edges with a strength higher than the high threshold will always appear as edges in the output image.
Return this image's color type.
Returns an image of the same size as the input, where each pixel is labelled by the connected foreground component it belongs to, or 0 if it's in the background. Input pixels are treated as belonging to the background if and only if they are equal to the provided background pixel.
Panics if the image contains 232 or more pixels. If this limitation causes you problems then open an issue and we can rewrite this function to support larger images.
Four: A pixel is connected to its N, S, E and W neighbors. Eight: A pixel is connected to all of its neighbors.
Return a cut out of this image delimited by the bounding rectangle.
Returns an image showing the distance of each pixel from a foreground pixel in the original image.
Equalises the histogram of an 8bpp grayscale image See also histogram equalization (wikipedia).
Filters this image with the specified 3x3 kernel.
Flip this image horizontally
Flip this image vertically
Blurs an image using a Gaussian of standard deviation sigma. The kernel used has type f32 and all intermediate calculations are performed at this type.
Adds independent additive Gaussian noise to all channels of an image, with the given mean and standard deviation.
Return a grayscale version of this image.
Returns horizontal correlations between an image and a 1d kernel. Pads by continuity. Intermediate calculations are performed at type K.
Hue rotate the supplied image. value is the degrees to rotate each pixel by. 0 and 360 do nothing, the rest rotates by the given degree value. just like the css webkit filter hue-rotate(180)
Invert the colors of this image.
Transforms the input image.
Transforms the input image.
Applies a median filter of given dimensions to an image. Each output pixel is the median
of the pixels in a (2 * x_radius + 1) * (2 * y_radius + 1)
kernel of pixels in the input image.
Pads by continuity. Performs O(max(x_radius, y_radius)) operations per pixel.
Dilation followed by erosion.
See the erode
and dilate
documentation for definitions of dilation
and erosion.
Sets all pixels within distance k of a foreground pixel to white.
A pixel is treated as belonging to the foreground if it has non-zero intensity.
Sets all pixels within distance k of a background pixel to black.
A pixel is treated as belonging to the foreground if it has non-zero intensity.
Erosion followed by dilation.
See the erode
and dilate
documentation for definitions of dilation
and erosion.
Returns the [Otsu threshold level] of an 8bpp image. [Otsu threshold level]: https://en.wikipedia.org/wiki/Otsu%27s_method
Sometimes called “fold”, useful for e.g. summing specific pixel values.
Sometimes called “fold”, useful for e.g. summing specific pixel values.
Resize this image using the specified filter algorithm. Returns a new image.
Rotate this image 180 degrees clockwise.
Rotate this image 270 degrees clockwise.
Rotate this image 90 degrees clockwise.
Converts pixels to black or white at the given rate (between 0.0 and 1.0). Black and white occur with equal probability.
Saves the supplied buffer to a file at the path specified. The image format is derived from the file extension.
Saves the supplied buffer to a file at the path specified in the specified format.
Returns 2d correlation of view with the outer product of the 1d kernels h_kernel
and v_kernel
.
Returns 2d correlation of an image with the outer product of the 1d kernel filter with itself.
Sharpens a grayscale image (to converts to grayscale) by applying a 3x3 approximation to the Laplacian.
Sharpens a grayscale image using a Gaussian as a low-pass filter.
is the standard deviation of the Gaussian filter used
controls the level of sharpening. output = input + amount * edges
.
Reduces the width of an image using seam carving.
Warning: this is very slow! It implements the algorithm from (here)[https://inst.eecs.berkeley.edu/~cs194-26/fa16/hw/proj4-seamcarving/imret.pdf] with some extra unnecessary allocations thrown in. Rather than attempting to optimise the implementation of this inherently slow algorithm, the planned next step is to switch to the algorithm from (here)[https://users.cs.cf.ac.uk/Paul.Rosin/resources/papers/seam-carving-ChinaF.pdf].
Linearly stretches the contrast in an image, sending lower
to 0
and upper
to 2558
.
Is it common to choose upper
and lower
values using image percentiles -
see percentile
.
Returns a binarized image from an input 8bpp grayscale image obtained by applying the given threshold. Pixels with intensity equal to the threshold are assigned to the background.
Scale this image down to fit within a specific size. Returns a new image. This method uses a fast integer algorithm where each source pixel contributes to exactly one target pixel. May give aliasing artifacts if new size is close to old size.
Performs an unsharpen mask on this image. sigma is the amount to blur the image by. threshold is a control of how much to sharpen
Returns horizontal correlations between an image and a 1d kernel. Pads by continuity.
Open the image located at the path specified. The image's format is determined from the path's file extension.
let image: Promise<Image> = Image
.open("test.jpeg")
.then(x => {
console.log("loaded image");
return x;
});
let image: Promise<Image> = Image
.open("test.jpeg")
.then(x => {
console.log("loaded image");
return x;
});
Generated using TypeDoc
A loaded image
This class is the core API of Web Images.
API Example:
import {Image} from "web-images"; import {basename} from "path"; import * as fs from "fs"; async function load_and_save_fast(path: string): Promise<null> { // Assume `path` has a file extension set to “jpeg”. const output_path = `./output/${basename(path, "jpeg")}.png`; return Image .open(path) .then((x: Image) => x.thumbnail({ width: 500, height: 500 })) .then((x: Image) => x.save(output_path)) .then((_) => { console.log("done"); return null; }); } async function load_and_save_quality(path: string): Promise<null> { // Assume `path` has a file extension set to “jpeg”. const output_path = `./output/${basename(path, "jpeg")}.png`; return Image .open(path) .then((x: Image) => x.resize({ width: 500, height: 500 })) .then((x: Image) => x.save(output_path)) .then((_) => { console.log("done"); return null; }); } async function load_only(path: string): Promise<Image> { return Image .open(path) .then((x: Image) => x.resize({ width: 500, height: 500, resize_exact: false, filter_type: "Lanczos3" })); }