### Get Buffer from Cache Pool Source: https://inspirit.github.io/jsfeat Obtain a temporary buffer from the cache pool for use in calculations. Ensure to return the buffer to the cache when done. ```javascript var size_in_bytes = 640; var temp_buffer = jsfeat.cache.get_buffer(size_in_bytes); var temp_u8 = temp_buffer.u8; // Uint8Array 640 entries // but you also can get other data types // Int32Array but length will be 640/4 = 160 entries var temp_i32 = temp_buffer.i32; // since all buffers comes from data_t instance // you can also use it to construct matrix_t var columns = 320, rows = 240, data_type = jsfeat.U8_t | jsfeat.C1_t; var my_matrix = new jsfeat.matrix_t(columns, rows, data_type, temp_buffer.data); // be careful because you always should provide enough space for matrix ``` -------------------------------- ### Sort Numeric Array Source: https://inspirit.github.io/jsfeat Sort a numeric array in place using a custom comparison function. The sorting is performed between the specified start and end indices. ```javascript // sort numeric array var arr = [10,2,1,0,0,4,6,1,3,8,5,3]; var cmp_numeric = function(a, b) { return (a < b); } jsfeat.math.qsort(arr, 0, arr.length-1, cmp_numeric); ``` -------------------------------- ### Math Utilities Source: https://inspirit.github.io/jsfeat The `jsfeat.math` module provides various utility methods for mathematical operations. ```APIDOC ## Math `JSFEAT` has it's own `jsfeat.math` module, it contains different math utilite methods that can be useful. #### get_gaussian_kernel Calculates gaussian kernel coefficients using specified options: ```javascript var kernel_size = 5, sigma = 0, kernel_array = [], data_type = jsfeat.F32_t; jsfeat.math.get_gaussian_kernel(kernel_size, sigma, kernel_array, data_type); // you can provide zero sigma to determinate it automatically from kernel_size // or set desired value ``` NOTE: setting `data_type` to `jsfeat.U8_t` will result in integer based kernel that can be used to filter `unsigned char` image avoiding floating-point operations. #### qsort Generic sorting method that allows you to specify start and end sorting indices for the source array aswell as provide custom comparison method. Current implementation was derived from *BSD system `qsort()`. ```javascript // sort numeric array var arr = [10,2,1,0,0,4,6,1,3,8,5,3]; var cmp_numeric = function(a, b) { return (a < b); } jsfeat.math.qsort(arr, 0, arr.length-1, cmp_numeric); // sort array of points var point_arr = [ new jsfeat.keypoint_t(1,10), new jsfeat.keypoint_t(5,1), new jsfeat.keypoint_t(33,10), new jsfeat.keypoint_t(0,0), new jsfeat.keypoint_t(8,6), new jsfeat.keypoint_t(3,0)]; // define comparison method to sort points by ascending of y coordinates // and if y's are equal x's should ascend. var cmp_points = function(a, b) { return (a.y < b.y) || (a.y < b.y && a.x < b.x); } jsfeat.math.qsort(point_arr, 0, point_arr.length-1, cmp_points); ``` #### median Calculate median value of provided `Array`, NOTE: input `Array` instance will be modified. ```javascript var arr = [10,2,1,0,0,4,6,1,3,8,5,3]; var median = jsfeat.math.median(arr, 0, arr.length-1); ``` #### perspective_4point_transform Calculates the perspective transform from 4 pairs of the corresponding points. The function calculates the `3x3 Matrix` ```javascript jsfeat.math.perspective_4point_transform(mat:matrix_t, src_x0, src_y0, dst_x0, dst_y0, src_x1, src_y1, dst_x1, dst_y1, src_x2, src_y2, dst_x2, dst_y2, src_x3, src_y3, dst_x3, dst_y3); ``` ``` -------------------------------- ### Allocate and build a pyramid_t Source: https://inspirit.github.io/jsfeat Initialize a pyramid_t structure with a specified number of levels and allocate memory for image matrices. The build method populates the pyramid levels from a source matrix. ```javascript var levels = 3, start_width = 640, start_height = 480, data_type = jsfeat.U8_t | jsfeat.C1_t; var my_pyramid = new jsfeat.pyramid_t(levels); // this will populate data property with matrix_t instances my_pyramid.allocate(start_width, start_height, data_type); var level_0 = my_pyramid.data[0]; // cols = 640, rows = 480 var level_1 = my_pyramid.data[1]; // cols = 320, rows = 240 var level_2 = my_pyramid.data[2]; // cols = 160, rows = 120 // with build method you can draw input source to levels // skip_first_level is true by default my_pyramid.build(source_matrix_t, skip_first_level = true); ``` -------------------------------- ### Prepare and Detect BBF Cascade Source: https://inspirit.github.io/jsfeat Prepares the cascade for Brightness Binary Feature detection and builds an image pyramid. Detection is then run on the pyramid. ```javascript jsfeat.bbf.prepare_cascade(cascade); var img_pyramid:pyramid_t = jsfeat.bbf.build_pyramid(src, min_width, min_height, interval = 4); var rects:Array = jsfeat.bbf.detect(img_pyramid:pyramid_t, cascade); ``` -------------------------------- ### Initialize and access matrix_t properties Source: https://inspirit.github.io/jsfeat Create a matrix_t with specified dimensions and data type, then access its properties like columns, rows, data buffer, type, and channel count. ```javascript var columns = 320, rows = 240, data_type = jsfeat.U8_t | jsfeat.C1_t; var my_matrix = new jsfeat.matrix_t(columns, rows, data_type); // we can access following properties: // my_matrix.cols, my_matrix.rows // my_matrix.data - underlaying array for data holding // to check what type is used for data you can use bit mask: // if(my_matrix.type & jsfeat.U8_t) ... // my_matrix.channel = 1/2/3/4 ``` -------------------------------- ### Initialize matrix_t with pre-allocated data_t Source: https://inspirit.github.io/jsfeat Create a matrix_t using a pre-allocated data_t object, ensuring efficient memory management for matrix data. ```javascript // you can also provide pre-allocated data_t for matrix var columns = 320, rows = 240, data_type = jsfeat.U8_t | jsfeat.C1_t; var data_buffer = new jsfeat.data_t(columns*rows); var my_matrix = new jsfeat.matrix_t(columns, rows, data_type, data_buffer); ``` -------------------------------- ### Configure RANSAC parameters Source: https://inspirit.github.io/jsfeat Create a ransac_params_t object to configure the RANSAC algorithm for motion estimation. Key parameters include the minimum model size, inlier threshold, outlier ratio, and probability of success. ```javascript var model_size = 4; // minimum points to estimate motion var thresh = 3; // max error to classify as inlier var eps = 0.5; // max outliers ratio var prob = 0.99; // probability of success var params = new jsfeat.ransac_params_t(model_size, thresh, eps, prob); ``` -------------------------------- ### Create a JSFEAT matrix_t Source: https://inspirit.github.io/jsfeat Instantiate a matrix_t for image or mathematical operations. Specify dimensions, data type, and an optional pre-allocated buffer. ```javascript var my_matrix = new jsfeat.matrix_t(columns, rows, data_type, data_buffer = undefined); ``` -------------------------------- ### Cache Pool Source: https://inspirit.github.io/jsfeat JSFeat provides a simple cache pool system for managing temporary buffers. Buffers can be acquired using `get_buffer` and must be returned using `put_buffer`. ```APIDOC ## Cache Pool `JSFEAT` has very simple and experimental linked pool based cache system. At the moment I'm not sure if it is really needed since most JavaScript engines have their own powerful caching. But running some tests I noticed that repeatedly calling methods that need temporary `Array`(s) allocation significantly increase its execution time. So replacing allocation with pooled buffers helps to improve performance in some cases. How it works: ```javascript var size_in_bytes = 640; var temp_buffer = jsfeat.cache.get_buffer(size_in_bytes); var temp_u8 = temp_buffer.u8; // Uint8Array 640 entries // but you also can get other data types // Int32Array but length will be 640/4 = 160 entries var temp_i32 = temp_buffer.i32; // since all buffers comes from data_t instance // you can also use it to construct matrix_t var columns = 320, rows = 240, data_type = jsfeat.U8_t | jsfeat.C1_t; var my_matrix = new jsfeat.matrix_t(columns, rows, data_type, temp_buffer.data); // be careful because you always should provide enough space for matrix ``` NOTE: you always need to put buffer back to cache pool after you are done: ```javascript jsfeat.cache.put_buffer(temp_buffer); ``` At the moment the number of temporary buffers is fixed to 30 entries. I cant hardly imagine scenario where you may need more buffers. If the whole idea having `cache` pool will prove its usefulness we can extend it to different data types and add auto extending functionality. ``` -------------------------------- ### BBF Prepare Cascade Source: https://inspirit.github.io/jsfeat Prepares the cascade data for Brightness Binary Feature (BBF) detection. This step is needed once to create a local copy of features. ```APIDOC ## jsfeat.bbf.prepare_cascade ### Description This step is needed only once to create a local copy of features to prevent multiple Array relocations during detection. ### Parameters - **cascade** (object) - The cascade data to prepare. ``` -------------------------------- ### Create a keypoint_t Source: https://inspirit.github.io/jsfeat Instantiate a keypoint_t object to represent a 2D point with associated score and level information. All arguments default to zero if not provided. ```javascript // all arguments are zero by default var my_point = new jsfeat.keypoint_t(x = 0, y = 0, score = 0, level = 0); ``` -------------------------------- ### jsfeat.linalg.svd_invert Source: https://inspirit.github.io/jsfeat This routine calculates the pseudo-inverse of the matrix `A`. ```APIDOC ## jsfeat.linalg.svd_invert ### Description This routine calculates the pseudo-inverse of the matrix `A`. ### Method ``` // inverts matrix A to matrix Ainvert jsfeat.linalg.svd_invert(Ainvert:matrix_t, A:matrix_t); ``` ``` -------------------------------- ### jsfeat.linalg.svd_decompose Source: https://inspirit.github.io/jsfeat This routine decomposes an `rows x cols` matrix `A`, into a product of the three matrices `U`, `W`, and `V'`, i.e. `A = UWV'`, where `U` is an `rows x rows` matrix whose columns are orthogonal, `W` is a `1 x cols` matrix, and `V` is an `cols x cols` orthogonal matrix. ```APIDOC ## jsfeat.linalg.svd_decompose ### Description This routine decomposes an `rows x cols` matrix `A`, into a product of the three matrices `U`, `W`, and `V'`, i.e. `A = UWV'`, where `U` is an `rows x rows` matrix whose columns are orthogonal, `W` is a `1 x cols` matrix, and `V` is an `cols x cols` orthogonal matrix. ### Method ``` // U - the left orthogonal matrix // W - vector of singular values // V - the right orthogonal matrix // options - jsfeat.SVD_U_T and/or jsfeat.SVD_V_T to return transposed U and/or V jsfeat.linalg.svd_decompose(A:matrix_t, W:matrix_t, U:matrix_t, V:matrix_t, options); ``` ``` -------------------------------- ### BBF Detect Objects Source: https://inspirit.github.io/jsfeat Runs the Brightness Binary Feature (BBF) detection algorithm on the image pyramid. ```APIDOC ## jsfeat.bbf.detect ### Description Runs detection using the Brightness Binary Feature algorithm. ### Parameters - **img_pyramid** (pyramid_t) - The image pyramid generated by `build_pyramid`. - **cascade** (object) - The prepared cascade data. ### Returns - **rects** (Array) - Rectangles representing detected objects. ``` -------------------------------- ### Create and use data_t wrapper Source: https://inspirit.github.io/jsfeat Instantiate a data_t wrapper for an ArrayBuffer, providing convenient access to typed arrays (Uint8Array, Int32Array, Float32Array) for interpreting the underlying data. ```javascript // you can provide preallocated ArrayBuffer var my_data = new jsfeat.data_t(size_in_bytes, buffer = undefined); var my_data_buffer = my_data.buffer; // ArrayBuffer var u8_data = my_data.u8; // Uint8Array var i32_data = my_data.i32; // Int32Array var f32_data = my_data.f32; // Float32Array ``` -------------------------------- ### YAPE Feature Detection Source: https://inspirit.github.io/jsfeat Initializes and performs feature detection using the YAPE algorithm. Requires initialization with image dimensions and parameters before detection. Preallocate keypoint_t array. ```javascript 1. var corners = [], 2. image_width = img.cols, image_height = img.rows, 3. radius = 5, pyramid_levels = 1; // for now only single level support 4. 5. // YAPE needs init before running detection 6. jsfeat.yape.init(image_width, image_height, radius, pyramid_levels); 7. 8. // you should use preallocated keypoint_t array 9. for(var i = 0; i < img.cols*img.rows, ++i) { 10. corners[i] = new jsfeat.keypoint_t(0,0,0,0); 11. } 12. 13. // perform detection 14. // returns the amount of detected corners 15. var count = jsfeat.yape.detect(img:matrix_t, corners:Array, border = 4); ``` -------------------------------- ### BBF Build Pyramid Source: https://inspirit.github.io/jsfeat Builds an image pyramid using canvas drawImage for BBF detection. This creates scaled versions of the source image. ```APIDOC ## jsfeat.bbf.build_pyramid ### Description Builds an image pyramid using canvas drawImage. ### Parameters - **src** (matrix_t) - Source grayscale matrix (U8_t|C1_t). - **min_width** (number) - Minimum width to scale pyramid to. - **min_height** (number) - Minimum height to scale pyramid to. - **interval** (number) - Number of original scale levels in pyramid (default: 4). ### Returns - **img_pyramid** (pyramid_t) - The generated image pyramid. ``` -------------------------------- ### jsfeat.motion_model.affine2d Source: https://inspirit.github.io/jsfeat This kernel calculates the affine transform from corresponding points. The function calculates the `3x3 Matrix` ```APIDOC ## jsfeat.motion_model.affine2d ### Description This kernel calculates the affine transform from corresponding points. The function calculates the `3x3 Matrix` ### Method ``` // create affine kernel // you can reuse it for different point sets var affine_kernel = new jsfeat.motion_model.affine2d(); var affine_transform = new jsfeat.matrix_t(3, 3, jsfeat.F32_t | jsfeat.C1_t); var count = 33; var from = []; var to = [];   for(var i = 0; i < count; ++i) { // you can use keypoint_t structure // or just provide object with x and y properties from[i] = { "x":Math.random()*320, "y":Math.random()*240 }; to[i] = { "x":from[i].x + 5, "y":from[i].y+5 }; } affine_kernel.run(from, to, affine_transform, count);   // you can also calculate transform error for each point var error = new jsfeat.matrix_t(count, 1, jsfeat.F32_t | jsfeat.C1_t); affine_kernel.error(from, to, affine_transform, error.data, count); ``` ``` -------------------------------- ### jsfeat.matmath.multiply_3x3 Source: https://inspirit.github.io/jsfeat Quick 3x3 matrix multiplication. Can operate inplace. ```APIDOC ## jsfeat.matmath.multiply_3x3 ### Description Quick 3x3 matrix multiplication. Can operate inplace. ### Method ``` jsfeat.matmath.multiply_3x3(C:matrix_t, A:matrix_t, B:matrix_t); ``` ``` -------------------------------- ### Calculate Pseudo-Inverse using SVD Source: https://inspirit.github.io/jsfeat Calculates the pseudo-inverse of matrix A using SVD. ```javascript // inverts matrix A to matrix Ainvert jsfeat.linalg.svd_invert(Ainvert:matrix_t, A:matrix_t); ``` -------------------------------- ### Matrix Math Source: https://inspirit.github.io/jsfeat Provides generalized matrix operations for linear algebra tasks. ```APIDOC ## Matrix Math Various generalized matrix operations. #### transpose Transposes a matrix. ```javascript jsfeat.matmath.transpose(At:matrix_t, A:matrix_t); ``` #### multiply Performs matrix multiplication. ```javascript jsfeat.matmath.multiply(C:matrix_t, A:matrix_t, B:matrix_t); ``` #### multiply_ABt Post multiply the `nrows x ncols` matrix `A` by the transpose of the `mrows x ncols` matrix `B` to form the `nrows x mrows` matrix `C`, i.e. `C = A*B'`. ```javascript jsfeat.matmath.multiply_ABt(C:matrix_t, A:matrix_t, B:matrix_t); ``` #### multiply_AtB Post multiply the transpose of the `nrows x ncols` matrix `A` by the `nrows x mcols` matrix `B` to form the `ncols x mcols` matrix `C`, i.e. `C = A'*B`. ```javascript jsfeat.matmath.multiply_AtB(C:matrix_t, A:matrix_t, B:matrix_t); ``` ``` -------------------------------- ### Multiply Transpose by Matrix (A'*A) Source: https://inspirit.github.io/jsfeat Pre-multiplies matrix A by its transpose, resulting in a square symmetric matrix C. C = A'*A. ```javascript jsfeat.matmath.multiply_AtA(C:matrix_t, A:matrix_t); ``` -------------------------------- ### Multiply Matrix by its Transpose (A*A') Source: https://inspirit.github.io/jsfeat Post-multiplies matrix A by its transpose, resulting in a square symmetric matrix C. C = A*A'. ```javascript jsfeat.matmath.multiply_AAt(C:matrix_t, A:matrix_t); ``` -------------------------------- ### jsfeat.matmath.mat3x3_determinant Source: https://inspirit.github.io/jsfeat Calculate 3x3 matrix determinant. ```APIDOC ## jsfeat.matmath.mat3x3_determinant ### Description Calculate 3x3 matrix determinant. ### Method ``` var determinant = jsfeat.matmath.mat3x3_determinant(M:matrix_t); ``` ``` -------------------------------- ### Compute Sobel Derivatives Source: https://inspirit.github.io/jsfeat Computes image gradients using the Sobel kernel. The result is stored as a sequence of [gx, gy] pairs in a 2-channel matrix. ```javascript // result is written as [gx0,gy0,gx1,gy1, ...] sequence in 2 channel matrix_t jsfeat.imgproc.sobel_derivatives(source:matrix_t, dest:matrix_t); ``` -------------------------------- ### jsfeat.linalg.lu_solve Source: https://inspirit.github.io/jsfeat Solves the system of linear equations `Ax = B` using Gaussian elimination with optimal pivot element chosen. NOTE: input `matrix_t` instances will be modified and result output in matrix `B`. ```APIDOC ## jsfeat.linalg.lu_solve ### Description Solves the system of linear equations `Ax = B` using Gaussian elimination with optimal pivot element chosen. NOTE: input `matrix_t` instances will be modified and result output in matrix `B`. ### Method ``` // A and B modified and result output in B jsfeat.linalg.lu_solve(A:matrix_t, B:matrix_t); ``` ``` -------------------------------- ### Resize a matrix_t Source: https://inspirit.github.io/jsfeat Dynamically resize an existing matrix_t instance. Note that resizing to a larger dimension will discard the current data. ```javascript my_matrix.resize(new_cols, new_rows, new_channels); ``` -------------------------------- ### jsfeat.matmath.invert_3x3 Source: https://inspirit.github.io/jsfeat Quick inverse of 3x3 matrix. Can operate inplace. ```APIDOC ## jsfeat.matmath.invert_3x3 ### Description Quick inverse of 3x3 matrix. Can operate inplace. ### Method ``` jsfeat.matmath.invert_3x3(from:matrix_t, to:matrix_t); ``` ``` -------------------------------- ### jsfeat.matmath.multiply_AAt Source: https://inspirit.github.io/jsfeat Post multiply an `nrows x ncols` matrix `A` by its transpose. The result is an `nrows x nrows` square symmetric matrix `C`, i.e. `C = A*A'`. ```APIDOC ## jsfeat.matmath.multiply_AAt ### Description Post multiply an `nrows x ncols` matrix `A` by its transpose. The result is an `nrows x nrows` square symmetric matrix `C`, i.e. `C = A*A'`. ### Method ``` jsfeat.matmath.multiply_AAt(C:matrix_t, A:matrix_t); ``` ``` -------------------------------- ### Solve Linear System using LU Decomposition Source: https://inspirit.github.io/jsfeat Solves the system of linear equations Ax = B using Gaussian elimination with optimal pivoting. Note that input matrices A and B will be modified, with the result output in B. ```javascript // A and B modified and result output in B jsfeat.linalg.lu_solve(A:matrix_t, B:matrix_t); ``` -------------------------------- ### FAST Corner Detection Source: https://inspirit.github.io/jsfeat Detects corners in an image using the FAST algorithm. Requires pre-allocating a keypoint array and setting a threshold. ```javascript // threshold on difference between intensity of the central pixel // and pixels of a circle around this pixel var threshold = 20; jsfeat.fast_corners.set_threshold(threshold); var corners = [], border = 3; // you should use preallocated keypoint_t array for(var i = 0; i < img.cols*img.rows, ++i) { corners[i] = new jsfeat.keypoint_t(0,0,0,0); } // perform detection // returns the amount of detected corners var count = jsfeat.fast_corners.detect(img:matrix_t, corners:Array, border = 3); ``` -------------------------------- ### pyrdown Source: https://inspirit.github.io/jsfeat Downsamples a single-channel image to a destination matrix using a simple 4-pixel average. ```APIDOC ## pyrdown ### Description Downsample `source` to `dest` writing simple 4 pix average value. Works with single channel only. ### Method jsfeat.imgproc.pyrdown ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the downsampled image. ``` -------------------------------- ### Estimate Homography with RANSAC Source: https://inspirit.github.io/jsfeat Estimates a homography transformation using the RANSAC algorithm to handle incorrect correspondences. Requires a minimum number of points, a threshold for inlier error, and outlier ratio. ```javascript var ransac = jsfeat.motion_estimator.ransac; var homo_kernel = new jsfeat.motion_model.homography2d(); var transform = new jsfeat.matrix_t(3, 3, jsfeat.F32_t | jsfeat.C1_t); var count = 333; var from = []; var to = []; for(var i = 0; i < count; ++i) { from[i] = { "x":Math.random()*320, "y":Math.random()*240 }; to[i] = { "x":from[i].x + Math.random()*5, "y":from[i].y+Math.random()*5 }; } var mask = new jsfeat.matrix_t(count, 1, jsfeat.U8_t | jsfeat.C1_t); var model_size = 4; var thresh = 3; var eps = 0.5; var prob = 0.99; var params = new jsfeat.ransac_params_t(model_size, thresh, eps, prob); var max_iters = 1000; var ok = ransac(params, homo_kernel, from, to, count, transform, mask, max_iters); ``` -------------------------------- ### jsfeat.linalg.eigenVV Source: https://inspirit.github.io/jsfeat Computes eigenvalues and eigenvectors of a symmetric matrix. ```APIDOC ## jsfeat.linalg.eigenVV ### Description Computes eigenvalues and eigenvectors of a symmetric matrix. ### Method ``` jsfeat.linalg.eigenVV(A:matrix_t, EigenVectors:matrix_t, EigenValues:matrix_t); // you can ask for Vectors or Values only jsfeat.linalg.eigenVV(A:matrix_t, null, EigenValues:matrix_t); jsfeat.linalg.eigenVV(A:matrix_t, EigenVectors:matrix_t, null); ``` ``` -------------------------------- ### Downsample Image (Pyrdown) Source: https://inspirit.github.io/jsfeat Downsamples a single-channel source image to a destination image by averaging 4 pixels. Works with single channel data only. ```javascript jsfeat.imgproc.pyrdown(source:matrix_t, dest:matrix_t); ``` -------------------------------- ### Multiply Transpose of Matrix by Another Source: https://inspirit.github.io/jsfeat Compute C = A' * B, where A is an nrows x ncols matrix and B is an nrows x mcols matrix. ```javascript jsfeat.matmath.multiply_AtB(C:matrix_t, A:matrix_t, B:matrix_t); ``` -------------------------------- ### Return Buffer to Cache Pool Source: https://inspirit.github.io/jsfeat Return a temporary buffer to the cache pool after it is no longer needed. This is crucial for efficient memory management. ```javascript jsfeat.cache.put_buffer(temp_buffer); ``` -------------------------------- ### Solve Linear System using SVD Source: https://inspirit.github.io/jsfeat Solves the system of linear equations Ax = B using Singular Value Decomposition (SVD). This method can handle over-defined systems and singular matrices. ```javascript // A - left-hand side of the system // B - right-hand side of the system // X - output solution jsfeat.linalg.svd_solve(A:matrix_t, X:matrix_t, B:matrix_t); ``` -------------------------------- ### Multiply Matrix by Transpose of Another Source: https://inspirit.github.io/jsfeat Compute C = A * B', where A is an nrows x ncols matrix and B is an mrows x ncols matrix. ```javascript jsfeat.matmath.multiply_ABt(C:matrix_t, A:matrix_t, B:matrix_t); ``` -------------------------------- ### jsfeat.linalg.svd_solve Source: https://inspirit.github.io/jsfeat Solves the system of linear equations `Ax = B` using Singular value decomposition (SVD) method; the system can be over-defined and/or the matrix `A` can be singular. ```APIDOC ## jsfeat.linalg.svd_solve ### Description Solves the system of linear equations `Ax = B` using Singular value decomposition (SVD) method; the system can be over-defined and/or the matrix `A` can be singular. ### Method ``` // A - left-hand side of the system // B - right-hand side of the system // X - output solution jsfeat.linalg.svd_solve(A:matrix_t, X:matrix_t, B:matrix_t); ``` ``` -------------------------------- ### fast_corners Source: https://inspirit.github.io/jsfeat Detects corners in an image using the FAST algorithm. Requires pre-allocated keypoint_t array. ```APIDOC ## fast_corners ### Description Detects corners using the `FAST` algorithm. ### Method jsfeat.fast_corners.detect ### Parameters - **img**: matrix_t - The source image matrix. - **corners**: Array - Pre-allocated array of `keypoint_t` to store detected corners. - **border**: number - Optional. Border size around the image to consider. Defaults to 3. ``` -------------------------------- ### jsfeat.matmath.multiply_AtA Source: https://inspirit.github.io/jsfeat Pre multiply an `nrows x ncols` matrix `A` by its transpose. The result is an `ncols x ncols` square symmetric matrix `C`, i.e. `C = A'*A`. ```APIDOC ## jsfeat.matmath.multiply_AtA ### Description Pre multiply an `nrows x ncols` matrix `A` by its transpose. The result is an `ncols x ncols` square symmetric matrix `C`, i.e. `C = A'*A`. ### Method ``` jsfeat.matmath.multiply_AtA(C:matrix_t, A:matrix_t); ``` ``` -------------------------------- ### Invert 3x3 Matrix Source: https://inspirit.github.io/jsfeat Performs a quick inversion of a 3x3 matrix. This operation can be performed in-place. ```javascript jsfeat.matmath.invert_3x3(from:matrix_t, to:matrix_t); ``` -------------------------------- ### sobel_derivatives Source: https://inspirit.github.io/jsfeat Computes the image gradient using the Sobel kernel for single-channel images. ```APIDOC ## sobel_derivatives ### Description Compute gradient using Sobel kernel `[1 2 1] * [-1 0 1]^T`. Works with single channel only. ### Method jsfeat.imgproc.sobel_derivatives ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the gradient. Result is written as [gx0,gy0,gx1,gy1, ...] sequence in a 2-channel matrix_t. ``` -------------------------------- ### Transpose Matrix Source: https://inspirit.github.io/jsfeat Compute the transpose of a matrix A and store it in matrix At. ```javascript jsfeat.matmath.transpose(At:matrix_t, A:matrix_t); ``` -------------------------------- ### Decompose Matrix using SVD Source: https://inspirit.github.io/jsfeat Decomposes matrix A into U, W, and V' matrices (A = UWV'). U and V are orthogonal matrices, and W contains singular values. Options can be provided to return transposed U and/or V. ```javascript // U - the left orthogonal matrix // W - vector of singular values // V - the right orthogonal matrix // options - jsfeat.SVD_U_T and/or jsfeat.SVD_V_T to return transposed U and/or V jsfeat.linalg.svd_decompose(A:matrix_t, W:matrix_t, U:matrix_t, V:matrix_t, options); ``` -------------------------------- ### Perspective 4-Point Transform Source: https://inspirit.github.io/jsfeat Calculate a 3x3 perspective transform matrix from four pairs of corresponding source and destination points. ```javascript jsfeat.math.perspective_4point_transform(mat:matrix_t, src_x0, src_y0, dst_x0, dst_y0, src_x1, src_y1, dst_x1, dst_y1, src_x2, src_y2, dst_x2, dst_y2, src_x3, src_y3, dst_x3, dst_y3); ``` -------------------------------- ### Solve Linear System using Cholesky Factorization Source: https://inspirit.github.io/jsfeat Solves the system of linear equations Ax = B using Cholesky factorization. The matrix A must be symmetric and positively defined. Note that input matrices A and B will be modified, with the result output in B. ```javascript // A and B modified and result output in B jsfeat.linalg.cholesky_solve(A:matrix_t, B:matrix_t); ``` -------------------------------- ### Calculate Affine Transform Source: https://inspirit.github.io/jsfeat Calculates the affine transform (3x3 matrix) from corresponding point sets. The kernel can be reused for different point sets. It also provides a method to calculate the transform error for each point. ```javascript // create affine kernel // you can reuse it for different point sets var affine_kernel = new jsfeat.motion_model.affine2d(); var affine_transform = new jsfeat.matrix_t(3, 3, jsfeat.F32_t | jsfeat.C1_t); var count = 33; var from = []; var to = [];   for(var i = 0; i < count; ++i) { // you can use keypoint_t structure // or just provide object with x and y properties from[i] = { "x":Math.random()*320, "y":Math.random()*240 }; to[i] = { "x":from[i].x + 5, "y":from[i].y+5 }; } affine_kernel.run(from, to, affine_transform, count);   // you can also calculate transform error for each point var error = new jsfeat.matrix_t(count, 1, jsfeat.F32_t | jsfeat.C1_t); affine_kernel.error(from, to, affine_transform, error.data, count); ``` -------------------------------- ### Lucas-Kanade Optical Flow Tracking Source: https://inspirit.github.io/jsfeat Tracks sparse features using the Lucas-Kanade method with pyramids. Requires previous and current frame pyramids, input/output coordinate arrays, and configuration parameters. The status array indicates if flow was found for each feature. ```javascript 1. /* 2. prev_pyr - previous frame 8-bit pyramid_t 3. curr_pyr - current frame 8-bit pyramid_t 4. prev_xy - Array of 2D coordinates for which the flow needs to be found 5. curr_xy - Array of 2D coordinates containing the calculated new positions 6. count - number of input coordinates 7. win_size - size of the search window at each pyramid level 8. max_iter - stop searching after the specified maximum number of iterations 9. status - each element is set to 1 if the flow for the corresponding features 10. has been found overwise 0 11. eps - stop searching when the search window moves by less than eps 12. min_eigen_threshold - the algorithm calculates the minimum eigen value of a 2x2 13. normal matrix of optical flow equations, divided by number of 14. pixels in a window; if this value is less than min_eigen_threshold, 15. then a corresponding feature is filtered out and its flow is not 16. processed, it allows to remove bad points and get a performance boost 17. */ 18. 19. jsfeat.optical_flow_lk.track(prev_pyr:pyramid_t, curr_pyr:pyramid_t, 20. prev_xy:Array, curr_xy:Array, count, 21. win_size, max_iter = 30, status:Array = null, 22. eps = 0.01, min_eigen_threshold = 0.0001); ``` -------------------------------- ### ORB Descriptor Generation Source: https://inspirit.github.io/jsfeat Generates ORB descriptors for detected corners. Requires a preallocated matrix_t for descriptors. ```javascript 1. var corners = []; // jsfeat.keypoint_t Array 2. 3. var cols = 32; // 32 Bytes / 256 BIT descriptor 4. var rows = num_corners; // descriptors stored per row 5. var descriptors = new jsfeat.matrix_t(cols, rows, jsfeat.U8_t | jsfeat.C1_t); 6. 7. jsfeat.orb.describe(img_u8:matrix_t, corners:Array, num_corners, descriptors:matrix_t); ``` -------------------------------- ### Convert RGBA Image to Grayscale Source: https://inspirit.github.io/jsfeat Converts an RGBA image data to grayscale using the formula Y = 0.299*R + 0.587*G + 0.114*B. Specify the source input channel order. ```javascript var image_data = context2d.getImageData(0, 0, width, height); var gray_img = new jsfeat.matrix_t(width, height, jsfeat.U8_t | jsfeat.C1_t); var code = jsfeat.COLOR_RGBA2GRAY; jsfeat.imgproc.grayscale(image_data.data, width, height, gray_img, code); ``` -------------------------------- ### Warp Perspective Transformation Source: https://inspirit.github.io/jsfeat Applies a perspective transformation to a single-channel image using a 3x3 matrix. Sampling is done in reverse (destination to source) to avoid artifacts. ```javascript jsfeat.imgproc.warp_perspective(source:matrix_t, dest:matrix_t, warp_mat:matrix_t, fill_value = 0); ``` -------------------------------- ### Compute Scharr Derivatives Source: https://inspirit.github.io/jsfeat Computes image gradients using the Scharr kernel. The result is stored as a sequence of [gx, gy] pairs in a 2-channel matrix. ```javascript // result is written as [gx0,gy0,gx1,gy1, ...] sequence in 2 channel matrix_t jsfeat.imgproc.scharr_derivatives(source:matrix_t, dest:matrix_t); ``` -------------------------------- ### gaussian_blur Source: https://inspirit.github.io/jsfeat Applies a Gaussian blur to a single-channel grayscale image. Kernel size or sigma can be specified. ```APIDOC ## gaussian_blur ### Description Works with single channel data only. You can choose between providing `kernel_size` or `sigma` argument or both. ### Method jsfeat.imgproc.gaussian_blur ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the blurred image. - **kernel_size**: number - The size of the Gaussian kernel. - **sigma**: number - Optional. The standard deviation for the Gaussian kernel. Defaults to 0. ``` -------------------------------- ### Warp Affine Transformation Source: https://inspirit.github.io/jsfeat Applies an affine transformation to a single-channel image using a 2x3 or 3x3 matrix. Sampling is done in reverse (destination to source) to avoid artifacts. ```javascript jsfeat.imgproc.warp_affine(source:matrix_t, dest:matrix_t, warp_mat:matrix_t, fill_value = 0); ``` -------------------------------- ### warp_affine Source: https://inspirit.github.io/jsfeat Applies an affine transformation to a single-channel image using a 2x3 or 3x3 matrix. Mapping is done in reverse to avoid sampling artifacts. ```APIDOC ## warp_affine ### Description Applies an affine transformation to an image using `2x3 or 3x3 Matrix`. Single channel source only. To avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel of the destination image, the functions compute coordinates of the corresponding “donor” pixel in the source image and copy the pixel value. ### Method jsfeat.imgproc.warp_affine ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the transformed image. - **warp_mat**: matrix_t - The 2x3 or 3x3 affine transformation matrix. - **fill_value**: number - Optional. The value to fill pixels outside the source image. Defaults to 0. ``` -------------------------------- ### Compute Integral Image Source: https://inspirit.github.io/jsfeat Calculates integral images (sum, squared sum, tilted sum) for a single-channel source image. Destination arrays should be one pixel larger than the source. ```javascript jsfeat.imgproc.compute_integral_image(source:matrix_t, sum:Array, sqsum:Array, tilted:Array); ``` -------------------------------- ### Resample Matrix Data Source: https://inspirit.github.io/jsfeat Generic method to resize a matrix_t. For performance-critical applications or multiple resizes, consider using the canvas's built-in drawImage method. ```javascript jsfeat.imgproc.resample(source:matrix_t, dest:matrix_t, new_width, new_height); ``` -------------------------------- ### warp_perspective Source: https://inspirit.github.io/jsfeat Applies a perspective transformation to a single-channel image using a 3x3 matrix. Mapping is done in reverse to avoid sampling artifacts. ```APIDOC ## warp_perspective ### Description Applies a perspective transformation to an image using `3x3 Matrix`. Single channel source only. To avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel of the destination image, the functions compute coordinates of the corresponding “donor” pixel in the source image and copy the pixel value. ### Method jsfeat.imgproc.warp_perspective ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the transformed image. - **warp_mat**: matrix_t - The 3x3 perspective transformation matrix. - **fill_value**: number - Optional. The value to fill pixels outside the source image. Defaults to 0. ``` -------------------------------- ### Compute Eigenvalues and Eigenvectors Source: https://inspirit.github.io/jsfeat Computes eigenvalues and eigenvectors of a symmetric matrix. Can compute only vectors or only values by passing null for the other parameter. ```javascript jsfeat.linalg.eigenVV(A:matrix_t, EigenVectors:matrix_t, EigenValues:matrix_t); ``` ```javascript // you can ask for Vectors or Values only jsfeat.linalg.eigenVV(A:matrix_t, null, EigenValues:matrix_t); ``` ```javascript jsfeat.linalg.eigenVV(A:matrix_t, EigenVectors:matrix_t, null); ``` -------------------------------- ### Box Blur Grayscale Image Source: https://inspirit.github.io/jsfeat Applies a box blur to a single-channel grayscale image. Ensure the destination matrix is of type `jsfeat.S32_t` if `jsfeat.BOX_BLUR_NOSCALE` is used to handle accumulated values. ```javascript jsfeat.imgproc.box_blur_gray(source:matrix_t, dest:matrix_t, radius, options = 0); ``` -------------------------------- ### Estimate Affine Transform with LMEDS Source: https://inspirit.github.io/jsfeat Estimates an affine transformation using the Least Median of Squares algorithm, which is robust to outliers by minimizing the median error. Requires a minimum number of points and an epsilon for outlier ratio. ```javascript var lmeds = jsfeat.motion_estimator.lmeds; var affine_kernel = new jsfeat.motion_model.affine2d(); var transform = new jsfeat.matrix_t(3, 3, jsfeat.F32_t | jsfeat.C1_t); var count = 333; var from = []; var to = []; for(var i = 0; i < count; ++i) { from[i] = { "x":Math.random()*320, "y":Math.random()*240 }; to[i] = { "x":from[i].x + Math.random()*5, "y":from[i].y+Math.random()*5 }; } var mask = new jsfeat.matrix_t(count, 1, jsfeat.U8_t | jsfeat.C1_t); var model_size = 3; var thresh = 0; var eps = 0.45; var prob = 0.99; var params = new jsfeat.ransac_params_t(model_size, thresh, eps, prob); var max_iters = 1000; var ok = lmeds(params, affine_kernel, from, to, count, transform, mask, max_iters); ``` -------------------------------- ### scharr_derivatives Source: https://inspirit.github.io/jsfeat Computes the image gradient using the Scharr kernel for single-channel images. ```APIDOC ## scharr_derivatives ### Description Compute gradient using Scharr kernel `[3 10 3] * [-1 0 1]^T`. Works with single channel only. ### Method jsfeat.imgproc.scharr_derivatives ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the gradient. Result is written as [gx0,gy0,gx1,gy1, ...] sequence in a 2-channel matrix_t. ``` -------------------------------- ### Calculate Gaussian Kernel Source: https://inspirit.github.io/jsfeat Compute Gaussian kernel coefficients. A sigma of 0 allows automatic determination from kernel size. Use jsfeat.U8_t for integer-based kernels suitable for unsigned char images. ```javascript var kernel_size = 5, sigma = 0, kernel_array = [], data_type = jsfeat.F32_t; jsfeat.math.get_gaussian_kernel(kernel_size, sigma, kernel_array, data_type); // you can provide zero sigma to determinate it automatically from kernel_size // or set desired value ``` -------------------------------- ### Calculate Homography Transformation Source: https://inspirit.github.io/jsfeat Calculates a 3x3 perspective transform matrix between two sets of 2D points. Can be reused for different point sets. Also calculates the error for each point. ```javascript var homo_kernel = new jsfeat.motion_model.homography2d(); var homo_transform = new jsfeat.matrix_t(3, 3, jsfeat.F32_t | jsfeat.C1_t); var count = 33; var from = []; var to = []; for(var i = 0; i < count; ++i) { from[i] = { "x":Math.random()*320, "y":Math.random()*240 }; to[i] = { "x":from[i].x + 5, "y":from[i].y+5 }; } homo_kernel.run(from, to, homo_transform, count); var error = new jsfeat.matrix_t(count, 1, jsfeat.F32_t | jsfeat.C1_t); homo_kernel.error(from, to, homo_transform, error.data, count); ``` -------------------------------- ### YAPE06 Feature Detection Source: https://inspirit.github.io/jsfeat Detects features using Laplacian and minimum eigen value thresholds. Ensure thresholds are set before detection and preallocate keypoint_t array. ```javascript 1. var corners = [], 2. laplacian_threshold = 30, 3. min_eigen_value_threshold = 25; 4. 5. // choose threshold values 6. jsfeat.yape06.laplacian_threshold = laplacian_threshold; 7. jsfeat.yape06.min_eigen_value_threshold = min_eigen_value_threshold; 8. 9. // you should use preallocated keypoint_t array 10. for(var i = 0; i < img.cols*img.rows, ++i) { 11. corners[i] = new jsfeat.keypoint_t(0,0,0,0); 12. } 13. 14. // perform detection 15. // returns the amount of detected corners 16. var count = jsfeat.yape06.detect(img:matrix_t, corners:Array, border = 5); ``` -------------------------------- ### box_blur_gray Source: https://inspirit.github.io/jsfeat Applies a box blur to a single-channel grayscale image. Options can be provided to control scaling. ```APIDOC ## box_blur_gray ### Description Works with single channel data only. NOTE: if input is `jsfeat.U8_t` and `options = jsfeat.BOX_BLUR_NOSCALE` dest should be at least `jsfeat.S32_t` to handle accumulated values correctly. ### Method jsfeat.imgproc.box_blur_gray ### Parameters - **source**: matrix_t - The source image matrix. - **dest**: matrix_t - The destination matrix to store the blurred image. - **radius**: number - The blur radius. - **options**: number - Optional. Can be `jsfeat.BOX_BLUR_NOSCALE` to avoid result values scaling. Defaults to 0. ```