Overview of ImageJS Operations and Methods
threshold method is used to convert an Image to a Mask, and watershed is used to create a Region of Interest (ROI) map.website·Indexed 32 days ago
https://docs.image-js.orgA versatile TypeScript library for image processing and analysis. It provides tools for image transformations, morphology (including Canny edge detection and bottom-hat), image segmentation using watershed and threshold operations, and detailed Regions of Interest (ROI) analysis such as solidity, sphericity, and convex hull.
threshold method is used to convert an Image to a Mask, and watershed is used to create a Region of Interest (ROI) map.holesInfo() method of the ROI class provides information about the holes within a region of interest. It returns an object containing the total number of holes and their combined surface area measured in pixels. This data is useful for calculating the fill ratio and analyzing the overall form of the ROI.const holesInfo = roi.holesInfo();NewValue = sqrt(Value1^2 + Value2^2). This is primarily used for image alignment, feature matching, and identifying corresponding points between images in computer vision applications.To localize and store data about regions of interest (ROI) identified in a binary mask, use the fromMask() function. This returns a RoiMapManager (or RoiMap) object.
Configuration:
allowCorners (boolean): Determines if regions connected only by corners are treated as a single region or separate regions. Defaults to false.import fromMask from 'image-js';
// Basic usage
const roiMap = fromMask(mask);
// Usage with allowCorners option
const roiMapWithCorners = fromMask(mask, { allowCorners: true });out parameter will throw an error if the provided image is incompatible with the required dimensions or color model. Additionally, some functions that change the image's fundamental properties (such as convertColor) cannot use the source image as the out target because the color model change is incompatible with the existing object.// Example 1: Dimension mismatch
let image2 = new Image(1, 3, { colorModel: 'RGB' });
let testImage = new Image(3, 3, { colorModel: 'GREY' });
// Throws: `cannot use out image. Its width property must be 3. Received 1`
testImage = testImage.invert({ out: image2 });
// Example 2: Color model change incompatibility
let image1 = testUtils.createGreyImage([[1, 1, 1]]);
// Throws error because source cannot be target when changing color model
image1 = image1.convertColor('RGB', { out: image1 });The gradientFilter method highlights edges and boundaries by calculating the rate of change in pixel intensities. It is a fundamental tool for edge detection, object recognition, and image segmentation. Because gradient filters are sensitive to noise, it is recommended to smooth the image (e.g., using a Gaussian blur) before application to avoid false edges.
Compatible Image Properties:
import type { Image } from 'image-js';
export default function gradientFilter(image: Image) {
// Image must be grayscale before applying the filter
image = image.grey();
return image.gradientFilter({
kernelX: [
[1, 0, 1],
[0, 0, 0],
[1, 0, 1],
],
});
}ImageJS provides several modules for processing images:
transform() function is a fundamental image processing operation. It requires two primary parameters: the image to be transformed and a transformation matrix. Additionally, it accepts an options object to refine the transformation behavior.minDiameter and maxDiameter properties of a Feret object are themselves FeretDiameter objects. These objects provide detailed geometric data about the specific diameter measurement:// Example of properties available on a FeretDiameter object:
// feret.minDiameter.length -> number (length of the diameter)
// feret.minDiameter.angle -> number (angle in degrees relative to horizontal)
// feret.minDiameter.points -> [Point, Point] (start and end points)
// feret.minDiameter.calliperLines -> [[Point, Point], [Point, Point]] (the two parallel tangent lines)Feret diameters (also known as caliper diameters) measure the minimum and maximum distances between two parallel tangents that touch the boundary of a region of interest. This is used for shape and structure analysis.
In ImageJS, you can obtain these measurements using the feret accessor on an Roi instance or the getFeret() method on a Mask instance. Both return a Feret object containing:
minDiameter: The minimum diameter (type FeretDiameter).maxDiameter: The maximum diameter (type FeretDiameter).aspectRatio: The ratio between the maximum and minimum diameter lengths (type number).// Using ROI accessor
const feret = roi.feret;
// Using Mask method
const feret = mask.getFeret();