You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用fo-dicom的InvertLut类实现DICOM图像灰度反转?

如何在fo-dicom中使用InvertLut实现灰度反转

要在你的DICOM查看器里用InvertLut实现灰度反转,只需要在渲染图像时配置对应的渲染选项,把反转查找表(LUT)应用进去即可。以下是修改后的代码,关键是给RenderImage方法传入包含InvertLut的GrayscaleRenderOptions:

public WriteableBitmap DisplayedImage { get; set; }
// 可添加开关控制反转状态
public bool IsGrayscaleInverted { get; set; }

//...
private void ExecuteLoadImageCommand()
{
    _dicomFile = DicomFile.Open(GetImageFileName());
    _dicomImage = new DicomImage(_dicomFile.Dataset);
    WindowLevel = _dicomImage.WindowCenter;
    WindowWidth = _dicomImage.WindowWidth;
    var grayScaleOptions = GrayscaleRenderOptions.FromBitRange(_dicomFile.Dataset);
    Depth = grayScaleOptions.BitDepth.BitsAllocated;

    // 配置渲染选项,按需应用反转LUT
    var renderOptions = new GrayscaleRenderOptions(
        grayScaleOptions.BitDepth,
        grayScaleOptions.RescaleSlope,
        grayScaleOptions.RescaleIntercept,
        IsGrayscaleInverted ? InvertLut.Instance : null
    );

    DisplayedImage = _dicomImage.RenderImage(WindowLevel, WindowWidth, renderOptions).As<WriteableBitmap>();
}

关键说明:

  • InvertLut.Instance是fo-dicom提供的单例反转查找表,直接使用无需手动实例化。
  • 如果需要支持动态切换反转状态,可以通过IsGrayscaleInverted布尔属性控制,用户触发反转操作时切换该值并重新调用渲染逻辑即可更新图像。
  • 渲染时同时传入窗宽窗位和配置好的渲染选项,能保证反转效果与窗宽窗位调整同时生效。

内容的提问来源于stack exchange,提问作者SoothingMusic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 21:15:43