computeKernelSize function

int computeKernelSize(
  1. int width,
  2. int height,
  3. double scaleFactor
)

Computes the appropriate kernel size for dilation based on image dimensions.

This function calculates a kernel size proportional to the image dimensions, which is useful for morphological operations like dilation.

Parameters:

  • width: The width of the image in pixels.
  • height: The height of the image in pixels.
  • scaleFactor: A scaling factor that determines how the kernel size relates to image dimensions. Typically a small value (e.g., 0.01-0.05).

Returns: An integer representing the computed kernel size, clamped between 1 and the image width.

Implementation

int computeKernelSize(int width, int height, double scaleFactor) {
  return (scaleFactor * width).round().clamp(1, width);
}