UNPKG

image-js

Version:

Image processing and manipulation in JavaScript

35 lines 1.4 kB
import { Image, ImageCoordinates } from '../../Image.js'; import { merge } from '../../operations/index.js'; import { ImageColorModel } from '../../utils/constants/colorModels.js'; /** * Overlap two images and specify. The first image can be translated, * rotated and scaled to match the second one. * The first image is drawn in red and the second one in green. * @param image1 - First image. * @param image2 - Second image. * @param options - Overlap image options. * @returns The overlapping images. */ export function overlapImages(image1, image2, options = {}) { const { origin = { row: 0, column: 0 }, angle = 0, scale = 1 } = options; if (scale === 0) { throw new Error('Scale cannot be 0'); } if (image1.colorModel !== ImageColorModel.GREY) { image1 = image1.grey(); } if (image2.colorModel !== ImageColorModel.GREY) { image2 = image2.grey(); } const inverted1 = image1.invert(); const inverted2 = image2.invert(); const rotated = inverted1.transformRotate(angle, { center: ImageCoordinates.TOP_LEFT, }); const scaled = rotated.resize({ xFactor: scale, yFactor: scale }); const empty = Image.createFrom(inverted2); const alignedGrey1 = scaled.copyTo(empty, { origin }); const result = merge([alignedGrey1, inverted2, empty]); return result; } //# sourceMappingURL=overlapImages.js.map