医工互联

 找回密码
 注册[Register]

手机动态码快速登录

手机号快速登录

微信登录

微信扫一扫,快速登录

QQ登录

只需一步,快速开始

查看: 641|回复: 0
收起左侧

医学影像知识(一):DICOM影像文件参数:窗宽窗位

[复制链接]

  离线 

发表于 2023-11-1 06:40:47 | 显示全部楼层 |阅读模式
Dicom文件参数

SOP类别(SOP Class): 表示DICOM文件所表示的医学图像类型,如X光、MRI、CT等。
SOP实例UID(SOP Instance UID): 唯一标识DICOM文件中的具体图像实例,每个图像实例都有一个独特的UID。
序列描述(Series Description): 描述了同一批次图像的特定信息,通常与采集参数、扫描顺序等相关。
病人信息(Patient Information): 包括患者的姓名、性别、出生日期等身份和基本信息。
扫描日期和时间(Acquisition Date/Time): 表示图像数据获取的日期和时间。
像素尺寸(Pixel Spacing): 定义图像中每个像素在物理尺寸上的间隔,以毫米为单位。
影像位置(Image Position)和影像方向(Image Orientation): 描述了图像在三维空间中的位置和方向。
像素表示(Pixel Representation): 定义了像素值的表示方式,通常为有符号整数或无符号整数。
像素位深度(Bits Allocated、Bits Stored、High Bit): 描述了图像中每个像素的位数和数值范围。
重建间隔(Slice Thickness): 对于体层扫描,表示相邻图像切片之间的间距。
对比剂信息(Contrast/Bolus Information): 如果影像中使用了对比剂,会包括有关对比剂类型、剂量等信息。
采集设备信息(Equipment Information): 描述了使用的影像设备的信息,包括制造商、型号、软件版本等。
图像修剪(Image Cropping): 描述是否对图像进行了裁剪或修剪。
窗宽和窗位(Window Width/Level): 控制影像显示的对比度和亮度。
像素数据(Pixel Data): 包含实际图像的像素值,这是DICOM文件中最重要的部分。
Modality LUT和VOI LUT: 用于调整图像的灰度级和对比度显示。
DICOM标记(DICOM Tags): 包含大量的元数据,用于描述DICOM文件的各个方面。
窗宽窗位

其中,窗宽(Window Width)和窗位(Window Level)是两个重要的概念。它们在可视化影像时起着关键作用,帮助医生和医学影像技术人员更好地识别和分析图像中的组织和病变。
窗宽(Window Width)是显示灰度级别的范围,也称为灰度宽度、对比度或亮度范围。它决定了在显示器上可见的不同组织和结构的灰度差异程度。较大的窗宽意味着更宽广的灰度范围,可以显示更多的细节,但可能在图像中丧失一些对比度。较小的窗宽则会强调图像中的细微灰度变化,但在图像的范围内可能丢失了一些细节。总而言之,窗宽大,对比度差,适合密度差别大的结构;窗宽小,对比度强,适合密度接近的组织
窗位(Window Level)是显示灰度级别的中心值,也称为中心亮度、亮度水平或对比度中心。它定义了在图像上显示的中心灰度级别。通过调整窗位,您可以将兴趣区域的灰度级别放在图像上的合适位置,使其更易于观察。
手动调节窗宽窗位

利用ITK包可以实现Dicom文件的读取并对窗宽、窗位进行调整;
  1. #include "itkImage.h"
  2. #include "itkImageFileReader.h"
  3. int main(int argc, char* argv[])
  4. {
  5.     if (argc < 4)
  6.     {
  7.         std::cerr << "Usage: " << argv[0] << " inputDicomDirectory windowWidth windowLevel" << std::endl;
  8.         return EXIT_FAILURE;
  9.     }
  10.     using PixelType = signed short;
  11.     constexpr unsigned int Dimension = 3;
  12.     using ImageType = itk::Image<PixelType, Dimension>;
  13.     using ReaderType = itk::ImageFileReader<ImageType>;
  14.     ReaderType::Pointer reader = ReaderType::New();
  15.     reader->SetFileName(argv[1]);
  16.     // Read the DICOM image
  17.     try
  18.     {
  19.         reader->Update();
  20.     }
  21.     catch (itk::ExceptionObject& ex)
  22.     {
  23.         std::cerr << "Exception caught: " << ex << std::endl;
  24.         return EXIT_FAILURE;
  25.     }
  26.     ImageType::Pointer image = reader->GetOutput();
  27.     double windowWidth = std::stod(argv[2]);
  28.     double windowLevel = std::stod(argv[3]);
  29.     // Apply manual windowing
  30.     itk::ImageRegionIterator<ImageType> iterator(image, image->GetLargestPossibleRegion());
  31.     for (iterator.GoToBegin(); !iterator.IsAtEnd(); ++iterator)
  32.     {
  33.         PixelType pixelValue = iterator.Get();
  34.         iterator.Set(static_cast<PixelType>((pixelValue - windowLevel + 0.5 * windowWidth) / windowWidth * 255.0));
  35.     }
  36.     // Save the windowed image (for demonstration)
  37.     using WriterType = itk::ImageFileWriter<ImageType>;
  38.     WriterType::Pointer writer = WriterType::New();
  39.     writer->SetFileName("output.dcm");
  40.     writer->SetInput(image);
  41.     try
  42.     {
  43.         writer->Update();
  44.     }
  45.     catch (itk::ExceptionObject& ex)
  46.     {
  47.         std::cerr << "Exception caught: " << ex << std::endl;
  48.         return EXIT_FAILURE;
  49.     }
  50.     return EXIT_SUCCESS;
  51. }
