简体   繁体   English

使用灰度软拷贝演示 State 与 fo-dicom

[英]Using Grayscale Softcopy Presentation State with fo-dicom

I would like to add markings to a DICOM image (for example, drawings or textual comments) using Grayscale Softcopy Presentation State IOD.我想使用灰度软拷贝演示 State IOD 为 DICOM 图像(例如,绘图或文本注释)添加标记。

I have created a DICOM image object like this:我创建了一个 DICOM 图像 object,如下所示:

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");

Then I have created a Grayscale Softcopy Presentation State object like this:然后我创建了一个灰度软拷贝演示 State object,如下所示:

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"));

        }

I do not really understand how this two object are connected with each other?我不太明白这两个object是怎么相互连接的?

The Presentation State is connected to the Image by ReferencedSeriesSequence . Presentation State 通过ReferencedSeriesSequence连接到图像。 I see you are filling that attribute in, so this should be ok.我看到您正在填写该属性,所以这应该没问题。 Now you also need to save the Presentation State as a separate DICOM file, exactly the way you save the image.现在您还需要将演示文稿 State 保存为单独的 DICOM 文件,与保存图像的方式完全相同。 In order to check the result, just use fo-dicom to open the PS file and read from it, eg:为了检查结果,只需使用 fo-dicom 打开 PS 文件并从中读取,例如:

 var file = DicomFile.Open(your_path, readOption: FileReadOption.ReadAll);
 var dicomDataset = file.Dataset;
 var isItem = dicomDataset.Contains(DicomTag.SOPInstanceUID);
....

You can easily check dicomDataset above in the debugger and see that all the attributes you put in the PS should be there.您可以在调试器中轻松检查上面的 dicomDataset 并查看您放入 PS 中的所有属性都应该在那里。

I've done the same, but the problem is I couldn't find a free DICOM viewer that visualizes both the image and the Presentation State properly.我也做了同样的事情,但问题是我找不到一个免费的 DICOM 查看器,它可以正确地可视化图像和演示 State。 Still looking for one....还在找一个。。。。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM