我在將 dicom 影像放到畫布上時遇到問題。我試圖按照這個答案,但它導致影像太亮: dicom image dicom tags
public redraw() {
...
const buffer8 = this.base64ToArrayBuffer(entry)
let minValue = (windowCenter - windowWidth) / 2;
let maxValue = (windowCenter windowWidth) / 2;
let scale = (maxValue - minValue) / 256;
for (let i = 0, j = 0; i < dstBmp.length; i = 4, j = 2) {
let pixelValue = (buffer8[j]) (buffer8[j 1]) * 256
let displayValue = Math.min((pixelValue - minValue) / scale, 255)
dstBmp[i 0] = displayValue
dstBmp[i 1] = displayValue
dstBmp[i 2] = displayValue
dstBmp[i 3] = 255
}
const idata = new ImageData(dstBmp, entryWidth, entryHeight);
context.putImageData(idata, 0, 0);
}
public base64ToArrayBuffer(base64: string) {
const binary_string = window.atob(base64);
const len = binary_string.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i ) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes;
}
uj5u.com熱心網友回復:
我沒有嘗試運行您的代碼,也沒有完全遵循它來查看您在做什么,但是在開始時您確實 - 可能 - 誤用了視窗和級別。
基于視窗和級別的最小值和最大值的邏輯應該是最小值是中心減去寬度的一半,反之亦然。
這不是您的代碼似乎在做什么。您正在執行的設定 min 和 max 的操作將導致值過低,因此您的影像可能會全部顯示為白色,這就是您所說的所見。
也許試試這個:
let minValue = windowCenter - windowWidth / 2;
let maxValue = windowCenter windowWidth / 2;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/349967.html
標籤:打字稿 html5-canvas 迪康
下一篇:我如何處理Jest中的承諾?