复制代码
自适应调节窗宽窗位

下面是一个基于ITK的简单自适应的自动调节窗宽窗位的示例代码。这个示例使用了直方图分析来自适应地计算窗宽窗位值。
  1. #include "itkImage.h"
  2. #include "itkImageFileReader.h"
  3. #include "itkImageFileWriter.h"
  4. #include "itkStatisticsImageFilter.h"
  5. int main(int argc, char* argv[])
  6. {
  7.     if (argc < 2)
  8.     {
  9.         std::cerr << "Usage: " << argv[0] << " inputDicomDirectory" << std::endl;
  10.         return EXIT_FAILURE;
  11.     }
  12.     using PixelType = signed short;
  13.     constexpr unsigned int Dimension = 3;
  14.     using ImageType = itk::Image<PixelType, Dimension>;
  15.     using ReaderType = itk::ImageFileReader<ImageType>;
  16.     using StatisticsFilterType = itk::StatisticsImageFilter<ImageType>;
  17.     ReaderType::Pointer reader = ReaderType::New();
  18.     reader->SetFileName(argv[1]);
  19.     // Read the DICOM image
  20.     try
  21.     {
  22.         reader->Update();
  23.     }
  24.     catch (itk::ExceptionObject& ex)
  25.     {
  26.         std::cerr << "Exception caught: " << ex << std::endl;
  27.         return EXIT_FAILURE;
  28.     }
  29.     ImageType::Pointer image = reader->GetOutput();
  30.     // Compute image statistics
  31.     StatisticsFilterType::Pointer statisticsFilter = StatisticsFilterType::New();
  32.     statisticsFilter->SetInput(image);
  33.     statisticsFilter->Update();
  34.     double minValue = statisticsFilter->GetMinimum();
  35.     double maxValue = statisticsFilter->GetMaximum();
  36.     // Adaptive windowing
  37.     double range = maxValue - minValue;
  38.     double windowWidth = range * 0.8; // Adjust this factor based on preference
  39.     double windowLevel = minValue + range / 2.0;
  40.     // Apply adaptive windowing
  41.     itk::ImageRegionIterator<ImageType> iterator(image, image->GetLargestPossibleRegion());
  42.     for (iterator.GoToBegin(); !iterator.IsAtEnd(); ++iterator)
  43.     {
  44.         PixelType pixelValue = iterator.Get();
  45.         iterator.Set(static_cast<PixelType>((pixelValue - windowLevel + 0.5 * windowWidth) / windowWidth * 255.0));
  46.     }
  47.     // Save the windowed image (for demonstration)
  48.     using WriterType = itk::ImageFileWriter<ImageType>;
  49.     WriterType::Pointer writer = WriterType::New();
  50.     writer->SetFileName("output.dcm");
  51.     writer->SetInput(image);
  52.     try
  53.     {
  54.         writer->Update();
  55.     }
  56.     catch (itk::ExceptionObject& ex)
  57.     {
  58.         std::cerr << "Exception caught: " << ex << std::endl;
  59.         return EXIT_FAILURE;
  60.     }
  61.     return EXIT_SUCCESS;
  62. }
复制代码
窗宽窗位是医学影像处理中不可或缺的概念,通过调整灰度范围和中心,可以提高图像的对比度和清晰度。手动调节虽然常用,但受主观因素影响较大。自动调节算法的引入可以提高效率和一致性。通过深度学习方法,我们可以训练模型来实现自动调节,从而更好地支持临床诊断。
希望这篇博客内容对您有所帮助。
回复

使用道具 举报

提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!
您需要登录后才可以回帖 登录 | 注册[Register] 手机动态码快速登录 微信登录

本版积分规则

发布主题 快速回复 收藏帖子 返回列表 客服中心 搜索
简体中文 繁體中文 English 한국 사람 日本語 Deutsch русский بالعربية TÜRKÇE português คนไทย french

QQ|RSS订阅|小黑屋|处罚记录|手机版|联系我们|Archiver|医工互联 |粤ICP备2021178090号 |网站地图

GMT+8, 2024-9-17 04:10 , Processed in 0.231834 second(s), 57 queries .

Powered by Discuz!

Copyright © 2001-2023, Discuz! Team.

快速回复 返回顶部 返回列表