Skip to main content

Computer vision

ABS

abs(Array of F64 a) -> Array -r
STABLE

The absolute of an image.

Takes the absolute value of each element in a floating point graylevel image.

ParameterDescription
aImage to take the absolute of.

Return: Absolute image.


CV:CONST:COLORMAP_HOT

cv:const:colormap_hot( ) -> Charstring
STABLE

Stored function with colormap ID.

Return: Colormap ID as string.


CV:CONST:COLORMAP_JET

cv:const:colormap_jet( ) -> Charstring
STABLE

Stored function with colormap ID.

Return: Colormap ID as string.


CV:CONST:COLORMAP_VIRIDIS

cv:const:colormap_viridis( ) -> Charstring
STABLE

Stored function with colormap ID.

Return: Colormap ID as string.


CV:CONST:THRESH_BINARY

cv:const:thresh_binary( ) -> Charstring
STABLE

Stored function with thresholding type ID.


CV:CONST:THRESH_BINARY_INV

cv:const:thresh_binary_inv( ) -> Charstring
STABLE

Stored function with thresholding type ID.


CV:CONST:THRESH_TO_ZERO

cv:const:thresh_to_zero( ) -> Charstring
STABLE

Stored function with thresholding type ID.


CV:CONST:THRESH_TO_ZERO_INV

cv:const:thresh_to_zero_inv( ) -> Charstring
STABLE

Stored function with thresholding type ID.


CV:CONST:THRESH_TRUNK

cv:const:thresh_trunk( ) -> Charstring
STABLE

Stored function with thresholding type ID.


CV:CROP

cv:crop(Array of U8 im, Integer y, Integer x, Integer h, Integer w) -> Array out
STABLE

Cut out a w*h subimage at position (x,y) (1-indexed).

ParameterDescription
imThe image to be cropped (size [height,width[,channels]])
yThe y coordinate of the crop rectangle (the top edge, 1-indexed)
xThe x coordinate of the crop rectangle (the left edge, 1-indexed)
hThe height of the crop rectangle
wThe width of the crop rectangle

Return: A "U8" array of size [h,w[,channels]]


CV:DRAW_RECT

cv:draw_rect(Array im, Integer y0, Integer y1, Integer x0, Integer x1, Array of U8 col) -> Array out
STABLE

Draw a rectangle in a color image.

Draws a rectangle at (y0,x0) -> (y1,x1) with color col.

ParameterDescription
imThe image where the rectangle is drawn.
y0Top of rectangle.
y1Bottom of rectangle.
x0Left side of rectangle.
x1Right side of rectangle.
colRectangle color (RGB).

Return: Image with rectangle drawn.


CV:FILTER_2D

cv:filter_2d(Array of U8 im, Array of F64 filter) -> Array out
STABLE

Filter graylevel image with a kernel.

This filters the graylevel image im with a kernel using convolution. The function uses padding, so the output image will have the same size as the input image.

ParameterDescription
imThe graylevel image to filter.
filterThe filter kernel.

Return: Graylevel image of same size and type as original image.


cv:filter_2d(Array of F64 im, Array of F64 filter) -> Array -r
STABLE

Filter graylevel (floating point) image with a kernel.

This filters the graylevel image im with a kernel using convolution. The function uses padding, so the output image will have the same size as the input image.

ParameterDescription
imThe graylevel image to filter.
filterThe filter kernel.

Return: Graylevel image of same size and type as original image.


CV:FILTER_2D_NO_PAD

cv:filter_2d_no_pad(Array of F64 im, Array of F64 filter) -> Array -r
STABLE

Filter graylevel (floating point) image with a kernel, without padding.

This filters the graylevel image im with a kernel using convolution. The function does not use padding, so the output image will be smaller than the input image.

ParameterDescription
imThe graylevel image to filter.
filterThe filter kernel.

Return: Graylevel image of same type as original image.


CV:FINDMAX

