目前我正在编写一个转换为JPEG
转换的模块DICOM Image
。经过分析,我已经完成了标签渲染,现在图像没有在DICOM
文件中正确渲染。
是否有任何算法可以JPEG
将DICOM
.
目前我正在编写一个转换为JPEG
转换的模块DICOM Image
。经过分析,我已经完成了标签渲染,现在图像没有在DICOM
文件中正确渲染。
是否有任何算法可以JPEG
将DICOM
.
继续 Matthieu 的回复,这里是使用优秀的 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();
please have a look at the mdcm C# DICOM library, originally written by Colby Dillion. He has developed managed C++ "bridges" to the IJG/LibJPEG and OpenJPEG code bases, so mdcm provides both 8/12/16-bit lossy and lossless JPEG support as well as JPEG-2000 support.
Colby's original library has WinForms dependencies. I have created a Silverlight and WPF targeted fork of mdcm here. The WPF version of the library can fully utilize the same JPEG(-2000) codecs that Colby originally implemented.
The Silverlight version on the other hand currently cannot benefit from these codecs. I have made some attempts to apply the FJCore and LibJpeg.Net libraries for lossy JPEG support in Silverlight, but these libraries only support 8-bit images at the moment.
Regards,
Anders @ 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
不需要解压缩/重新压缩,那会浪费资源。
.NET 本身没有支持 DICOM 的功能。您将需要使用库。我不知道有什么免费的,但我使用了 LeadTools,它会做到(收费)。但我只会给它一个 4/10,我会重新开始你寻找其他选择。