目前我正在編寫一個模塊,用於將JPEG
轉換爲DICOM Image
轉換。在分析中,我已經完成了標記渲染,現在圖像不能在DICOM
文件中正確呈現。如何使用C#將普通jpeg圖像字節轉換爲DICOM本機圖像字節
是否有任何算法將JPEG
轉換爲DICOM
。
目前我正在編寫一個模塊,用於將JPEG
轉換爲DICOM Image
轉換。在分析中,我已經完成了標記渲染,現在圖像不能在DICOM
文件中正確呈現。如何使用C#將普通jpeg圖像字節轉換爲DICOM本機圖像字節
是否有任何算法將JPEG
轉換爲DICOM
。
.NET本身沒有DICOM支持的功能。你將需要使用一個庫。我不知道任何免費的,但我已經使用LeadTools,它會做(價格)。但我只會給它一個4/10,我會重新開始尋找其他選項。
請查看mdcm C#DICOM庫,最初由Colby Dillion編寫。他爲IJG/LibJPEG和OpenJPEG代碼庫開發了託管C++「橋」,因此mdcm提供了8/12/16位有損和無損JPEG支持以及JPEG-2000支持。
Colby的原始庫有WinForms依賴項。我創建了一個mdcm here的Silverlight和WPF目標分支。該庫的WPF版本可以充分利用Colby最初實現的相同JPEG(-2000)編解碼器。
另一方面,Silverlight版本目前無法從這些編解碼器中受益。我已經嘗試了在Silverlight中將FJCore和LibJpeg.Net庫應用於有損JPEG支持,但這些庫目前僅支持8位圖像。
問候,
安德斯@ Cureos
如果誰低估這個答案可以解釋爲什麼,我將不勝感激。 –
你並不需要 '轉換' JPEG到DICOM。 DICOM僅僅是JPEG流的'信封'。以下是我在做GDCM封裝(=放入信封DICOM)現有的MPEG2文件:
http://gdcm.sourceforge.net/html/MpegVideoInfo_8cs-example.html
簡單地適應代碼爲輸入JPEG文件。比如看看:
http://gdcm.sourceforge.net/html/DecompressJPEGFile_8cs-example.html
無需解壓/重新壓縮,這將是資源的浪費。
從馬蒂厄的反應繼續,這裏是創建使用優秀GDCM庫和他引用的例子是JPEG流的DICOM信封的一個非常簡單的方法(注意:我已經使用了一些輔助類,但非常簡單):
ImageReader r = new ImageReader();
gdcm.Image image = r.GetImage();
image.SetNumberOfDimensions(2);
DataElement pixeldata = DataElementHelper.PixelData;
string file1 = @"D:\testfil.jpeg";
System.IO.FileStream infile =
new System.IO.FileStream(file1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
//uint fsize = gdcm.PosixEmulation.FileSize(file1);
//byte[] jstream = new byte[fsize];
//infile.Read(jstream, 0, jstream.Length);
byte[] jstream = System.IO.File.ReadAllBytes(file1);
uint fsize = (uint) jstream.Length;
SmartPtrFrag sq = SequenceOfFragments.New();
Fragment frag = new Fragment();
frag.SetByteValue(jstream, new gdcm.VL((uint)jstream.Length));
sq.AddFragment(frag);
pixeldata.SetValue(sq.__ref__());
// insert:
image.SetDataElement(pixeldata);
PhotometricInterpretation pi = new PhotometricInterpretation(PhotometricInterpretation.PIType.MONOCHROME2);
image.SetPhotometricInterpretation(pi);
// FIXME hardcoded:
PixelFormat pixeltype = new PixelFormat(PixelFormat.ScalarType.UINT8);
image.SetPixelFormat(pixeltype);
TransferSyntax ts = new TransferSyntax(TransferSyntax.TSType.JPEGBaselineProcess1);
image.SetTransferSyntax(ts);
image.SetDimension(0, (uint)1700);
image.SetDimension(1, (uint)2200);
ImageWriter writer = new ImageWriter();
gdcm.File file = writer.GetFile();
var ds = file.GetDataSet();
DataElement patientID = DataElementHelper.PatientID;
DataElement patientName = DataElementHelper.PatientName;
DataElement accessionNumber = DataElementHelper.AccessionNumber;
DataElement studyDate = DataElementHelper.StudyDate;
DataElement studyTime = DataElementHelper.StudyTime;
DataElement studyInstanceUID = DataElementHelper.StudyInstanceUID;
DataElement seriesInstanceUID = DataElementHelper.SeriesInstanceUID;
DataElement mediaStorage = DataElementHelper.SOPClassUID;
string studyUID = new gdcm.UIDGenerator().Generate();
string seriesUID = new gdcm.UIDGenerator().Generate();
//pixelData.SetArray(b, (uint)b.Length);
DataElementHelper.SetDataElement(ref patientName, "TEST^MARCUS");
DataElementHelper.SetDataElement(ref patientID, "0000000801");
DataElementHelper.SetDataElement(ref accessionNumber, "0000000801-12345");
DataElementHelper.SetDataElement(ref studyDate, DateTime.Now.ToString("yyyyMMdd"));
DataElementHelper.SetDataElement(ref studyTime, DateTime.Now.ToString("HHmmss"));
DataElementHelper.SetDataElement(ref studyInstanceUID, studyUID);
DataElementHelper.SetDataElement(ref seriesInstanceUID, seriesUID);
DataElementHelper.SetDataElement(ref mediaStorage, "1.2.840.10008.5.1.4.1.1.7");
ds.Insert(patientID);
ds.Insert(patientName);
ds.Insert(accessionNumber);
ds.Insert(studyDate);
ds.Insert(studyTime);
ds.Insert(studyInstanceUID);
ds.Insert(seriesInstanceUID);
ds.Insert(mediaStorage);
writer.SetImage(image);
writer.SetFileName("gdcm_test.dcm");
bool ret = writer.Write();
我們不得不[滾動我們自己的](ftp://medical.nema.org/medical/dicom/2011/) –