本文整理汇总了C#中DicomFile.ChangeTransferSyntax方法的典型用法代码示例。如果您正苦于以下问题:C# DicomFile.ChangeTransferSyntax方法的具体用法?C# DicomFile.ChangeTransferSyntax怎么用?C# DicomFile.ChangeTransferSyntax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DicomFile
的用法示例。
在下文中一共展示了DicomFile.ChangeTransferSyntax方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: SetupEncapsulatedImageWithIconSequence
private void SetupEncapsulatedImageWithIconSequence(DicomFile file, bool encapsulateIconPixelData)
{
var codec = new NullDicomCodec();
DicomAttributeCollection dataSet = file.DataSet;
SetupSecondaryCapture(dataSet);
SetupMetaInfo(file);
file.TransferSyntax = TransferSyntax.ImplicitVrLittleEndian;
file.ChangeTransferSyntax(codec.CodecTransferSyntax);
// explicitly create the icon sequence as either encapsulated or native, so that we are not depending on correct behaviour elsewhere...
CreateIconImageSequence(dataSet);
if (encapsulateIconPixelData)
{
var dataset = ((DicomAttributeSQ) dataSet[DicomTags.IconImageSequence])[0];
var pixelData = dataset[DicomTags.PixelData];
var pd = new DicomUncompressedPixelData(dataset);
using (var pixelStream = ((DicomAttributeBinary) pixelData).AsStream())
{
//Before compression, make the pixel data more "typical", so it's harder to mess up the codecs.
//NOTE: Could combine mask and align into one method so we're not iterating twice, but I prefer having the methods separate.
if (DicomUncompressedPixelData.RightAlign(pixelStream, pd.BitsAllocated, pd.BitsStored, pd.HighBit))
{
var newHighBit = (ushort) (pd.HighBit - pd.LowBit);
pd.HighBit = newHighBit; //correct high bit after right-aligning.
dataset[DicomTags.HighBit].SetUInt16(0, newHighBit);
}
DicomUncompressedPixelData.ZeroUnusedBits(pixelStream, pd.BitsAllocated, pd.BitsStored, pd.HighBit);
}
// Set transfer syntax before compression, the codecs need it.
var fragments = new DicomCompressedPixelData(pd) {TransferSyntax = codec.CodecTransferSyntax};
codec.Encode(pd, fragments, null);
fragments.UpdateAttributeCollection(dataset);
}
}
示例3: ExpectedFailureTest
public static void ExpectedFailureTest(TransferSyntax syntax, DicomFile theFile)
{
try
{
theFile.ChangeTransferSyntax(syntax);
}
catch (DicomCodecUnsupportedSopException)
{
return;
}
Assert.IsTrue(false, "Unexpected successfull compression of object.");
}
示例4: 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);
}
示例5: 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));
}
示例6: LosslessImageTestWithBitsAllocatedConversion
public static void LosslessImageTestWithBitsAllocatedConversion(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);
string failureDescription;
var newPd = DicomPixelData.CreateFrom(newFile);
var oldPd = DicomPixelData.CreateFrom(saveCopy);
bool result = Compare(newPd, oldPd, out failureDescription);
Assert.IsFalse(result, failureDescription);
Assert.IsFalse(newFile.DataSet.Equals(saveCopy.DataSet));
DicomAttributeCollection newDataSet = newFile.DataSet.Copy(true, true, true);
DicomAttributeCollection oldDataSet = theFile.DataSet.Copy(true, true, true);
oldDataSet.RemoveAttribute(DicomTags.BitsAllocated);
newDataSet.RemoveAttribute(DicomTags.BitsAllocated);
oldDataSet.RemoveAttribute(DicomTags.PixelData);
newDataSet.RemoveAttribute(DicomTags.PixelData);
var results = new List<DicomAttributeComparisonResult>();
bool check = oldDataSet.Equals(newDataSet, ref results);
Assert.IsTrue(check, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
for (int i = 0; i < oldPd.NumberOfFrames; i++)
{
var frame = oldPd.GetFrame(i);
var convertedFrame = DicomUncompressedPixelData.ToggleBitDepth(frame, frame.Length,
oldPd.UncompressedFrameSize,
oldPd.BitsStored, oldPd.BitsAllocated);
var newFrame = newPd.GetFrame(i);
int pixelsVarying = 0;
decimal totalVariation = 0.0m;
for (int j = 0; j < convertedFrame.Length; j++)
if (convertedFrame[j] != newFrame[j])
{
pixelsVarying++;
totalVariation += Math.Abs(convertedFrame[i] - newFrame[i]);
}
if (pixelsVarying > 0)
{
Assert.Fail(String.Format(
"Tag (7fe0,0010) Pixel Data: {0} of {1} pixels varying, average difference: {2}",
pixelsVarying, convertedFrame.Length, totalVariation/pixelsVarying));
}
}
}
示例7: 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);
string failureDescription;
bool result = Compare(DicomPixelData.CreateFrom(newFile),
DicomPixelData.CreateFrom(saveCopy), out failureDescription);
Assert.IsTrue(result, failureDescription);
Assert.IsFalse(newFile.DataSet.Equals(saveCopy.DataSet));
}
示例8: PartialFrameTest
public void PartialFrameTest()
{
DicomFile file = new DicomFile("RlePartialFrameTest.dcm");
SetupMultiframeXA(file.DataSet, 511, 511, 7);
file.ChangeTransferSyntax(TransferSyntax.RleLossless);
file.Save();
DicomFile newFile = new DicomFile(file.Filename);
newFile.Load(DicomReadOptions.StorePixelDataReferences);
DicomPixelData pd;
if (!newFile.TransferSyntax.Encapsulated)
pd = new DicomUncompressedPixelData(newFile);
else if (newFile.TransferSyntax.Equals(TransferSyntax.RleLossless))
pd = new DicomCompressedPixelData(newFile);
else
throw new DicomCodecException("Unsupported transfer syntax: " + newFile.TransferSyntax);
for (int i=0; i< pd.NumberOfFrames; i++)
{
pd.GetFrame(i);
}
}
示例9: RleTest
public void RleTest(DicomFile file)
{
// Make a copy of the source format
DicomAttributeCollection originalDataSet = file.DataSet.Copy();
DicomAttributeCollection originalMetaInfo = file.MetaInfo.Copy();
DicomFile originalFile = new DicomFile("", originalMetaInfo, originalDataSet);
file.ChangeTransferSyntax(TransferSyntax.RleLossless);
file.Save();
DicomFile newFile = new DicomFile(file.Filename);
newFile.Load();
newFile.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
newFile.Filename = "Output" + file.Filename;
newFile.Save();
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);
}
示例10: RleOverlayTest
public void RleOverlayTest()
{
DicomFile file = new DicomFile("RleCodecOverlayTest.dcm");
SetupMRWithOverlay(file.DataSet);
SetupMetaInfo(file);
// Save a copy
file.Save();
// Load the file into new DicomFile object
DicomFile newFile = new DicomFile(file.Filename);
newFile.Load();
OverlayPlaneModuleIod overlayIod = new OverlayPlaneModuleIod(newFile.DataSet);
OverlayPlane overlay = overlayIod[0];
// SHould be no OverlayData tag
Assert.IsNull(overlay.OverlayData, "Overlay should be in pixel data");
// Overlay should be extracted out of pixel data here
newFile.ChangeTransferSyntax(TransferSyntax.RleLossless);
Assert.IsNotNull(overlay.OverlayData,"Overlay Data is not null");
newFile.Save();
// Load a new copy
newFile = new DicomFile(file.Filename);
newFile.Load();
newFile.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
newFile.Filename = "Output" + file.Filename;
newFile.Save();
List<DicomAttributeComparisonResult> results = new List<DicomAttributeComparisonResult>();
bool compare = file.DataSet.Equals(newFile.DataSet, ref results);
// Shouldn't be the same, OverlayData tag should have been added
Assert.IsFalse(compare, results.Count > 0 ? CollectionUtils.FirstElement(results).Details : string.Empty);
}
示例11: 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);
}
示例12: RleTest
public void RleTest(DicomFile file)
{
// Make a copy of the source format
DicomAttributeCollection originalDataSet = file.DataSet.Copy();
DicomAttributeCollection originalMetaInfo = file.MetaInfo.Copy();
DicomFile originalFile = new DicomFile("", originalMetaInfo, originalDataSet);
file.ChangeTransferSyntax(TransferSyntax.RleLossless);
file.Save();
DicomFile newFile = new DicomFile(file.Filename);
newFile.Load();
newFile.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
newFile.Filename = "Output" + file.Filename;
newFile.Save();
Assert.AreEqual(originalFile.DataSet.Equals(newFile.DataSet), true);
}