cv:findmax(Array of F64 a)->(Integer, Integer)
STABLE

Find index for maximum value in 2D array.

ParameterDescription
a[sh,sw]The 2D array to search for maximum.

Return: A tuple (x,y) with the coordinate of the maximum.


cv:findmax(Array of F32 a)->(Integer, Integer)
STABLE

Find index for maximum value in 2D array.

ParameterDescription
a[sh,sw]The 2D array to search for maximum.

Return: A tuple (x,y) with the coordinate of the maximum.


CV:GET_GAUSSIAN_KERNEL

cv:get_gaussian_kernel(Integer sz, Real sigma) -> Array
STABLE

A gaussian kernel of size sz and standard deviation sigma.

ParameterDescription
szSize of gaussian kernel.
sigmaStandard deviation of gaussian kernel.

Return: Gaussian kernel as floating point (sz x sz) image.


CV:GRAY2RGB

cv:gray2rgb(Array of U8 im, Charstring colormap) -> Array of U8 rgb
STABLE

Convert graylevel image to RGB using colormap


cv:gray2rgb(Array of U8 im) -> Array -r
STABLE

Convert graylevel image to RBG.

Converts a graylevel image (MxN) to an RGB image (MxNx3). All color channels of the RGB image will have the same value as the respective pixels in the graylevel image.

ParameterDescription
imThe graylevel image to convert.

Return: An RGB image (MxNx3).


cv:gray2rgb(Array of U8 im, Charstring colormap, Boolean normalize) -> Array out
STABLE

Convert graylevel image to RGB using colormap, with option to normalize RGB image.

Converts a graylevel image (MxN) to an RGB image (MxNx3). The translation of the colors to the RGB image will be determined by the colormap. When normalize is true, the graylevel image will be normailzed to use the full range of unsigned byte values (0-255) before converting to RGB.

ParameterDescription
imThe graylevel image to convert.
colormapThe colormap for translating the graylevel values to RGB.

Return: An RGB image (MxNx3).


CV:HIST

cv:hist(Array of U8 im) -> Array
STABLE

Histogram of image.

Computes a histogram with 256 bins for an U8 image.

ParameterDescription
imImage to compute histogram.

Return: 1D array of histogram values.


CV:MASK

cv:mask(Array of U8 im, Array of U8 mask) -> Array out
STABLE

Apply a mask to an image (graylevel or RGB).

A pixel under the mask will keep its value. All pixels outside the mask will be set to zero.

ParameterDescription
imThe image to be masked (size [h,w[,3]])
maskThe mask to apply (size [h,w])

Return: A "U8" image of size [h,w[,3]]


CV:MATCH_TEMPLATE

cv:match_template(Array of F32 image, Array of F32 template) -> Array -r
STABLE

Template matching for graylevel images.

Implements template matching using template matching mode similar to OpenCV TM_CCORR_NORMED.

ParameterDescription
imageImage to search for template.
templateTemplate to find in image.

Return: A template map (same size as input image) with TM_CCORR_NORMED values (high values means good match with template at that position).


CV:OTSU_BINARIZATION

cv:otsu_binarization(Array of U8 im) -> Integer threshold
STABLE

Otsu binarization.

Computes the Otsu's binarization threshold for an image. (See https://en.wikipedia.org/wiki/Otsu%27s_method)

ParameterDescription
imGraylevel image for which to find the Otsu
binarization threshold value.

Return: The Otsu binarization threshold value.


CV:RESIZE

cv:resize(Array of U8 im, Integer h, Integer w) -> Array out
STABLE

Resize image (RGB or graylevel image) using nearest neighbor sampling.

ParameterDescription
imThe image to resize (can be RGB or graylevel)
hNew image height
wNew image width

Return: A "U8" image with size [h,w[,3]]


CV:RGB2GRAY

cv:rgb2gray(Array of U8 mat) -> Array -r
STABLE

