Dicom image too bright

Issue

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;
  }

Solution

I didn’t try and run your code, nor follow it all completely to see what you’re doing, however at the start you do have – possibly – a mis-use of window and level.

The logic for min and max based on window and level should be that the min value is the center minus half the width, and vica versa for the max.

That isn’t what your code seems to be doing. What you’re doing to set min and max will result in values that are too low, and so likely you’re image will appear all white, which is what you’re saying you see.

Perhaps try this instead:

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

Answered By – Richard

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published