你好,
我正在读取 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);
}
它似乎将图像存储为 BMP,因为 DICOM 文件的大小膨胀得令人难以置信。
我尝试了 DicomTag.TransferSyntaxUID 的不同组合:
data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGLSLossless);
data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGBaseline1);
data.Add(DicomTag.TransferSyntaxUID, DicomUID.JPEGLosslessNonHierarchical14);
想法?
(注意:这也是在 fo-dicom 用户组上发布的)
最佳答案
我们找到了答案:
DicomDataset data = new DicomDataset() { };
改为:
DicomDataset data = new DicomDataset(DicomTransferSyntax.JPEGProcess1) { };
这是基于这篇文章:
关于c# - 将 jpg 图像作为 jpg 图像添加到 DICOM 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52649545/