将灰度软拷贝呈现状态与 fo-dicom 一起使用
Using Grayscale Softcopy Presentation State with fo-dicom
我想使用 Grayscale Softcopy Presentation State IOD 向 DICOM 图像(例如绘图或文本注释)添加标记。
我创建了一个 DICOM 图像对象,如下所示:
Bitmap bitmap = new Bitmap(path);
bitmap = GetValidImage(bitmap);
int rows, columns;
byte[] pixels = GetPixels(bitmap, out rows, out columns);
MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);
DicomDataset imageDataset = new DicomDataset();
FillDataset(imageDataset);
DicomDataset annotationdataset = new DicomDataset();
FillAnnotation(imageDataset, annotationdataset);
imageDataset.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Rgb.Value);
imageDataset.Add(DicomTag.Rows, (ushort)rows);
imageDataset.Add(DicomTag.Columns, (ushort)columns);
imageDataset.Add(DicomTag.BitsAllocated, (ushort)8);
DicomPixelData pixelData = DicomPixelData.Create(imageDataset, true);
pixelData.BitsStored = 8;
pixelData.SamplesPerPixel = 3;
pixelData.HighBit = 7;
pixelData.PixelRepresentation = 0;
pixelData.PlanarConfiguration = 0;
pixelData.AddFrame(buffer);
DicomFile dicomfile = new DicomFile(imageDataset);
if (File.Exists("test.dcm"))
File.Delete("test.dcm");
dicomfile.Save("test.dcm");
然后我创建了一个灰度软拷贝演示状态对象,如下所示:
private static void FillAnnotation(DicomDataset imageDataset, DicomDataset annotationDataset)
{
//type 1 attributes.
annotationDataset.Add(DicomTag.SOPClassUID, DicomUID.GrayscaleSoftcopyPresentationStateStorage);
annotationDataset.Add(DicomTag.StudyInstanceUID, _studyInstanceUid);
annotationDataset.Add(DicomTag.SeriesInstanceUID, _seriesInstanceUID);
annotationDataset.Add(DicomTag.SOPInstanceUID, GenerateUid());
//type 2 attributes
annotationDataset.Add(DicomTag.PatientID, _patientId);
annotationDataset.Add(DicomTag.PatientName, _patientName);
annotationDataset.Add(DicomTag.PatientBirthDate, _patientBirthDate);
annotationDataset.Add(DicomTag.PatientSex, _patientSex);
annotationDataset.Add(DicomTag.StudyDate, _studyDateTime);
annotationDataset.Add(DicomTag.StudyTime, _studyDateTime);
annotationDataset.Add(DicomTag.AccessionNumber, _accessionNumber);
annotationDataset.Add(DicomTag.ReferringPhysicianName, _referringPhysicianName);
annotationDataset.Add(DicomTag.StudyID, _studyID);
annotationDataset.Add(DicomTag.SeriesNumber, _seriesNumber);
//annotationDataset.Add(DicomTag.ModalitiesInStudy, "CR");
annotationDataset.Add(DicomTag.Modality, _modality);
annotationDataset.Add(DicomTag.Manufacturer, _manufacturer);
annotationDataset.Add(DicomTag.PresentationCreationDate, _presentationCreationDateTime);
annotationDataset.Add(DicomTag.PresentationCreationTime, _presentationCreationDateTime);
DicomDataset serie = new DicomDataset();
serie.Add(DicomTag.SeriesInstanceUID, _seriesInstanceUID);
serie.Add(DicomTag.ReferencedImageSequence, imageDataset);
annotationDataset.Add(DicomTag.ReferencedSeriesSequence, serie);
DicomDataset displayedArea = new DicomDataset();
displayedArea.Add(DicomTag.DisplayedAreaTopLeftHandCorner, "50\50");
displayedArea.Add(DicomTag.DisplayedAreaBottomRightHandCorner, "100\100");
displayedArea.Add(DicomTag.PresentationSizeMode, "SCALE TO FIT");
annotationDataset.Add(DicomTag.DisplayedAreaSelectionSequence, displayedArea);
annotationDataset.Add(DicomTag.ICCProfile, Byte.Parse("00000001"));
}
我不太明白这两个对象是如何相互联系的?
Presentation State 通过 ReferencedSeriesSequence 连接到图像。我看到你正在填写那个属性,所以这应该没问题。现在您还需要将演示状态保存为单独的 DICOM 文件,这与您保存图像的方式完全相同。
为了检查结果,只需使用 fo-dicom 打开 PS 文件并从中读取,例如:
var file = DicomFile.Open(your_path, readOption: FileReadOption.ReadAll);
var dicomDataset = file.Dataset;
var isItem = dicomDataset.Contains(DicomTag.SOPInstanceUID);
....
您可以在调试器中轻松检查上面的 dicomDataset,并看到您放入 PS 中的所有属性都应该存在。
我也做了同样的事情,但问题是我找不到免费的 DICOM 查看器来正确显示图像和演示状态。还在找一个....
我想使用 Grayscale Softcopy Presentation State IOD 向 DICOM 图像(例如绘图或文本注释)添加标记。
我创建了一个 DICOM 图像对象,如下所示:
Bitmap bitmap = new Bitmap(path);
bitmap = GetValidImage(bitmap);
int rows, columns;
byte[] pixels = GetPixels(bitmap, out rows, out columns);
MemoryByteBuffer buffer = new MemoryByteBuffer(pixels);
DicomDataset imageDataset = new DicomDataset();
FillDataset(imageDataset);
DicomDataset annotationdataset = new DicomDataset();
FillAnnotation(imageDataset, annotationdataset);
imageDataset.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Rgb.Value);
imageDataset.Add(DicomTag.Rows, (ushort)rows);
imageDataset.Add(DicomTag.Columns, (ushort)columns);
imageDataset.Add(DicomTag.BitsAllocated, (ushort)8);
DicomPixelData pixelData = DicomPixelData.Create(imageDataset, true);
pixelData.BitsStored = 8;
pixelData.SamplesPerPixel = 3;
pixelData.HighBit = 7;
pixelData.PixelRepresentation = 0;
pixelData.PlanarConfiguration = 0;
pixelData.AddFrame(buffer);
DicomFile dicomfile = new DicomFile(imageDataset);
if (File.Exists("test.dcm"))
File.Delete("test.dcm");
dicomfile.Save("test.dcm");
然后我创建了一个灰度软拷贝演示状态对象,如下所示:
private static void FillAnnotation(DicomDataset imageDataset, DicomDataset annotationDataset)
{
//type 1 attributes.
annotationDataset.Add(DicomTag.SOPClassUID, DicomUID.GrayscaleSoftcopyPresentationStateStorage);
annotationDataset.Add(DicomTag.StudyInstanceUID, _studyInstanceUid);
annotationDataset.Add(DicomTag.SeriesInstanceUID, _seriesInstanceUID);
annotationDataset.Add(DicomTag.SOPInstanceUID, GenerateUid());
//type 2 attributes
annotationDataset.Add(DicomTag.PatientID, _patientId);
annotationDataset.Add(DicomTag.PatientName, _patientName);
annotationDataset.Add(DicomTag.PatientBirthDate, _patientBirthDate);
annotationDataset.Add(DicomTag.PatientSex, _patientSex);
annotationDataset.Add(DicomTag.StudyDate, _studyDateTime);
annotationDataset.Add(DicomTag.StudyTime, _studyDateTime);
annotationDataset.Add(DicomTag.AccessionNumber, _accessionNumber);
annotationDataset.Add(DicomTag.ReferringPhysicianName, _referringPhysicianName);
annotationDataset.Add(DicomTag.StudyID, _studyID);
annotationDataset.Add(DicomTag.SeriesNumber, _seriesNumber);
//annotationDataset.Add(DicomTag.ModalitiesInStudy, "CR");
annotationDataset.Add(DicomTag.Modality, _modality);
annotationDataset.Add(DicomTag.Manufacturer, _manufacturer);
annotationDataset.Add(DicomTag.PresentationCreationDate, _presentationCreationDateTime);
annotationDataset.Add(DicomTag.PresentationCreationTime, _presentationCreationDateTime);
DicomDataset serie = new DicomDataset();
serie.Add(DicomTag.SeriesInstanceUID, _seriesInstanceUID);
serie.Add(DicomTag.ReferencedImageSequence, imageDataset);
annotationDataset.Add(DicomTag.ReferencedSeriesSequence, serie);
DicomDataset displayedArea = new DicomDataset();
displayedArea.Add(DicomTag.DisplayedAreaTopLeftHandCorner, "50\50");
displayedArea.Add(DicomTag.DisplayedAreaBottomRightHandCorner, "100\100");
displayedArea.Add(DicomTag.PresentationSizeMode, "SCALE TO FIT");
annotationDataset.Add(DicomTag.DisplayedAreaSelectionSequence, displayedArea);
annotationDataset.Add(DicomTag.ICCProfile, Byte.Parse("00000001"));
}
我不太明白这两个对象是如何相互联系的?
Presentation State 通过 ReferencedSeriesSequence 连接到图像。我看到你正在填写那个属性,所以这应该没问题。现在您还需要将演示状态保存为单独的 DICOM 文件,这与您保存图像的方式完全相同。 为了检查结果,只需使用 fo-dicom 打开 PS 文件并从中读取,例如:
var file = DicomFile.Open(your_path, readOption: FileReadOption.ReadAll);
var dicomDataset = file.Dataset;
var isItem = dicomDataset.Contains(DicomTag.SOPInstanceUID);
....
您可以在调试器中轻松检查上面的 dicomDataset,并看到您放入 PS 中的所有属性都应该存在。
我也做了同样的事情,但问题是我找不到免费的 DICOM 查看器来正确显示图像和演示状态。还在找一个....