image-js
Version:
Image processing and manipulation in JavaScript
38 lines • 1.57 kB
JavaScript
import { Image } from '../Image.js';
import { subtract } from '../compare/index.js';
import { checkKernel } from '../utils/validators/checkKernel.js';
import checkProcessable from '../utils/validators/checkProcessable.js';
/**
* This function is the black top hat (also called bottom hat).
* In mathematical morphology and digital image processing,
* top-hat transform is an operation that extracts small elements and details from given images.
* The black top-hat transform is defined dually as the difference between the closed and the input image.
* Top-hat transforms are used for various image processing tasks, such as feature extraction, background equalization,
* image enhancement, and others. (Wikipedia)
* @see {@link http://docs.opencv.org/2.4/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html}
* @param image - Image to process.
* @param options - Bottom hat options.
* @returns The bottom-hatted image.
*/
export function bottomHat(image, options = {}) {
const { kernel = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1],
], iterations = 1, } = options;
if (image instanceof Image) {
checkProcessable(image, {
bitDepth: [1, 8, 16],
components: 1,
alpha: false,
});
}
checkKernel(kernel);
let newImage = image;
for (let i = 0; i < iterations; i++) {
const openImage = newImage.close({ kernel });
newImage = subtract(openImage, newImage, { absolute: true });
}
return newImage;
}
//# sourceMappingURL=bottomHat.js.map