简体   繁体   English

(fo-dicom)如何修改DICOM文件并将其保存到新目录?

[英](fo-dicom) How can I modify and save a DICOM file to a new directory?

I want to modify the header of a DICOM and set two tags. 我想修改DICOM的标题并设置两个标签。 This works but then when I want to save it in a new file I get this Exception: 这可行,但是当我要将其保存在新文件中时,出现此异常:

NullReferenceException: Object reference not set to an instance of an object
Dicom.Network.NetworkManager.get_MachineName ()
Dicom.DicomFileMetaInformation.CreateSourceApplicationEntityTitle ()
Dicom.DicomFileMetaInformation..ctor (Dicom.DicomFileMetaInformation metaInfo)
Dicom.DicomFile.PreprocessFileMetaInformation ()
Dicom.DicomFile.Save (System.String fileName,   
Dicom.IO.Writer.DicomWriteOptions options)
DICOMConverter.addMaxMin () (at Assets/Scripts/DICOMConverter.cs:67)

My code of DICOMConverter.addMaxMin() is: 我的DICOMConverter.addMaxMin()代码是:

 var dicomFile = DicomFile.Open(DICOMFilePath);
 var dicomImage = new DicomImage(dicomFile.Dataset);
 var header = DicomPixelData.Create(dicomImage.Dataset);

 var pixelData = PixelDataFactory.Create(header, 0);

 for (int x = 0; x < Convert.ToInt32(dicomFile.Dataset.Get<string>(DicomTag.Columns)); x++)
 {
    for (int y = 0; y < Convert.ToInt32(dicomFile.Dataset.Get<string>(DicomTag.Rows)); y++)
    {
         if (pixelData.GetPixel(x, y) < minValue)
                    minValue = pixelData.GetPixel(x, y);
         if (pixelData.GetPixel(x, y) > maxValue)
                    maxValue = pixelData.GetPixel(x, y);
     }
  }

  dicomFile.Dataset.AddOrUpdate(DicomTag.LargestImagePixelValue, Convert.ToString(maxValue));
  dicomFile.Dataset.AddOrUpdate(DicomTag.SmallestImagePixelValue, Convert.ToString(minValue));

  dicomFile.Save(@"newDicom"); 

It throws the exception always when I try to use the Save() Method. 当我尝试使用Save()方法时,它总是抛出异常。
I used for this the file operation example from https://github.com/fo-dicom/fo-dicom , but it doesn't work properly. 我为此使用了https://github.com/fo-dicom/fo-dicom中的文件操作示例,但是它不能正常工作。

Has someone an idea for a better save solution or can me explain what I am missing? 有人对更好的保存解决方案有想法吗,或者我可以解释一下我所缺少的吗?

This exception happens, because for some reason your application has no platform specific implementation of NetworkManager set up correctly. 发生此异常是因为由于某种原因您的应用程序没有正确设置平台特定的NetworkManager实现。 This happens in the static constructor of NetworkManager class. 这发生在NetworkManager类的静态构造函数中。 But you can set it manually any time by NetworkManager.SetImplementation(..). 但是您可以随时通过NetworkManager.SetImplementation(..)手动进行设置。 Without any further information it is hard to say why there is no instance initialized, but there will be an other solution in next release of fo-dicom: 没有更多的信息,很难说为什么没有实例被初始化,但是在下一版的fo-dicom中将有另一个解决方案:

When writing the file to disk, fo-dicom sets the SourceApplicationEntityTile (0002,0016) and therefore tries to access the NetworkManager.LocalMachineName. 将文件写入磁盘时,fo-dicom会设置SourceApplicationEntityTile(0002,0016),因此尝试访问NetworkManager.LocalMachineName。 This pull request wants to reuse the SourceApplicationEntityTitle if the file was not created newly but cloned from an other file and therefore already has a SourceApplicationEntityTitle. 如果该文件不是新建的,而是从另一个文件克隆的,因此已经具有SourceApplicationEntityTitle,则该拉取请求希望重用SourceApplicationEntityTitle。 This would solve your problem. 这样可以解决您的问题。 Take a closer look at https://github.com/fo-dicom/fo-dicom/pull/615 仔细看看https://github.com/fo-dicom/fo-dicom/pull/615

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

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