Convert RGB image to graylevel.

Converts an RGB image (MxNx3) to a graylevel image (MxN).

ParameterDescription
matThe RGB image to convert.

Return: A graylevel image of size MxN.


CV:SCALE

cv:scale(Array of U8 image, Real scale) -> Array
STABLE

Resize image by a factor of image size.

ParameterDescription
imageThe image to scale
scaleThe scale factor

Return: A scaled version of the input image


CV:SLICE

cv:slice(Array of U8 a, Integer s, Integer e) -> Array -r
STABLE

Slice array.

Extracts subarray from index s to index e.

ParameterDescription
aArray to slice.
sStart index of slice (inclusive).
eEnd index of slice (inclusive).

Return: Array slice.


CV:SLICE2

cv:slice2(Array of U8 a, Array of I64 iy, Array of I64 ix) -> Array -r
STABLE

Slice 2D array.

Extracts 2D subarray with row indices in iy and column indices in ix.

ParameterDescription
a2D array to slice.
iyArray with row indices to extract.
ixArray with column indices to extract.

Return: 2D array slice.


CV:SLICE3

cv:slice3(Array of U8 a, Array of I64 iy, Array of I64 ix, Array of I64 ic) -> Array -r
STABLE

Slice 3D array.

Extracts 3D subarray with row indices in iy, column indices in ix, and "color" indices in ic.

ParameterDescription
a3D array (color image) to slice.
iyArray with row indices to extract.
ixArray with column indices to extract.
icArray with "color" indices to extract.

Return: 3D array slice.


CV:SSIM

cv:ssim(Charstring img1_path, Charstring img2_path, Real filter_size, Real filter_sigma, Real k1, Real k2) -> Real
STABLE

Structural similarity index measure (SSIM) of two images files.

