使用ClearCanvas将JPG图像文件编码为DICOM PixelData [英] Encode JPG image file as DICOM PixelData using ClearCanvas

查看:167
本文介绍了使用ClearCanvas将JPG图像文件编码为DICOM PixelData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组JPG图像,它们实际上是CT扫描的一部分,我想将其重建为DICOM图像文件并导入到PACS中.

I have a set of JPG images that are actually slices of a CT scan, which I want to reconstruct into DICOM image files and import into a PACS.

我正在使用ClearCanvas,并设置了所有必需的标签(并通过使用专有应用程序将我的JPG文件之一转换为DICOM以确保它们相同来进行确认).我只是不确定如何处理JPG文件以将其放入PixelData标签中?

I am using ClearCanvas, and have set all of the requisite tags (and confirmed them by converting one of my JPG files to DICOM using a proprietary application to make sure they are the same). I am just not sure how I should be processing my JPG file to get it into the PixelData tag?

目前,根据ClearCanvas论坛的建议,我正在将其转换为Byte数组,但是图像在DICOM查看器中只是乱码.我应该如何处理图像数据以使其成为可读格式?

Currently I am converting it to a Byte array, on advice from ClearCanvas forums, but the image is just garbled in the DICOM viewer. How should I be processing the image data to get it into a readable format?

    public DicomFile CreateFileFromImage(Image image)
    {
        int height = image.Height;
        int width = image.Width;
        short bitsPerPixel = (short)Image.GetPixelFormatSize(image.PixelFormat);

        byte[] imageBuffer = ImageToByteArray(image);
        DicomFile dicomFile = new DicomFile();
        dicomFile.DataSet[DicomTags.Columns].SetInt32(0, width);
        dicomFile.DataSet[DicomTags.Rows].SetInt32(0, height);
        dicomFile.DataSet[DicomTags.BitsStored].SetInt16(0, bitsPerPixel);
        dicomFile.DataSet[DicomTags.BitsAllocated].SetInt16(0, bitsPerPixel);
        dicomFile.DataSet[DicomTags.HighBit].SetInt16(0, 7);
        //other tags not shown
        dicomFile.DataSet[DicomTags.PixelData].Values = imageBuffer;
        return dicomFile;
    }
    public static byte[] ImageToByteArray(Image imageIn)
    {
        MemoryStream ms = new MemoryStream();

        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        return ms.ToArray();
    }

推荐答案

ClearCanvas库是两个帮助程序类,可以更轻松地对DicomFile中的像素数据进行编码和解码.它们是DicomCompressedPixelData类和DicomUncompressedPixelData类.您可以使用它们来设置图像的参数,并将其编码为DicomFile对象.

The ClearCanvas library as two helper classes that make it easier to encode and decode pixel data within a DicomFile. They are the DicomCompressedPixelData class and the DicomUncompressedPixelData class. You can use these to set the parameters for the image, and encode them into the DicomFile object.

在这种情况下,由于要对压缩对象进行编码,因此应使用DicomCompressedPixelData类.在类上可以设置属性.调用UpdateMessage方法会将这些属性值复制到DicomFile对象.同样,此类具有AddFrameFragment方法,该方法可以正确编码像素数据.请注意,压缩的像素数据必须在数据的每一帧周围都有一些特定的二进制包装器.这是您以前的代码中缺少的部分.下面的代码显示了如何进行设置.

In your case, since you're encoding a compressed object, you should use the DicomCompressedPixelData class. There are properties on the class that can be set. Calling the UpdateMessage method will copy these property values over to the DicomFile object. Also, this class has an AddFrameFragment method that properly encodes the pixel data. Note that compressed pixel data has to have some specific binary wrappers around each frame of data. This was the part missing from your previous code. The code below shows how to set this up.

        short bitsPerPixel = (short)Image.GetPixelFormatSize(image.PixelFormat);

        var dicomFile = new DicomFile();
        var pd = new DicomCompressedPixelData(dicomFile);

        pd.ImageWidth = (ushort)image.Width;
        pd.ImageHeight = (ushort) image.Height;
        pd.BitsStored = (ushort)bitsPerPixel;
        pd.BitsAllocated = (ushort) bitsPerPixel;
        pd.HighBit = 7;
        pd.SamplesPerPixel = 3;
        pd.PlanarConfiguration = 0;
        pd.PhotometricInterpretation = "YBR_FULL_422";

        byte[] imageBuffer = ImageToByteArray(image);
        pd.AddFrameFragment(imageBuffer);

        pd.UpdateMessage(dicomFile);

        return dicomFile;

这篇关于使用ClearCanvas将JPG图像文件编码为DICOM PixelData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