voluptasquisquam
Version:
Image processing and manipulation in JavaScript
11 lines (9 loc) • 314 B
JavaScript
import {SVD} from 'ml-matrix';
export default function getSeparatedKernel(kernel) {
const svd = new SVD(kernel, {autoTranspose: true});
if (svd.rank !== 1) return null;
const s = Math.sqrt(svd.s[0]);
const v = svd.U.map(v => v[0] * s);
const h = svd.V.map(h => h[0] * s);
return [v, h];
}