Image
OpenCV image
Operations
- AdaptiveThreshold
- BilateralFilter
- BoundingRect
- Bytes
- Canny
- Clone
- Columns
- ContourArea
- Convert
- Crop
- CvtColor
- Dilate
- DrawCircle
- DrawContours
- DrawRectangle
- DrawText
- Erode
- FindContours
- Flip
- GaussianBlur
- GetRotationMatrix2D
- IsEmpty
- Load
- MedianBlur
- MorphologyEx
- Normalize
- Resize
- Rows
- Save
- Show
- Size
- Sobel
- Threshold
- Type
- WarpAffine
- WarpPerspective
AdaptiveThreshold #
Applies an adaptive threshold to an array
method : public : AdaptiveThreshold(maxval:Float, adaptive_method:Int, threshold_type:Int, block_size:Int, C:Float) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| maxval | Float | non-zero value assigned to pixels that satisfy the condition |
| adaptive_method | Int | adaptive thresholding algorithm (0=MEAN_C, 1=GAUSSIAN_C) |
| threshold_type | Int | threshold type (must be BINARY or BINARY_INV) |
| block_size | Int | size of the pixel neighborhood (must be odd and greater than 1) |
| C | Float | constant subtracted from the mean or weighted mean |
Return
| Type | Description |
|---|---|
| Image | thresholded image |
BilateralFilter #
Applies bilateral filter to the image
method : public : BilateralFilter(d:Int, sigmaColor:Float, sigmaSpace:Float) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| d | Int | diameter of each pixel neighborhood |
| sigmaColor | Float | filter sigma in the color space |
| sigmaSpace | Float | filter sigma in the coordinate space |
Return
| Type | Description |
|---|---|
| Image | filtered image |
BoundingRect # function
Computes the bounding rectangle for a single contour.
function : BoundingRect(contours:Int[], index:Int) ~ RectParameters
| Name | Type | Description |
|---|---|---|
| contours | Int | packed contour data from FindContours() |
| index | Int | index of the contour |
Return
| Type | Description |
|---|---|
| Rect | bounding rectangle |
Canny #
Applies Canny edge detection
method : public : Canny(threshold1:Float, threshold2:Float) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| threshold1 | Float | first threshold for hysteresis procedure |
| threshold2 | Float | second threshold for hysteresis procedure |
Return
| Type | Description |
|---|---|
| Image | edge-detected image |
Example
image := Image->Load("photo.jpg");
gray := image->CvtColor(6);
edges := gray->Canny(50.0, 150.0);
edges->Save("edges.png");Clone #
Creates a deep copy of the image
method : public : Clone() ~ ImageReturn
| Type | Description |
|---|---|
| Image | cloned image |
ContourArea # function
Computes the area of a single contour.
function : ContourArea(contours:Int[], index:Int) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| contours | Int | packed contour data from FindContours() |
| index | Int | index of the contour |
Return
| Type | Description |
|---|---|
| Float | area of the contour |
Convert #
Convert an image to a given byte format
method : public : Convert(format:Image->Format) ~ Byte[]Parameters
| Name | Type | Description |
|---|---|---|
| format | Image->Format | output format |
Return
| Type | Description |
|---|---|
| Byte | converted image bytes |
Example
image := Image->Load("photo.jpg");
png_bytes := image->Convert(Image->Format->PNG);
"PNG bytes: {$png_bytes->Size()}"->PrintLine();Crop #
Crops an image using a rectangle region of interest
method : public : Crop(rect:Rect) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| rect | Rect | bounding rectangle for the crop region |
Return
| Type | Description |
|---|---|
| Image | cropped image |
Example
image := Image->Load("photo.jpg");
region := Rect->New(10, 10, 200, 150);
cropped := image->Crop(region);
cropped->Save("cropped.jpg");CvtColor #
Converts image color space
method : public : CvtColor(code:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| code | Int | color conversion code from ColorConversionCodes |
Return
| Type | Description |
|---|---|
| Image | converted image |
Example
image := Image->Load("photo.jpg");
gray := image->CvtColor(6);
gray->Save("gray.png");Dilate #
Dilates an image using a structuring element
method : public : Dilate(shape:Int, ksize_w:Int, ksize_h:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| shape | Int | structuring element shape from MorphShapes |
| ksize_w | Int | kernel width |
| ksize_h | Int | kernel height |
Return
| Type | Description |
|---|---|
| Image | dilated image |
DrawCircle #
Draws a bounding circle
method : public : DrawCircle(pt:Point, radius:Int, color:Scalar, thickness:Int, type:LineType) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| pt | Point | circle center |
| radius | Int | circle radius |
| color | Scalar | bounding circle color |
| thickness | Int | bounding circle thickness |
| type | LineType | bounding circle type |
Return
| Type | Description |
|---|---|
| Image | updated image |
DrawContours #
Draws contours on the image.
method : public : DrawContours(contours:Int[], contourIdx:Int, color:Scalar, thickness:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| contours | Int | packed contour data from FindContours() |
| contourIdx | Int | index of contour to draw, or -1 to draw all contours |
| color | Scalar | drawing color |
| thickness | Int | line thickness (default 1) |
Return
| Type | Description |
|---|---|
| Image | image with contours drawn |
DrawRectangle #
Draws a bounding rectangle
method : public : DrawRectangle(rect:Rect, color:Scalar, thickness:Int, type:LineType) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| rect | Rect | bounding rectangle |
| color | Scalar | bounding rectangle color |
| thickness | Int | bounding rectangle thickness |
| type | LineType | bounding rectangle type |
Return
| Type | Description |
|---|---|
| Image | updated image |
Example
image := Image->Load("photo.jpg");
box := Rect->New(50, 50, 100, 80);
red := Scalar->New(0.0, 0.0, 255.0);
annotated := image->DrawRectangle(box, red, 2);
annotated->Save("annotated.jpg");DrawText #
Draws text on an image
method : public : DrawText(text:String, font:Font, color:Scalar, thickness:Int, type:LineType) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| text | String | text to draw |
| font | Font | text font |
| color | Scalar | bounding circle color |
| thickness | Int | bounding circle thickness |
| type | LineType | bounding circle type |
Return
| Type | Description |
|---|---|
| Image | updated image |
Example
image := Image->Load("photo.jpg");
white := Scalar->New(255.0, 255.0, 255.0);
labeled := image->DrawText("Hello!", Point->New(10, 30), Font->FONT_HERSHEY_SIMPLEX, 1.0, white);
labeled->Save("labeled.jpg");Erode #
Erodes an image using a structuring element
method : public : Erode(shape:Int, ksize_w:Int, ksize_h:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| shape | Int | structuring element shape from MorphShapes |
| ksize_w | Int | kernel width |
| ksize_h | Int | kernel height |
Return
| Type | Description |
|---|---|
| Image | eroded image |
FindContours #
Finds contours in a binary image. The image should be single-channel (e.g., after CvtColor to grayscale and Threshold). Returns a packed Int[] with format: [count, size0..sizeN-1, x0,y0,x1,y1,...]. Use ContourArea() and BoundingRect() to analyze individual contours.
method : public : FindContours(mode:Int, approx:Int) ~ Int[]Parameters
| Name | Type | Description |
|---|---|---|
| mode | Int | contour retrieval mode from RetrievalModes |
| approx | Int | contour approximation method from ContourApproximationModes |
Return
| Type | Description |
|---|---|
| Int | packed Int[] representing the detected contours |
Flip #
Flips an image
method : public : Flip(flipCode:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| flipCode | Int | 0 for vertical, 1 for horizontal, -1 for both |
Return
| Type | Description |
|---|---|
| Image | flipped image |
Example
image := Image->Load("photo.jpg");
mirrored := image->Flip(1);
mirrored->Save("mirrored.jpg");GaussianBlur #
Applies Gaussian blur to the image
method : public : GaussianBlur(ksize_w:Int, ksize_h:Int, sigmaX:Float) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| ksize_w | Int | kernel width (must be odd) |
| ksize_h | Int | kernel height (must be odd) |
| sigmaX | Float | Gaussian kernel standard deviation in X direction |
Return
| Type | Description |
|---|---|
| Image | blurred image |
Example
image := Image->Load("photo.jpg");
blurred := image->GaussianBlur(5, 5, 1.5);
blurred->Save("blurred.jpg");GetRotationMatrix2D # function
Computes a 2D rotation matrix for an affine transformation.
function : GetRotationMatrix2D(center_x:Float, center_y:Float, angle:Float, scale:Float) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| center_x | Float | x-coordinate of the rotation center |
| center_y | Float | y-coordinate of the rotation center |
| angle | Float | rotation angle in degrees (positive counter-clockwise) |
| scale | Float | isotropic scale factor |
Return
| Type | Description |
|---|---|
| Float | 6-element Float[] representing the 2x3 rotation matrix |
IsEmpty #
Determines if an image is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Load # function
Load image from file
function : Load(image_path:String) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| image_path | String | image file path |
Return
| Type | Description |
|---|---|
| Image | loaded image |
Example
image := Image->Load("photo.jpg");
if(<>image->IsEmpty()) {
"Loaded: {$image->Columns()}x{$image->Rows()}"->PrintLine();
};Load # function
Load image from bytes
function : Load(image_bytes:Byte[]) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| image_bytes | Byte | raw image bytes |
Return
| Type | Description |
|---|---|
| Image | loaded image |
Example
raw := System.IO.Filesystem.FileReader->ReadBinaryFile("photo.jpg");
image := Image->Load(raw);
"Rows: {$image->Rows()}, Cols: {$image->Columns()}"->PrintLine();MedianBlur #
Applies median blur to the image
method : public : MedianBlur(ksize:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| ksize | Int | aperture size (must be odd and greater than 1) |
Return
| Type | Description |
|---|---|
| Image | blurred image |
Example
image := Image->Load("noisy.jpg");
denoised := image->MedianBlur(3);
denoised->Save("denoised.jpg");MorphologyEx #
Applies a morphological operation to an image
method : public : MorphologyEx(op:Int, shape:Int, ksize_w:Int, ksize_h:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| op | Int | morphological operation type from MorphTypes |
| shape | Int | structuring element shape from MorphShapes |
| ksize_w | Int | kernel width |
| ksize_h | Int | kernel height |
Return
| Type | Description |
|---|---|
| Image | processed image |
Normalize #
Normalizes the image for neural network preprocessing. Converts the image to float, normalizes to [0,1], converts BGR to RGB, subtracts the given mean values, and divides by the given std values per channel. Returns the result as a flattened CHW tensor (Float[]).
method : public : Normalize(mean_r:Float, mean_g:Float, mean_b:Float, std_r:Float, std_g:Float, std_b:Float) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| mean_r | Float | mean value for the red channel |
| mean_g | Float | mean value for the green channel |
| mean_b | Float | mean value for the blue channel |
| std_r | Float | standard deviation for the red channel |
| std_g | Float | standard deviation for the green channel |
| std_b | Float | standard deviation for the blue channel |
Return
| Type | Description |
|---|---|
| Float | flattened CHW Float[] tensor suitable for ONNX inference |
Resize #
Resizes an image
method : public : Resize(sz:Size, fx:Float, fy:Float, interpolation:InterpolationFlags) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| sz | Size | image size |
| fx | Float | x-scale factor |
| fy | Float | y-scale factor |
| interpolation | InterpolationFlags | filling missing pixels method |
Return
| Type | Description |
|---|---|
| Image | updated image |
Example
image := Image->Load("photo.jpg");
resized := image->Resize(Size->New(320, 240));
resized->Save("thumb.jpg");Resize #
Resizes an image
method : public : Resize(fx:Float, fy:Float, interpolation:InterpolationFlags) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| fx | Float | x-scale factor |
| fy | Float | y-scale factor |
| interpolation | InterpolationFlags | filling missing pixels method |
Return
| Type | Description |
|---|---|
| Image | updated image |
Resize #
Resizes an image
method : public : Resize(f:Float, ) ~ API.OpenCV.ImageParameters
| Name | Type | Description |
|---|---|---|
| f | Float | scale factor |
Return
| Type | Description |
|---|---|
| Image | updated image |
Save #
Saves an image to file
method : public : Save(path:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| path | String | output file path |
Return
| Type | Description |
|---|---|
| Bool | true if saved successfully, false otherwise |
Example
image := Image->Load("input.jpg");
blurred := image->GaussianBlur(5, 5, 1.5);
if(blurred->Save("output.jpg")) {
"Saved."->PrintLine();
};Show #
Shows an image
method : public : Show(title:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| title | String | dialog title |
Example
image := Image->Load("photo.jpg");
image->Show("Preview");Show #
Shows an image
method : public : Show(title:String, scale:Float) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| title | String | dialog title |
| scale | Float | scaling percentage |
Show #
Shows an image
method : public : Show(title:String, scale:Float, ) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| title | String | dialog title |
| scale | Float | scaling percentage |
Sobel #
Applies Sobel edge detection
method : public : Sobel(ddepth:Int, dx:Int, dy:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| ddepth | Int | desired depth of the destination image (use -1 for same as source) |
| dx | Int | order of the derivative x |
| dy | Int | order of the derivative y |
Return
| Type | Description |
|---|---|
| Image | edge-detected image |
Threshold #
Applies a fixed-level threshold to each array element
method : public : Threshold(thresh:Float, maxval:Float, type:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| thresh | Float | threshold value |
| maxval | Float | maximum value to use with BINARY and BINARY_INV threshold types |
| type | Int | threshold type from ThresholdTypes |
Return
| Type | Description |
|---|---|
| Image | thresholded image |
WarpAffine #
Applies an affine transformation to the image using a 2x3 matrix.
method : public : WarpAffine(matrix:Float[], width:Int, height:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| matrix | Float | 6-element Float[] representing the 2x3 affine matrix (row-major) |
| width | Int | output image width |
| height | Int | output image height |
Return
| Type | Description |
|---|---|
| Image | transformed image |
WarpPerspective #
Applies a perspective transformation to the image using a 3x3 matrix.
method : public : WarpPerspective(matrix:Float[], width:Int, height:Int) ~ ImageParameters
| Name | Type | Description |
|---|---|---|
| matrix | Float | 9-element Float[] representing the 3x3 perspective matrix (row-major) |
| width | Int | output image width |
| height | Int | output image height |
Return
| Type | Description |
|---|---|
| Image | transformed image |