Measures similarity between two graylevel images on file. (See https://en.wikipedia.org/wiki/Structural_similarity)

ParameterDescription
img1_pathPath to first image.
img2_pathPath to second image.
filter_sizeSize of gaussian filter used in SSIM.
filter_sigmaStandard deviation of gaussian filter used in SSIM.
k1Constant for stabilizing division (usually 0.01).
k2Constant for stabilizing division (usually 0.03).

Return: A value in the range [1,-1], where 1 indicates perfect similarity, 0 indicates no similarity, and -1 indicates perfect anti-correlation.


cv:ssim(Array of F64 img1, Array of F64 img2, Real filter_size, Real filter_sigma, Real k1, Real k2) -> Real
STABLE

Structural similarity index measure (SSIM) of two images.

Measures similarity between two (floating point) graylevel images. (See https://en.wikipedia.org/wiki/Structural_similarity)

ParameterDescription
img1First image.
img2Second image.
filter_sizeSize of gaussian filter used in SSIM.
filter_sigmaStandard deviation of gaussian filter used in SSIM.
k1Constant for stabilizing division (usually 0.01).
k2Constant for stabilizing division (usually 0.03).

Return: A value in the range [1,-1], where 1 indicates perfect similarity, 0 indicates no similarity, and -1 indicates perfect anti-correlation.


CV:THRESHOLD

cv:threshold(Array of U8 im, Integer thresh, Integer maxval, Charstring thresh_type) -> Array out
STABLE

Graylevel thresholding.

Applies fixed-level thresholding to a grayscale image. There are several types of thresholding supported by the function (determined by the thresh_type parameter).

ParameterDescription
imImage to threshold.
threshThreshold value (0-255).
maxvalMax value to use with THRESH_BINARY and
THRESH_BINARY_INV thresholding.
thresh_typeThresholding type ID.

Return: Thresholded image.


DOT

dot(Array of F32 source, Array of F32 template, Integer row, Integer col) -> Real
STABLE

Dot product of color image and color template.

Takes the dot product of the template and the region of the image that is covered by the template. Note that the template needs to fit in the image so the distance from the (row,col) position to the image bottom right corner cannot be smaller than the size of the template.

ParameterDescription
sourceColor image to use in dot product.
templateColor template to use in dot product.
rowY-coordinate for top left position of template.
colX-coordinate for top left position of template.

Return: Dot product between image and template at position (row,col) in the image.


DOT2

dot2(Array of F32 source, Array of F32 template, Integer row, Integer col) -> Real
STABLE

Dot product of graylevel image and graylevel template.

Takes the dot product of the template and the region of the image that is covered by the template. Note that the template needs to fit in the image so the distance from the (row,col) position to the image bottom right corner cannot be smaller than the size of the template. Example:

  src = | 1 2 3 4 |  temp = | 1 2 |   (row,col) = (1,3) 
| 5 6 7 8 | | 3 4 |
| 4 3 2 1 |
=> | 3 4 | * | 1 2 | = 1*3 + 2*4 + 7*3 + 8*4 = 64
| 7 8 | | 3 4 |
ParameterDescription
sourceGraylevel image to use in dot product.
templateGraylevel template to use in dot product.
rowY-coordinate for top left position of template.
colX-coordinate for top left position of template.

Return: Dot product between image and template at position (row,col) in the image.


PLUS

plus(Array of F64 a, Real x) -> Array r
STABLE

Add x to all elements in a.


PY:ANNOTATE

py:annotate(Array im, Charstring label, Vector rect) -> Array
STABLE

Annotate an image.

Annotates an image with a text string using the Python Pillow lbrary.

ParameterDescription
imThe image to annotate.
labelThe text to use as annotation.
rectA vector [x0, y0, x1, y1] with coordinates for the
label rectangle.

Return: The annotated image.


PY:DISPLAY_IMAGE

py:display_image(Array im) -> Array
STABLE

Display image in a separate window.

Displays an image in a seprate window using the Python Pillow lbrary.

ParameterDescription
imThe image to display.

Return: The displayed image.


PY:IMREAD

py:imread(Charstring file) -> Array
STABLE

Read image from file.

Reads an image from file by using the Python Pillow library.

ParameterDescription
fileThe image filename.

Return: Array containing the image.


PY:IMWRITE

py:imwrite(Charstring file, Array im) -> Array
STABLE

Write image to file.

Writes an image to file by using the Python Pillow library.

ParameterDescription
fileThe name of the file to write.
imThe image to write.

Return: Array containing the image.


PY:PUT_TEXT

py:put_text(Array of U8 im, Charstring text, Integer y, Integer x) -> Array
STABLE

Write text in image (using Python Pillow).

Writes text at a chosen position in a color image by calling the Python Pillow library.

ParameterDescription
imThe color image to which the text will be written.
textThe text to write.
yThe y-coordinate of the text.
xThe x-coordinate of the text.

Return: The image with the text.


ROUND_TO

round_to(Array of F64 a, Integer n) -> Array -r
STABLE

Round image vaules.

Round each value in a floating point graylevel image to n decimals.

ParameterDescription
aImage to round.
nNumber of decimals in output image.

Return: Rounded image (same size and type as input image).


SUM

sum(Array of F32 a, Integer row, Integer col, Integer height, Integer width) -> Real
STABLE

No description.


SUM2

sum2(Array of F32 a, Integer row, Integer col, Integer height, Integer width) -> Real
STABLE

Sum region in graylevel image.

Sum of array elements in rectangular region described by (row,col,height,width). Example:

  a = | 1 2 3 4 |  (row,col) = (1,3)   (height,width) = (2,2)
| 5 6 7 8 |
| 4 3 2 1 |
=> 3 + 4 + 7 + 8 = 22
ParameterDescription
aGraylevel image.
rowTop coordinate of rectangular region to sum.
colLeft coordinate of rectangular region to sum.
heightHeight of rectangular region to sum.
widthWidth of rectangular region to sum.