简体   繁体   English

用fo-dicom保存后DICOMDir文件损坏

[英]DICOMDir file getting corrupted after save with fo-dicom

I'm experiencing an issue with adding a file to a DICOMDir. 我在将文件添加到DICOMDir时遇到问题。 Based on this example I've successfully created and saved to disk an image from a series. 基于此示例,我成功创建了一系列图像并将其保存到磁盘。 Then, I tried adding that file to the DICOMDIR, so that the Dir references the new file, and, though the saving is successful, when I try to open the DICOMDir and its series again, I get a "Tag: (0088,0200) not found in dataset" exception. 然后,我尝试将该文件添加到DICOMDIR,以便Dir引用新文件,并且尽管保存成功,但是当我尝试再次打开DICOMDir及其系列时,我得到一个“标记:(0088,0200 )在数据集中找不到”)。

Code is as follows: 代码如下:

var dataset = new DicomDataset();
this.FillDataset(dataset); //this function copies several Tag values of an already existing DICOM Series file, such as Patient information
dataset.Add(DicomTag.PhotometricInterpretation, PhotometricInterpretation.Rgb.Value);
dataset.Add(DicomTag.Rows, (ushort)rows);
dataset.Add(DicomTag.Columns, (ushort)columns);

var pixelData = DicomPixelData.Create(dataset, true);
pixelData.AddFrame(buffer);
var dicomfile = new DicomFile(dataset);
var pathImage = Path.Combine(dirImages.FullName, imageFileName);
dicomfile.Save(pathImage); //Image is saved fine and it's well formed, I've checked opening it with an online DICOM viewer

var dicomdirPath = Path.Combine(studyPath, Constants.DICOMDIRFileName);
var dicomdir = DicomDirectory.Open(dicomdirPath);
dicomdir.AddFile(dicomfile, $@"Images\{imageFileName}");
dicomdir.Save(dicomdirPath); //this executes without problems and the DICOMDIR is saved

And this is the series opening method: 这是系列的打开方法:

var dicomDirectory = await DicomDirectory.OpenAsync(dicomdirPath);
foreach (var patientRecord in dicomDirectory.RootDirectoryRecordCollection)
{
    foreach (var studyRecord in patientRecord.LowerLevelDirectoryRecordCollection)
    {
        foreach (var seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection)
        {
            foreach (var imageRecord in seriesRecord.LowerLevelDirectoryRecordCollection)
            {
                var dicomDataset = imageRecord.GetSequence(DicomTag.IconImageSequence).Items.First(); //This line works fine before saving the image in the method above, but throws when opening the same study
                //Load data and series from dataset
            }
        }
    }
}

I don't know if I'm missing something regarding saving a DICOMDir file, or if it's an error. 我不知道是否丢失了有关保存DICOMDir文件的内容,或者是否出错。

You try to access the IconImageSequence (0088,0200) that is obviously not present. 您尝试访问显然不存在的IconImageSequence(0088,0200)。 DicomDir does only contain some main data of the image. DicomDir仅包含图像的一些主要数据。 When Adding an image to the dicomdir it is up to you to add additional information. 将图像添加到dicomdir时,由您决定是否要添加其他信息。 One of those optional informations, that fo-dicom does not automatically add, is the Icon. 图标是fo-dicom不会自动添加的那些可选信息之一。 DicomDir allows to contain a small icon to show if you want to display some previews quickly. DicomDir允许包含一个小图标,以显示是否要快速显示一些预览。

Actually imageRecord should contain all the informations you might need like instanceuid or filename etc. 实际上, imageRecord应该包含您可能需要的所有信息,例如instanceuid或filename等。

I don't know why the line of code worked well before you stored the file with fo-dicom. 我不知道为什么在使用fo-dicom存储文件之前代码行运行良好。 I assume there already was a DICOMDIR created with some other application that included the Icon? 我假设已经使用其他包含Icon的应用程序创建了DICOMDIR? then the foreach crashes when you reach the newly added entry. 然后当您到达新添加的条目时,foreach崩溃。

You could either add an Icon yourself when adding the new instance to the DICOMDIR, or you could add a check like "if imageRecord.TryGetSequece(iconImageSequence, out seq).." to handle the cases where there are no icons. 您可以在将新实例添加到DICOMDIR时自己添加一个Icon,也可以添加“ if imageRecord.TryGetSequece(iconImageSequence,out seq)..”之类的检查以处理没有图标的情况。

I recommend to add the check anyway, because you might read a DICOMDIR with a reference to some strucured report some day and those structured reports do not have pixel data and therefore will not have an icon included. 我建议还是添加检查,因为有一天您可能会阅读DICOMDIR并参考一些结构化报告,并且那些结构化报告没有像素数据,因此不会包含图标。

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

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