c# - 使用 GDCM 将 16 位图像写入 DICOM 文件格式

标签 c# dicom gdcm

我已经使用 GDCM 成功地将 8 位 图像写入 DICOM 文件图书馆。现在我正在尝试将 16 位 图像写入 DICOM 文件。这是我的代码。谁能指出我遗漏了什么或应该做什么。

static public void CreateSmallDICOMShort(string fileName, short [] buffer, uint[] dim)
  {
      using (var writer = new gdcm.PixmapWriter())
      {
          gdcm.Pixmap img = writer.GetImage();
          img.SetNumberOfDimensions(3);
          var pixelFormat = new PixelFormat();
          pixelFormat.SetScalarType(PixelFormat.ScalarType.UINT16);
          img.SetDimension(0, dim[0]);
          img.SetDimension(1, dim[1]);
          img.SetDimension(2, 1); // fake a 3d volume
          img.SetPixelFormat(pixelFormat);
          PhotometricInterpretation pi = new PhotometricInterpretation(PhotometricInterpretation.PIType.MONOCHROME1);
          img.SetPhotometricInterpretation(pi);
          gdcm.DataElement pixeldata = new gdcm.DataElement(new gdcm.Tag(0x7fe0, 0x0010));
          //byte[] buffer = new byte[512 * 512 * 2];
          pixeldata.SetArray(buffer,(uint)buffer.Length);
          img.SetDataElement(pixeldata);

          gdcm.File file = writer.GetFile();
          gdcm.DataSet ds = file.GetDataSet();
          gdcm.DataElement ms = new gdcm.DataElement(new gdcm.Tag(0x0008, 0x0016));
          string mediastorage = "1.2.840.10008.5.1.4.1.1.7.2"; // Multi-frame Grayscale Byte Secondary Capture Image Storage
          byte[] val = StrToByteArray(mediastorage);
          ms.SetByteValue(val, new gdcm.VL((uint)val.Length));
          ds.Insert(ms);

          writer.SetFileName(fileName);
          writer.Write();
      }
  }

最佳答案

您需要使用另一个 SetArray() 函数。您正在为图像缓冲区传递一个 8 位数据数组。只需传递一个 16 位数组。例如:

unsigned short[] buffer = new unsigned short[512 * 512];
pixeldata.SetArray(buffer,(uint)buffer.Length);

关于c# - 使用 GDCM 将 16 位图像写入 DICOM 文件格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22535598/

相关文章:

c# - 如何使用 Azure Function HTTP 绑定(bind)执行 REST API 可选字符串 URI 参数?

c# - C# 中代码隐藏的 CryptoJS.SHA3?

python - 在 Windows 上安装 GDCM -- ImportError

c# - Java 的 ByteBuffer 最接近 C# 中的对应物?

dicom - 如何在浏览器上查看 DICOM 图像?

wpf - 加载 Dicom 图像并显示它 - 使用 ClearCanvas 库

dicom - 如何修改存储的dcm文件

c++ - 将 itkImage 保存为 DICOM 时未写入图像位置/方向

python - 将 bmp 图像转换为 DICOM

c# - 在 WPF 上流式传输从 Kinect 的 RGB 摄像头接收到的连续图像?