简体   繁体   English

另存为PNG时,DICOM切片损坏

[英]DICOM slice corrupted when saved as PNG

I'm using SimpleITK to read a DICOM, and save a particular slice as a PNG file. 我正在使用SimpleITK读取DICOM,并将特定的切片保存为PNG文件。 I can write back a new DICOM file to disk fine, and it looks as expected. 我可以将新的DICOM文件写回到磁盘上,并且看起来像预期的那样。 But whenever I try to save it in any other format, it's greatly corrupted. 但是,每当我尝试以任何其他格式保存它时,它都会遭到严重破坏。 By that I mean it looks nothing like the input, it's completely garbled. 我的意思是,它看起来完全不像输入,它完全是乱码。

Here is the code: 这是代码:

        var imageReader = new ImageFileReader();
        imageReader.SetOutputPixelType(PixelIDValueEnum.sitkUInt8);
        var dicomFileNames = ImageSeriesReader.GetGDCMSeriesFileNames(@"D:\Study");
        imageReader.SetFileName(dicomFileNames[255]);
        var image = imageReader.Execute();
        var fileWriter = new ImageFileWriter();
        fileWriter.SetFileName("slice.png");
        fileWriter.Execute(image);

Getting the image's buffer and using it to create a BitMap suffers the same problem. 获取图像的缓冲区并使用其创建BitMap会遇到相同的问题。 Reading the DICOM series (my eventual goal) instead of one file, and using the 3D volume and extracting a slice in that manner also has the same issue. 读取DICOM系列(我的最终目标)而不是一个文件,并使用3D体积并以这种方式提取切片也存在相同的问题。

What am I missing? 我想念什么?

EDIT: Using PixelIDValueEnum.sitkUInt16 greatly improves the output of ImageFileWriter , although the contrast is off and loses some detail. 编辑:使用PixelIDValueEnum.sitkUInt16极大地改善ImageFileWriter的输出,尽管对比度已关闭并丢失了一些细节。 I still cannot convert the buffer to a BitMap and save that as a PNG, this code still creates corrupted data: 我仍然无法将缓冲区转换为BitMap并将其另存为PNG,此代码仍会创建损坏的数据:

        var size = image.GetSize();
        var length = (int)(size[0] * size[1]) * 2;
        var buffer = image.GetBufferAsUInt16();

        var rgbValues = new byte[length];

        Marshal.Copy(buffer, rgbValues, 0, length);

        var newBitmap = new Bitmap((int)image.GetWidth(), (int)image.GetHeight(), (int)image.GetWidth(), PixelFormat.Format16bppArgb1555, buffer);
        newBitmap.Save(@"C:\test.png", ImageFormat.Png);

I have tried every PixelFormat.16bpp* value without success, some data must be getting lost, because the output of the ImageFileWriter is more than 50% larger than when I save the bitmap. 我尝试了每个PixelFormat.16bpp*值都没有成功,某些数据必定会丢失,因为ImageFileWriter的输出比保存位图时的输出大50%以上。

Here is the bad BitMap: 这是不良的BitMap:

在此处输入图片说明

Most medical images are 16 bit deep ( short or unsigned short ), not 8 bit ( sitkUInt8 ). 大多数医学图像为16位深( shortunsigned short ),而不是8位( sitkUInt8 )。 Try a few other pixel formats. 尝试其他几种像素格式。 If that does not help, attach an extracted PNG slice - that will allow more/better advice. 如果这样做没有帮助,请附加提取的PNG切片-这样可以提供更多/更好的建议。

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

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