首页 > 解决方案 > Dicom 图像太亮

问题描述

我在将 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;
  }

标签: typescripthtml5-canvasdicom

解决方案


我没有尝试运行您的代码,也没有完全按照它来查看您在做什么,但是在开始时您确实 - 可能 - 误用了窗口和级别。

基于窗口和级别的最小值和最大值的逻辑应该是最小值是中心减去宽度的一半,反之亦然。

那不是您的代码似乎正在做的事情。您设置最小值和最大值的操作将导致值太低,因此您的图像很可能会显示为全白,这就是您所说的您所看到的。

也许试试这个:

    let minValue = windowCenter - windowWidth / 2;
    let maxValue = windowCenter + windowWidth / 2;

推荐阅读