将jpg图像作为jpg图像添加到DICOM文件

时间:2018-10-04 14:43:23

标签: c# dicom fo-dicom

美好的一天,

我正在读取jpg图像,并尝试将其作为jpg存储在DICOM文件中。我希望尽可能少地进行操作,以防止丢失或更改ICC配置文件。

我尝试过:

...
data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGLSLossless);

data.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Rgb);
data.Add(DicomTag.SamplesPerPixel, "3");
data.Add(DicomTag.PlanarConfiguration, "0");
data.Add(DicomTag.BitsAllocated, (ushort)8);
data.Add(DicomTag.BitsStored, (ushort)8);
data.Add(DicomTag.HighBit, (ushort)7);
data.Add(DicomTag.PixelRepresentation, "0");
data.Add(DicomTag.BurnedInAnnotation, "NO");
data.Add(DicomTag.LossyImageCompression, "01");
data.Add(DicomTag.LossyImageCompressionRatio, "10");
data.Add(DicomTag.LossyImageCompressionMethod, "ISO_10918_1");
...

DicomPixelData pixelData = DicomPixelData.Create(data, true);

using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageFilename))
{
    byte[] pixels = GetPixels(bitmap);
    MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);
    pixelData.AddFrame(buffer);
}

and

using (Image image = Image.FromFile(imageFilename))
{
    byte[] pixels = ImageToByteArray(image);
    MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);
    pixelData.AddFrame(buffer);
}

由于DICOM文件的大小急剧膨胀,似乎将图像存储为BMP。

我尝试了DicomTag.TransferSyntaxUID的不同组合:

data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGLSLossless);
data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGBaseline1);
data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGLosslessNonHierarchical14);

有想法吗?

(注意:这也是在fo-dicom用户组中提出的)

1 个答案:

答案 0 :(得分:2)

我们找到了答案:

DicomDataset data = new DicomDataset() { };

更改为:

DicomDataset data = new DicomDataset(DicomTransferSyntax.JPEGProcess1) { };

这是基于本文:

https://github.com/fo-dicom/fo-dicom/issues/553