embedded mpeg2 to dicom

197 views
Skip to first unread message

Nhan Vo

unread,
Jul 1, 2014, 12:49:32 PM7/1/14
to fo-d...@googlegroups.com
Hi,

I'm working on a project which requires me to convert mpeg2 format to dcm using mdcm (predecessor of fodicom) and store this converted dcm to "dcm4chee". 
So the first part, converting mpeg2 to dcm is done successfully. I also opened the converted file in dvtk Editor toolkit and there was no error. But the problem lies in the second part, storing the converted dcm to dcm4chee.
Dcm4chee keeps return status 110 whenever I upload the file with EOF Exception. 

Here is the code I used to convert the file. Please let me know if there is something I did wrong.

string mpeg2Input = @"C:\sample\recording.mpg";
                string dcmOutput = @"C:\sample\eric_converted_mpeg2.dcm";
                DateTime currentDate = DateTime.Now;
                string accessionNumber = currentDate.Millisecond.ToString();
                string referringPhysician = @"CHAMBOURCY^GASTONI";
                string patientName = @"Video^Test";
                string patientID = accessionNumber + "9821";
                string patientSex = "F";
                DateTime patientDOB = new DateTime(1990, 1, 15);
                DicomUID studyInstanceUID = DicomUID.Generate();
                DicomUID seriesInstanceUID = DicomUID.Generate();
                DicomUID sopInstanceUID = DicomUID.Generate(seriesInstanceUID, 1);
                //construct dataset
                DcmDataset dataset = new DcmDataset(DicomTransferSyntax.MPEG2);
                dataset.AddElementWithValue(DicomTags.SOPClassUID, DicomUID.VideoEndoscopicImageStorage);
                dataset.AddElementWithValue(DicomTags.ImageType, "ORIGINAL\\PRIMARY");
                dataset.AddElement(DicomTags.PatientOrientation);
                dataset.AddElementWithValue(DicomTags.StudyDate, currentDate);
                dataset.AddElementWithValue(DicomTags.SeriesDate, currentDate);
                dataset.AddElementWithValue(DicomTags.StudyTime, currentDate.ToString());
                dataset.AddElementWithValue(DicomTags.AccessionNumber, accessionNumber);
                dataset.AddElementWithValue(DicomTags.Modality, "OT");
                dataset.AddElementWithValue(DicomTags.ReferringPhysiciansName, referringPhysician);
                dataset.AddElementWithValue(DicomTags.PatientsName, patientName);
                dataset.AddElementWithValue(DicomTags.PatientsSex, patientSex);
                dataset.AddElementWithValue(DicomTags.PatientsBirthDate, patientDOB);
                dataset.AddElementWithValue(DicomTags.PatientID, patientID);
                dataset.AddElementWithValue(DicomTags.CineRate, "25");
                dataset.AddElementWithValue(DicomTags.FrameTime, "40.000000");
                dataset.AddElementWithValue(DicomTags.StudyInstanceUID, studyInstanceUID);
                dataset.AddElementWithValue(DicomTags.SeriesInstanceUID, seriesInstanceUID);
                dataset.AddElementWithValue(DicomTags.SOPInstanceUID, sopInstanceUID);
                dataset.AddElement(DicomTags.StudyID);
                dataset.AddElementWithValue(DicomTags.SeriesNumber, "1238712");
                dataset.AddElementWithValue(DicomTags.InstanceNumber, "2");
                dataset.AddElementWithValue(DicomTags.PhotometricInterpretation, PhotometricInterpretation.YbrFull422.Value);
                //dataset.AddElementWithValue(DicomTags.NumberOfFrames, "450");
                //dataset.AddElementWithValue(DicomTags.FrameIncrementPointer, DicomTags.FrameTime);
                
                dataset.AddElementWithValue(DicomTags.PixelAspectRatio, "4\\3");
                                
                dataset.AddElementWithValue(DicomTags.PixelRepresentation, (ushort) 0);
                dataset.AddElementWithValue(DicomTags.LossyImageCompression, "01");
                dataset.AddElementWithValue(DicomTags.SpecificCharacterSet, "ISO_IR 100");
                dataset.AddElementWithValue(DicomTags.ConversionType, "SI");
                dataset.AddElementWithValue(DicomTags.Manufacturer, "GlobalMed");
                //read mpeg2Input and store in byte                
                byte[] videoInByte = ReadBytesFromFile(mpeg2Input);                
                DcmPixelData pixelData = new DcmPixelData(DicomTransferSyntax.ExplicitVRLittleEndian);
                
                pixelData.HighBit = 7;
                pixelData.BitsStored = 8;
                pixelData.BitsAllocated = 8;
                pixelData.SamplesPerPixel = 3;
                pixelData.PlanarConfiguration = 0;
                pixelData.PhotometricInterpretation = PhotometricInterpretation.YbrFull422.Value;
                pixelData.PixelDataElement = DcmElement.Create(DicomTags.PixelData, DicomVR.OB);                
                
                pixelData.ImageHeight = 288;
                pixelData.ImageWidth = 352;                
                //add mpeg2Input byte into dicom dataset
                pixelData.AddFrame(videoInByte);                
                
                pixelData.UpdateDataset(dataset);
                     
                
                //save the dataset in dicom
                DicomFileFormat df = new DicomFileFormat(dataset);
                df.SaveToBackup = true;
                df.Save(dcmOutput, Dicom.DicomWriteOptions.Default);

Nhan Vo

unread,
Jul 2, 2014, 6:37:20 PM7/2/14
to fo-d...@googlegroups.com
I was able to fixed the issue. What I did is replacing  pixelData.PixelDataElement = DcmElement.Create (DicomTags. PixelData, DicomVR.OB);       with the following
DcmFragmentSequence fragmentSequence = new DcmFragmentSequence (DicomTags.PixelData, DicomVR.OB);                
                pixelData.PixelDataSequence = fragmentSequence;                
Reply all
Reply to author
Forward
0 new messages