本文整理汇总了C#中DicomFile.Load方法的典型用法代码示例。如果您正苦于以下问题:C# DicomFile.Load方法的具体用法?C# DicomFile.Load怎么用?C# DicomFile.Load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DicomFile
的用法示例。
在下文中一共展示了DicomFile.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnExecute
protected override void OnExecute(CommandProcessor theProcessor)
{
if (!File.Exists(_path))
{
Platform.Log(LogLevel.Error, "Unexpected error finding file to add to XML {0}", _path);
throw new ApplicationException("Unexpected error finding file to add to XML {0}" + _path);
}
var finfo = new FileInfo(_path);
long fileSize = finfo.Length;
var dicomFile = new DicomFile(_path);
dicomFile.Load(DicomReadOptions.StorePixelDataReferences | DicomReadOptions.Default);
_sopInstanceUid = dicomFile.DataSet[DicomTags.SopInstanceUid];
_seriesInstanceUid = dicomFile.DataSet[DicomTags.SeriesInstanceUid];
// Setup the insert parameters
if (false == _stream.AddFile(dicomFile, fileSize))
{
Platform.Log(LogLevel.Error, "Unexpected error adding SOP to XML Study Descriptor for file {0}",
_path);
throw new ApplicationException("Unexpected error adding SOP to XML Study Descriptor for SOP: " +
dicomFile.MediaStorageSopInstanceUid);
}
}
示例2: WriteOptionsTest
public void WriteOptionsTest(DicomFile sourceFile, DicomWriteOptions options)
{
bool result = sourceFile.Save(options);
Assert.AreEqual(result, true);
DicomFile newFile = new DicomFile(sourceFile.Filename);
DicomReadOptions readOptions = DicomReadOptions.Default;
newFile.Load(readOptions);
Assert.AreEqual(sourceFile.DataSet.Equals(newFile.DataSet), true);
// update a tag, and make sure it shows they're different
newFile.DataSet[DicomTags.PatientsName].Values = "NewPatient^First";
Assert.AreEqual(sourceFile.DataSet.Equals(newFile.DataSet), false);
// Now update the original file with the name, and they should be the same again
sourceFile.DataSet[DicomTags.PatientsName].Values = "NewPatient^First";
Assert.AreEqual(sourceFile.DataSet.Equals(newFile.DataSet), true);
// Return the original string value.
sourceFile.DataSet[DicomTags.PatientsName].SetStringValue("Patient^Test");
}
示例3: TestFile
public void TestFile()
{
string filename = "OutOfRange.dcm";
DicomFile file = new DicomFile(filename, new DicomAttributeCollection(), new DicomAttributeCollection());
SetupMR(file.DataSet);
SetupMetaInfo(file);
DicomTag tag = new DicomTag(0x00030010, "Test", "TestBad", DicomVr.LOvr, false, 1, 1, false);
file.DataSet[tag].SetStringValue("Test");
file.Save(filename);
file = new DicomFile(filename);
file.DataSet.IgnoreOutOfRangeTags = true;
file.Load();
Assert.IsNotNull(file.DataSet.GetAttribute(tag));
file = new DicomFile(filename);
file.DataSet.IgnoreOutOfRangeTags = false;
try
{
file.Load();
Assert.Fail("file.Load failed");
}
catch (DicomException)
{
}
}
示例4: LosslessImageTest
public static void LosslessImageTest(TransferSyntax syntax, DicomFile theFile)
{
if (File.Exists(theFile.Filename))
File.Delete(theFile.Filename);
DicomFile saveCopy = new DicomFile(theFile.Filename, theFile.MetaInfo.Copy(), theFile.DataSet.Copy());
theFile.ChangeTransferSyntax(syntax);
theFile.Save(DicomWriteOptions.ExplicitLengthSequence);
DicomFile newFile = new DicomFile(theFile.Filename);
newFile.Load(DicomReadOptions.Default);
newFile.ChangeTransferSyntax(saveCopy.TransferSyntax);
List<DicomAttributeComparisonResult> list = new List<DicomAttributeComparisonResult>();
bool result = newFile.DataSet.Equals(saveCopy.DataSet, ref list);
StringBuilder sb = new StringBuilder();
foreach (DicomAttributeComparisonResult compareResult in list)
sb.AppendFormat("Comparison Failure: {0}, ", compareResult.Details);
Assert.IsTrue(result,sb.ToString());
}
示例5: ButtonLoadFile_Click
private void ButtonLoadFile_Click(object sender, EventArgs e)
{
openFileDialog.DefaultExt = "dcm";
openFileDialog.ShowDialog();
DicomFile dicomFile = new DicomFile(openFileDialog.FileName);
dicomFile.Load(DicomReadOptions.Default);
_theStream.AddFile(dicomFile);
}
示例6: Load
public void Load()
{
_dicomFile = new DicomFile(_sourceFilename);
try
{
_dicomFile.Load();
}
catch (Exception e)
{
Logger.LogErrorException(e, "Unexpected exception loading DICOM file: {0}", _sourceFilename);
}
}
示例7: Load
public void Load()
{
_dicomFile = new DicomFile(_sourceFilename);
try
{
_dicomFile.Load();
}
catch (Exception e)
{
Platform.Log(LogLevel.Error, e, "Unexpected exception loading DICOM file: {0}", _sourceFilename);
}
}
示例8: AddPath
/// <summary>
/// Searches the given path for DICOM object files, automatically parsing for patient and study instance information.
/// </summary>
/// <param name="path">The file path on which to search for files.</param>
/// <param name="recursive">True if the paths should be processed recursively; False otherwise.</param>
public void AddPath(string path, bool recursive)
{
if (File.Exists(path))
{
try
{
DicomFile dcf = new DicomFile(path);
dcf.Load(DicomReadOptions.Default | DicomReadOptions.DoNotStorePixelDataInDataSet);
List<string> s = InternalAddStudy(dcf.DataSet[DicomTags.PatientId].ToString(), dcf.DataSet[DicomTags.PatientsName].ToString(), dcf.DataSet[DicomTags.StudyInstanceUid].ToString());
s.Add(path);
}
catch (DicomException) {}
}
else if (recursive && Directory.Exists(path))
{
foreach (string subpaths in Directory.GetFileSystemEntries(path))
AddPath(subpaths);
}
}
示例9: LoadFiles
private void LoadFiles(DirectoryInfo dir)
{
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
DicomFile dicomFile = new DicomFile(file.FullName);
try
{
DicomReadOptions options = new DicomReadOptions();
dicomFile.Load(options);
_theStream.AddFile(dicomFile);
/*
if (true == dicomFile.Load())
{
_theStream.AddFile(dicomFile);
}
* */
}
catch (DicomException)
{
// TODO: Add some logging for failed files
}
}
String[] subdirectories = Directory.GetDirectories(dir.FullName);
foreach (String subPath in subdirectories)
{
DirectoryInfo subDir = new DirectoryInfo(subPath);
LoadFiles(subDir);
continue;
}
}
示例10: LossyImageTest
public static void LossyImageTest(TransferSyntax syntax, DicomFile theFile)
{
if (File.Exists(theFile.Filename))
File.Delete(theFile.Filename);
DicomFile saveCopy = new DicomFile(theFile.Filename, theFile.MetaInfo.Copy(), theFile.DataSet.Copy());
theFile.ChangeTransferSyntax(syntax);
theFile.Save(DicomWriteOptions.ExplicitLengthSequence);
DicomFile newFile = new DicomFile(theFile.Filename);
newFile.Load(DicomReadOptions.Default);
newFile.ChangeTransferSyntax(saveCopy.TransferSyntax);
Assert.IsFalse(newFile.DataSet.Equals(saveCopy.DataSet));
Assert.IsTrue(newFile.DataSet.Contains(DicomTags.DerivationDescription));
Assert.IsTrue(newFile.DataSet.Contains(DicomTags.LossyImageCompression));
Assert.IsTrue(newFile.DataSet.Contains(DicomTags.LossyImageCompressionMethod));
Assert.IsTrue(newFile.DataSet.Contains(DicomTags.LossyImageCompressionRatio));
Assert.IsFalse(newFile.DataSet[DicomTags.DerivationDescription].IsEmpty);
Assert.IsFalse(newFile.DataSet[DicomTags.LossyImageCompression].IsEmpty);
Assert.IsFalse(newFile.DataSet[DicomTags.LossyImageCompressionMethod].IsEmpty);
Assert.IsFalse(newFile.DataSet[DicomTags.LossyImageCompressionRatio].IsEmpty);
Assert.IsFalse(newFile.DataSet[DicomTags.DerivationDescription].IsNull);
Assert.IsFalse(newFile.DataSet[DicomTags.LossyImageCompression].IsNull);
Assert.IsFalse(newFile.DataSet[DicomTags.LossyImageCompressionMethod].IsNull);
Assert.IsFalse(newFile.DataSet[DicomTags.LossyImageCompressionRatio].IsNull);
// Make copies of datasets, delete the tags that don't match, and ensure the same
DicomAttributeCollection newDataSet = newFile.DataSet.Copy(true, true, true);
DicomAttributeCollection oldDataSet = theFile.DataSet.Copy(true, true, true);
oldDataSet.RemoveAttribute(DicomTags.PixelData);
newDataSet.RemoveAttribute(DicomTags.PixelData);
oldDataSet.RemoveAttribute(DicomTags.DerivationDescription);
newDataSet.RemoveAttribute(DicomTags.DerivationDescription);
oldDataSet.RemoveAttribute(DicomTags.LossyImageCompression);
newDataSet.RemoveAttribute(DicomTags.LossyImageCompression);
oldDataSet.RemoveAttribute(DicomTags.LossyImageCompressionMethod);
newDataSet.RemoveAttribute(DicomTags.LossyImageCompressionMethod);
oldDataSet.RemoveAttribute(DicomTags.LossyImageCompressionRatio);
newDataSet.RemoveAttribute(DicomTags.LossyImageCompressionRatio);
oldDataSet.RemoveAttribute(DicomTags.PhotometricInterpretation);
newDataSet.RemoveAttribute(DicomTags.PhotometricInterpretation);
List<DicomAttributeComparisonResult> results = new List<DicomAttributeComparisonResult>();
bool check = oldDataSet.Equals(newDataSet, ref results);
Assert.IsTrue(check, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
}
示例11: LoadFile
/// <summary>
/// Load a <see cref="DicomFile"/> for the storage instance.
/// </summary>
/// <remarks>
/// If the constructor that supplies a <see cref="DicomFile"/> is used, that file is returned.
/// Otherwise, the file is loaded and returned. Note that a reference is not kept for the file
/// in this case.
/// </remarks>
/// <returns></returns>
public DicomFile LoadFile()
{
if (_dicomFile != null)
return _dicomFile;
DicomFile theFile = new DicomFile(_filename);
theFile.Load(DicomReadOptions.StorePixelDataReferences | DicomReadOptions.Default);
StudyInstanceUid = theFile.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty);
_patientsName = theFile.DataSet[DicomTags.PatientsName].GetString(0, string.Empty);
_patientId = theFile.DataSet[DicomTags.PatientId].GetString(0, string.Empty);
MetaInfoFileLength = theFile.MetaInfoFileLength;
return theFile;
}
示例12: SQUNTests
public void SQUNTests()
{
uint fakeTag = 0x00880199; // IconImageSequence is 0x00880200
DicomTag fakeSQTag = new DicomTag(fakeTag, "Fake Icon", "FakeIcon", DicomVr.SQvr, false, 1, 1, false);
if (DicomTagDictionary.TagDictionary.ContainsKey(fakeTag))
DicomTagDictionary.TagDictionary.Remove(fakeTag);
DicomTagDictionary.TagDictionary.Add(fakeTag, fakeSQTag);
DicomFile file = new DicomFile("SQUNTest.dcm");
DicomAttributeCollection dataSet = file.DataSet;
SetupMetaInfo(file);
SetupMR(dataSet);
DicomSequenceItem item = new DicomSequenceItem();
item[DicomTags.PhotometricInterpretation].AppendString("MONOCHROME1");
item[DicomTags.Rows].AppendUInt16(4);
item[DicomTags.Columns].AppendUInt16(4);
item[DicomTags.BitsAllocated].AppendUInt16(8);
item[DicomTags.BitsStored].AppendUInt16(8);
item[DicomTags.HighBit].AppendUInt16(7);
item[DicomTags.PixelData].Values = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
dataSet[fakeSQTag].AddSequenceItem(item);
// Save the file
DicomFile originalFile = new DicomFile("", file.MetaInfo.Copy(), file.DataSet.Copy());
DicomTagDictionary.TagDictionary.Remove(fakeTag);
List<DicomAttributeComparisonResult> results = new List<DicomAttributeComparisonResult>();
bool compare;
DicomReadOptions readOptions = DicomReadOptions.Default;
// Little Endian Tests
file.TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
// Implicit Little Endian, No tag in the Dictionary, Explicit Length SQ
Assert.IsTrue(file.Save(DicomWriteOptions.ExplicitLengthSequence), "UN File Save");
DicomFile newFile = new DicomFile(file.Filename);
newFile.Load(readOptions);
Assert.AreNotEqual(originalFile.DataSet.Equals(newFile.DataSet), true);
DicomFile saveUNfile = newFile;
// Implicit Little Endian, No tag in the Dictionary, Implicit Length SQ
// Parser knows its a SQ from implicit length SQ
Assert.IsTrue(file.Save(DicomWriteOptions.ExplicitLengthSequenceItem), "UN File Save");
newFile = new DicomFile(file.Filename);
newFile.Load(readOptions);
results = new List<DicomAttributeComparisonResult>();
compare = originalFile.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
// Implicit Little Endian, No tag in the Dictionary, Implicit Length SQ
// Parser knows its a SQ from implicit length SQ
Assert.IsTrue(file.Save(DicomWriteOptions.None), "UN File Save");
newFile = new DicomFile(file.Filename);
newFile.Load(readOptions);
results = new List<DicomAttributeComparisonResult>();
compare = originalFile.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
file = saveUNfile;
file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
// Explicit Little Endian, No tag in the dictionary, UN SQ
// Parser keeps tag as UN
Assert.IsTrue(file.Save(DicomWriteOptions.None), "UN File Save");
newFile = new DicomFile(file.Filename);
newFile.Load(readOptions);
results = new List<DicomAttributeComparisonResult>();
compare = file.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
Assert.AreNotEqual(originalFile.DataSet.Equals(newFile.DataSet), true);
file.TransferSyntax = TransferSyntax.ExplicitVrBigEndian;
// Explicit Big Endian, No tag in the dictionary, UN SQ
// Parser keeps tag as UN
Assert.IsTrue(file.Save(DicomWriteOptions.None), "UN File Save");
newFile = new DicomFile(file.Filename);
newFile.Load(readOptions);
results = new List<DicomAttributeComparisonResult>();
compare = file.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
Assert.AreNotEqual(originalFile.DataSet.Equals(newFile.DataSet), true);
// Now add the tag into thedictionary
DicomTagDictionary.TagDictionary.Add(fakeTag, fakeSQTag);
file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
// Note, if we add parsing of SQ UN tags, the result of this test would change
// Explicit Little Endian, Tag in the dictionary, UN SQ
// Parser keeps tag as UN
Assert.IsTrue(file.Save(DicomWriteOptions.None), "UN File Save");
//.........这里部分代码省略.........
示例13: LosslessImageTestWithConversion
public static void LosslessImageTestWithConversion(TransferSyntax syntax, DicomFile theFile)
{
if (File.Exists(theFile.Filename))
File.Delete(theFile.Filename);
DicomFile saveCopy = new DicomFile(theFile.Filename, theFile.MetaInfo.Copy(), theFile.DataSet.Copy());
theFile.ChangeTransferSyntax(syntax);
theFile.Save(DicomWriteOptions.ExplicitLengthSequence);
DicomFile newFile = new DicomFile(theFile.Filename);
newFile.Load(DicomReadOptions.Default);
newFile.ChangeTransferSyntax(saveCopy.TransferSyntax);
Assert.IsFalse(newFile.DataSet.Equals(saveCopy.DataSet));
}
示例14: AddDicomFileValues
/// <summary>
/// Adds the dicom file values.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <exception cref="FileNotFoundException"/>
public void AddDicomFileValues(string filePath)
{
if (!File.Exists(filePath))
throw new FileNotFoundException(filePath);
DicomFile dicomFile = new DicomFile(filePath);
dicomFile.Load();
AddDicomFileValues(dicomFile.DataSet);
}
示例15: StandardAttributeTest
public void StandardAttributeTest()
{
DicomFile file = new DicomFile("UNTest.dcm");
DicomAttributeCollection dataSet = file.DataSet;
SetupMetaInfo(file);
SetupMR(dataSet);
dataSet[DicomTags.RetrieveAeTitle].SetStringValue("TESTAE");
dataSet[DicomTags.RetrieveAeTitle].AppendString("TESTAE2");
dataSet[DicomTags.RetrieveAeTitle].AppendString("TESTAE3");
dataSet[DicomTags.RetrieveAeTitle].AppendString("TESTAE4");
dataSet[DicomTags.InstitutionAddress].SetStringValue("1224 Milwaukee Ave.");
dataSet[DicomTags.TimeRange].SetFloat32(0,1.111111f);
dataSet[DicomTags.TimeRange].AppendFloat32(2.222222f);
dataSet[DicomTags.RecommendedDisplayFrameRateInFloat].AppendFloat32(2.222222f);
dataSet[DicomTags.ReferencePixelX0].AppendInt32(101010);
dataSet[DicomTags.VerticesOfThePolygonalExposureControlSensingRegion].AppendInt16(324);
dataSet[DicomTags.VerticesOfThePolygonalExposureControlSensingRegion].AppendInt16(111);
dataSet[DicomTags.VerticesOfThePolygonalExposureControlSensingRegion].AppendInt16(1234);
dataSet[DicomTags.DimensionIndexValues].AppendInt32(123456);
dataSet[DicomTags.DimensionIndexValues].AppendInt32(789);
dataSet[DicomTags.DimensionIndexValues].AppendInt32(98765);
dataSet[DicomTags.PixelDataProviderUrl].SetStringValue("http://www.clearcanvas.ca");
dataSet[DicomTags.EncapsulatedDocument].Values = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
dataSet[DicomTags.VectorGridData].Values = new[] { 1234f, .01010f, 31231.31231f, 41414.4141414f };
DicomAttributeCollection originalDataSet = file.DataSet.Copy();
DicomAttributeCollection originalMetaInfo = file.MetaInfo.Copy();
DicomFile originalFile = new DicomFile("", originalMetaInfo, originalDataSet);
// Force a sampling of tags to UN
ConvertAttributeToUN(dataSet, DicomTags.RetrieveAeTitle); // AE
ConvertAttributeToUN(dataSet, DicomTags.PatientsAge); // AS
ConvertAttributeToUN(dataSet, DicomTags.TimeRange); // FD
ConvertAttributeToUN(dataSet, DicomTags.RecommendedDisplayFrameRateInFloat); // FL
ConvertAttributeToUN(dataSet, DicomTags.Modality); // CS
ConvertAttributeToUN(dataSet, DicomTags.SeriesDate); // DA
ConvertAttributeToUN(dataSet, DicomTags.PatientsWeight); // DS
ConvertAttributeToUN(dataSet, DicomTags.AcquisitionDatetime); // DT
ConvertAttributeToUN(dataSet, DicomTags.EchoTrainLength); // IS
ConvertAttributeToUN(dataSet, DicomTags.Manufacturer); // LO
ConvertAttributeToUN(dataSet, DicomTags.ImageComments); // LT
ConvertAttributeToUN(dataSet, DicomTags.EncapsulatedDocument); // OB
ConvertAttributeToUN(dataSet, DicomTags.VectorGridData); // OF
ConvertAttributeToUN(dataSet, DicomTags.ReferringPhysiciansName); // PN
ConvertAttributeToUN(dataSet, DicomTags.AccessionNumber); // SH
ConvertAttributeToUN(dataSet, DicomTags.ReferencePixelX0); // SL
ConvertAttributeToUN(dataSet, DicomTags.VerticesOfThePolygonalExposureControlSensingRegion); // SS
ConvertAttributeToUN(dataSet, DicomTags.InstitutionAddress); // ST
ConvertAttributeToUN(dataSet, DicomTags.SeriesTime); // TM
ConvertAttributeToUN(dataSet, DicomTags.StudyInstanceUid); // UI
ConvertAttributeToUN(dataSet, DicomTags.DimensionIndexValues); // UL
ConvertAttributeToUN(dataSet, DicomTags.SamplesPerPixel); // US
ConvertAttributeToUN(dataSet, DicomTags.PixelDataProviderUrl); // UT
// Explicit Big
file.TransferSyntax = TransferSyntax.ExplicitVrBigEndian;
file.Save();
DicomFile newFile = new DicomFile(file.Filename);
newFile.Load(DicomReadOptions.UseDictionaryForExplicitUN);
List<DicomAttributeComparisonResult> results = new List<DicomAttributeComparisonResult>();
bool compare = originalFile.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
// Explicit Little
file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
file.Save();
newFile = new DicomFile(file.Filename);
newFile.Load(DicomReadOptions.UseDictionaryForExplicitUN);
results = new List<DicomAttributeComparisonResult>();
compare = originalFile.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
// Implicit Little
file.TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
file.Save();
newFile = new DicomFile(file.Filename);
newFile.Load(DicomReadOptions.UseDictionaryForExplicitUN);
results = new List<DicomAttributeComparisonResult>();
compare = originalFile.DataSet.Equals(newFile.DataSet, ref results);
Assert.IsTrue(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
}