尝试获取 DicomDataset 时获取 "DicomTag doesn't support values"

Getting "DicomTag doesn't support values" when trying to obtain DicomDataset

升级到 fo-dicom 4.0 后,我在尝试从 DICOMDIR 文件获取 DicomDataset 时开始出现 DicomDataException: 'DicomTag doesn't support values'

代码如下:

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)
            {
                //this is the problematic line
                var dicomDataset = imageRecord.GetValue<DicomSequence>(DicomTag.IconImageSequence, 0).Items.First();
                //more stuff
            }
        }
    }
}

使用以前的版本 (3.?) 我正在做 var dicomImage = imageRecord.Get<DicomSequence>(DicomTag.IconImageSequence).Items.First(); 并且工作得很好,但是升级后我收到了过时的警告,所以我将其更改为推荐的方法,即 GetValue .

如何使用当前版本的 fo-dicom 获取数据集?

最后,在深入研究了 fo-dicom 的 Gitter 和 GitHub 问题之后(以及 in the comments as well), I found that in 4.0 we should use GetSequence(DicomTag.IconImageSequence) instead of GetValue<DicomSequence>(DicomTag.IconImageSequence): when retrieving Sequences, using GetValue will throw. Several other Get methods have been added, such as GetValueOrDefault, GetValues<T> instead of GetValue<T[]>, and more, as can be seen in the project's Dataset test

此外,作为推论,我还发现 4.0 中另一个 API 与先前版本不兼容(我将 post 放在这里以防有人升级并迷失在更改中):在处理 DicomImage 时,我们不应该访问它的 .Dataset 来检索值,因为它也已被弃用。相反,我们应该存储对创建 DicomImage 的数据集的引用,以便检索标签值。