Dicom 图像太亮

Dicom image too bright

我在将 dicom 图像放到 canvas 上时遇到问题。我试图跟随 但它导致图像太亮: 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;
  }

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

min和max根据window和level的逻辑应该是min值是中心减去宽度的一半,反之亦然

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

也许试试这个:

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