How to convert a DICOM file with no extension to a .png file or a .jpg file?

匆匆过客 提交于 2019-12-10 22:36:22

问题


I have a simple C# Console Application that places a dicom file into a stream and then Copies that stream to a .jpg file. My code creates the file but I'm unable to view the image. Below is the code I am using.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using rzdcxLib;
using System.Drawing.Imaging;

namespace ConsoleApplication1
{
    class Program
    {
       public static void CopyStream(Stream input, Stream output) { 
            byte[] buffer = new byte[8 * 1024];
            int len;
            while ((len = input.Read(buffer, 0, buffer.Length)) > 0) { 
                output.Write(buffer, 0, len); 
            } 
        } 
        static void Main(string[] args)
        {
            Stream myStream = 
             new FileStream("F:\\MIS\\JLoren\\Projects\\" + 
                             "814-Convert for Chandra\\DICOM\\Test\\IM1",
                            FileMode.Open, 
                            FileAccess.Read);
            Stream OutPut = 
             new FileStream("F:\\MIS\\JLoren\\Projects\\" +
                            "814-Convert for Chandra\\DICOM\\Test\\IM1.jpg", 
                            FileMode.Create, 
                            FileAccess.Write);
            CopyStream(myStream, OutPut);
        }
    }
}

回答1:


Look here for information on the DICOM image format and how to read up DICOM images with C#. Note that these images are often 16 bit grayscale, which means a 8bpp (per-channel) monitor format cannot display these images with their full color range. You will have to choose a value of "window" and "level" for your particular conversion. Fixing these values might cause you to lose information in the converted image. See: Hounsfeld units.

Also - one of the core tenets of DICOM is that the image be lossless. Ensure that this is acceptable for your purpose before proceeding with a JPG conversion. PNG ought to be ok.



来源:https://stackoverflow.com/questions/12094570/how-to-convert-a-dicom-file-with-no-extension-to-a-png-file-or-a-jpg-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!