our-medical
Version:
medical image vue component
42 lines (41 loc) • 1.27 kB
JavaScript
self.onmessage = function({ data: n }) {
const t = {
max: -1 / 0,
min: 1 / 0,
statistics: /* @__PURE__ */ new Map(),
huDistribution: /* @__PURE__ */ new Map()
};
if (n.modality === "PT")
for (const i of n.scalarData) {
t.max = Math.max(i, t.max), t.min = Math.min(i, t.min);
const s = Math.round(i), e = t.statistics.get(s);
t.statistics.set(s, e === void 0 ? 1 : e + 1);
}
else {
let i = (s) => s;
if (n.modality === "CT") {
const { rescaleIntercept: s, rescaleSlope: e } = n.modalityLutModule;
if (s === void 0 || e === void 0)
throw new Error("Missing intercept or slope information!");
i = (o) => o * e + s;
}
for (const s of n.scalarData) {
const e = i(s);
t.max = Math.max(e, t.max), t.min = Math.min(e, t.min);
const o = t.statistics.get(e);
t.statistics.set(e, o === void 0 ? 1 : o + 1);
}
}
t.huDistribution = r(t.statistics), self.postMessage(t);
};
function r(n) {
let i = Array.from(n.keys()).sort((a, c) => a - c).at(0);
const s = /* @__PURE__ */ new Map([[i, n.get(i)]]);
let e = 1;
const o = n.size;
for (; e < o; ) {
const a = n.get(++i);
a === void 0 ? s.set(i, 0) : (s.set(i, a + 1), e++);
}
return s;
}