I'm having problem with putting dicom image onto canvas. I tried to follow this answer but it results in image being too bright: 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;
}