You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用fo-dicom 4.0.7生成DICOMDIR时Number of Frames标签缺失问题求助

Solution for Missing "Number of Frames" Tag in DICOMDIR with fo-dicom 4.0.7

I’ve run into identical issues with fo-dicom’s DicomDirectory not pulling in non-default tags automatically, so here are two targeted fixes for your scenario:

1. Manually Add the Tag to the Directory Record

The AddFile() method only copies a predefined set of tags from your source DICOM file into the DICOMDIR record. Since "Number of Frames" (0028,0008) isn’t in that default set, you can explicitly fetch it from your source file and inject it into the corresponding record right after adding the file:

var sourcePath = Path.Combine(tempDirectory, "DICOM", $"PATIENT{i + 1}", $"STUDY{j + 1}", $"SERIES{k + 1}", $"SUBSERIES{l + 1}");
var dicomDir = new DicomDirectory { AutoValidate = false };
var numberOfFramesTag = DicomTag.NumberOfFrames;

foreach (var file in new DirectoryInfo(tempDirectory).GetFiles("*.*", SearchOption.AllDirectories)) {
    try {
        var dicomFile = DicomFile.Open(file.FullName);
        if (dicomFile != null) {
            var referenceField = file.FullName.Replace(tempDirectory, string.Empty).Trim('\\');
            // Add the file and capture the created directory record
            var directoryRecord = dicomDir.AddFile(dicomFile, referenceField);
            
            // Check if the source file has the tag, then add it to the record
            if (dicomFile.Dataset.Contains(numberOfFramesTag)) {
                var frameCount = dicomFile.Dataset.GetSingleValue<int>(numberOfFramesTag);
                directoryRecord.Dataset.Add(numberOfFramesTag, frameCount);
            }
        }
    } catch (Exception ex) {
        Log.Error(ex, ex.Message);
    }
}

var dicomDirPath = Path.Combine(tempDirectory, "DICOMDIR");
dicomDir.Save(dicomDirPath);
resultDirectories.Add(dicomDirPath);

2. Extend the Default Included Tags (Global Fix)

If you want "Number of Frames" to be included for all files added to any DicomDirectory instance, you can modify the static IncludeTags collection once before creating your directory. This avoids manual tag injection for every file:

// Add the tag to fo-dicom's default included tags list
DicomDirectory.IncludeTags.Add(DicomTag.NumberOfFrames);

var dicomDir = new DicomDirectory { AutoValidate = false };
// Rest of your existing code remains unchanged...

Why This Happens

fo-dicom’s DicomDirectory is configured to only copy a standard subset of DICOM tags into directory records by default. "Number of Frames" falls outside this subset, so you need to either add it globally or insert it per-record as shown above.

Note: In fo-dicom 4.x, IncludeTags is a static property, so modifying it affects all DicomDirectory instances in your application. Use the first approach if you only need this tag for specific DICOMDIRs.

内容的提问来源于stack exchange,提问作者Romeo Lazarciuc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 15:07:42