image-js
Version:
Image processing and manipulation in JavaScript
38 lines • 1.79 kB
JavaScript
import { getClockwiseAngle } from '../../maskAnalysis/utils/getAngle.js';
import { toDegrees } from '../../utils/geometry/angles.js';
import { getRadius } from '../../utils/getRadius.js';
import { checkBorderDistance } from '../utils/checkBorderDistance.js';
import { getFastKeypoints } from './getFastKeypoints.js';
import { getPatchIntensityCentroid } from './getPatchIntensityCentroid.js';
/**
* Find the oriented FAST features in a GREY image.
* How to add orientation to FAST is described in: http://www.gwylab.com/download/ORB_2012.pdf
* Basically, the intensity centroid of the window around the corner is computed and the
* orientation is given by the vector from the center to the intensity centroid.
* @param image - The image to process.
* @param options - Get oriented FAST keypoints options.
* @returns The oriented FAST keypoints.
*/
export function getOrientedFastKeypoints(image, options = {}) {
const { centroidPatchDiameter: windowSize = 7 } = options;
const fastKeypoints = getFastKeypoints(image, options);
const radius = getRadius(windowSize);
// handle edge cases: remove keypoints too close to border
const keypoints = [];
for (const keypoint of fastKeypoints) {
if (checkBorderDistance(image, keypoint.origin, radius)) {
keypoints.push(keypoint);
}
}
const orientedFastKeypoints = [];
for (const keypoint of keypoints) {
const centroid = getPatchIntensityCentroid(image, {
center: keypoint.origin,
radius,
})[0];
const angle = toDegrees(getClockwiseAngle({ column: 0, row: 0 }, centroid));
orientedFastKeypoints.push({ ...keypoint, angle });
}
return orientedFastKeypoints;
}
//# sourceMappingURL=getOrientedFastKeypoints.js.map