繁体   English   中英

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

[英]Writing 16-bit image to DICOM file format using 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);

你尝试过设置BitsAllocated,HighBit和BitsStored标签吗?

http://www.leadtools.com/sdk/medical/dicom-spec17.htm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM