ClearCanvas / ClearCanvas

Open source code base for enabling software innovation in medical imaging
http://clearcanvas.github.io
Other
447 stars 474 forks source link

Convert JPEG to DICOM image #187

Open jagjotwadali opened 6 years ago

jagjotwadali commented 6 years ago

Hi, I want to convert the Scanned JPEG Image of Xray to DICOM image.Is it possible?

Thanks

alayyoubi commented 6 years ago

Google DICOMizer

Ahmed Alayyoubi

On Oct 14, 2017, at 12:41 AM, jagjotwadali notifications@github.com<mailto:notifications@github.com> wrote:

Hi, I want to convert the Scanned JPEG Image of Xray to DICOM image.Is it possible?

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/ClearCanvas/ClearCanvas/issues/187, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOkL5E1MbXJv0CtNKu-p3yQpJ2XL_SxUks5ssFeAgaJpZM4P5R_H.

jagjotwadali commented 6 years ago

I think DICOMizer is a paid software.I need a free and open source library developed in C#.

I am working on a telemedicine application which is developed in visual studio 2008 using 3.5 dot net framework.I have a high resolution scanner which is used to convert radipgraphic X-ray to JPEG format and I want a free and open source library which can convert that JPEG images to DICOM images.

itcthienkhiem commented 6 years ago

try it : https://github.com/ClearCanvas/ClearCanvas-Contrib/tree/master/ImportFromBitmap

Reinyn commented 1 year ago

I would also like a JPEG to DICOM example. I have ImportFromBitmap working but am struggling to convert it to JPEG.

If anyone can help the following code will execute but it produces a invalid DICOM file when saved. I feel like either the JPEG encoder I am using or the DataSet DICOM tags are wrong. I am basically using all the tags from the ImportFromBitmap project.

MemoryStream jpegStream = new MemoryStream(); fixedBitmap.SaveJPG100(jpegStream); Image jpegImage = Image.FromStream(jpegStream);

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

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

                                byte[] imageBuffer = jpegStream.ToArray();
                                compressedPixelData.AddFrameFragment(imageBuffer);

                                compressedPixelData.UpdateMessage(dicomFile);

public static void SaveJPG100(this Bitmap bmp, Stream stream) { EncoderParameters encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); bmp.Save(stream, GetEncoder(ImageFormat.Jpeg), encoderParameters);

        if (stream.Length % 2 == 1)
            stream.WriteByte(0x0);
    }

    public static ImageCodecInfo GetEncoder(ImageFormat format)
    {
        ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();

        foreach (ImageCodecInfo codec in codecs)
        {
            if (codec.FormatID == format.Guid)
            {
                return codec;
            }
        }

        return null;
    }