cornerstone.js 中PT图像自己计算窗宽窗位

背景:做petct过程中,前端的PT图像可以正常显示窗框窗位,后端要做截图时不能正确显示窗宽窗位。

解决思路:前端可以正常显示是因为 cornerstone.js 的源码里有算法做过处理,可以参考源码算法。

computeAutoVoi.js 中的源码贴出来记录一下:

/**
 * Computes the VOI to display all the pixels if no VOI LUT data (Window Width/Window Center or voiLUT) exists on the viewport object.
 *
 * @param {Viewport} viewport - Object containing the viewport properties
 * @param {Object} image An Image loaded by a Cornerstone Image Loader
 * @returns {void}
 * @memberof Internal
 */
export default function computeAutoVoi (viewport, image) {
  if (hasVoi(viewport)) {
    return;
  }

  const maxVoi = image.maxPixelValue * image.slope + image.intercept;
  const minVoi = image.minPixelValue * image.slope + image.intercept;
  const ww = maxVoi - minVoi;
  const wc = (maxVoi + minVoi) / 2;

  if (viewport.voi === undefined) {
    viewport.voi = {
      windowWidth: ww,
      windowCenter: wc
    };
  } else {
    viewport.voi.windowWidth = ww;
    viewport.voi.windowCenter = wc;
  }
}

核心代码就是:

  // 从图像的dicom标签中可以拿到图像最大像素值/最小像素值*图像斜率+图像的截距
  const maxVoi = image.maxPixelValue * image.slope + image.intercept;
  const minVoi = image.minPixelValue * image.slope + image.intercept;

  // 窗宽
  const ww = maxVoi - minVoi;
  // 窗位
  const wc = (maxVoi + minVoi) / 2;

你可能感兴趣的:(javascript,图像处理)