本文整理汇总了C#中DicomUncompressedPixelData类的典型用法代码示例。如果您正苦于以下问题:C# DicomUncompressedPixelData类的具体用法?C# DicomUncompressedPixelData怎么用?C# DicomUncompressedPixelData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DicomUncompressedPixelData类属于命名空间,在下文中一共展示了DicomUncompressedPixelData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeSyntax
public void ChangeSyntax(TransferSyntax syntax)
{
try
{
if (!_dicomFile.TransferSyntax.Encapsulated)
{
// Check if Overlay is embedded in pixels
OverlayPlaneModuleIod overlayIod = new OverlayPlaneModuleIod(_dicomFile.DataSet);
for (int i = 0; i < 16; i++)
{
if (overlayIod.HasOverlayPlane(i))
{
OverlayPlane overlay = overlayIod[i];
if (overlay.OverlayData == null)
{
DicomUncompressedPixelData pd = new DicomUncompressedPixelData(_dicomFile);
overlay.ConvertEmbeddedOverlay(pd);
}
}
}
}
else if (syntax.Encapsulated)
{
// Must decompress first.
_dicomFile.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
}
_dicomFile.ChangeTransferSyntax(syntax);
}
catch (Exception e)
{
Platform.Log(LogLevel.Error, e, "Unexpected exception compressing/decompressing DICOM file");
}
}
示例2: DecodeFrame
public void DecodeFrame(int frame, DicomCompressedPixelData oldPixelData, DicomUncompressedPixelData newPixelData, DicomCodecParameters parameters)
{
using (var input = new MemoryStream(oldPixelData.GetFrameFragmentData(frame)))
using (var gzipStream = new GZipStream(input, CompressionMode.Decompress, false))
{
var data = new byte[oldPixelData.UncompressedFrameSize];
gzipStream.Read(data, 0, data.Length);
newPixelData.AppendFrame(data);
}
}
示例3: SetupMRWithOverlay
public void SetupMRWithOverlay(DicomAttributeCollection theSet)
{
SetupMR(theSet);
OverlayPlaneModuleIod overlayIod = new OverlayPlaneModuleIod(theSet);
DicomUncompressedPixelData pd = new DicomUncompressedPixelData(theSet);
OverlayPlane overlay = overlayIod[0];
// Embedded overlays are retired in dicom, just doing it for testing purposes
theSet[DicomTags.OverlayBitPosition].SetInt32(0, pd.HighBit + 1);
overlay.OverlayBitsAllocated = 1;
overlay.OverlayColumns = pd.ImageWidth;
overlay.OverlayRows = pd.ImageHeight;
overlay.OverlayOrigin = new Point(0, 0);
overlay.OverlayType = OverlayType.R;
}
示例4: DecodeFrame
public void DecodeFrame(int frame, DicomCompressedPixelData oldPixelData, DicomUncompressedPixelData newPixelData, DicomCodecParameters parameters)
{
if (oldPixelData.UncompressedFrameSize%2 == 1)
{
using (var stream = new MemoryStream(oldPixelData.GetFrameFragmentData(frame)))
{
var data = new byte[oldPixelData.UncompressedFrameSize];
stream.Read(data, 0, data.Length);
newPixelData.AppendFrame(data);
}
}
else
{
newPixelData.AppendFrame(oldPixelData.GetFrameFragmentData(frame));
}
}
示例5: Encode
public void Encode(DicomUncompressedPixelData oldPixelData, DicomCompressedPixelData newPixelData, DicomCodecParameters parameters)
{
for (var n = 0; n < oldPixelData.NumberOfFrames; ++n)
{
using (var output = new MemoryStream())
{
using (var gzipStream = new GZipStream(output, CompressionMode.Compress, true))
{
var data = oldPixelData.GetFrame(n);
gzipStream.Write(data, 0, data.Length);
}
// if the compressed stream is odd length, append an extra byte - gzip will know that it's padding during decompression
if (output.Length%2 == 1) output.WriteByte(0);
newPixelData.AddFrameFragment(output.ToArray());
}
}
}
示例6: 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);
}
}
示例7: Encode
public void Encode(DicomUncompressedPixelData oldPixelData, DicomCompressedPixelData newPixelData, DicomCodecParameters parameters)
{
if (oldPixelData.UncompressedFrameSize%2 == 1)
{
for (var n = 0; n < oldPixelData.NumberOfFrames; ++n)
{
using (var stream = new MemoryStream())
{
var data = oldPixelData.GetFrame(n);
stream.Write(data, 0, data.Length);
stream.WriteByte(0); // must pad fragments to even length
newPixelData.AddFrameFragment(stream.ToArray());
}
}
}
else
{
for (var n = 0; n < oldPixelData.NumberOfFrames; ++n)
{
newPixelData.AddFrameFragment(oldPixelData.GetFrame(n));
}
}
}
示例8: TestBasic_MessageInMemory_8Bits_OB
public void TestBasic_MessageInMemory_8Bits_OB()
{
var dcf = CreateDicomImage(rows : 20, columns : 30, numberOfFrames : 3, bitsAllocated16 : false, useOB : true);
var pd = new DicomUncompressedPixelData(dcf);
Assert.AreEqual(8, pd.BitsAllocated, "BitsAllocated");
Assert.AreEqual(8, pd.BitsStored, "BitsStored");
Assert.AreEqual(7, pd.HighBit, "HighBit");
Assert.AreEqual(20, pd.ImageHeight, "ImageHeight");
Assert.AreEqual(30, pd.ImageWidth, "ImageWidth");
Assert.AreEqual(3, pd.NumberOfFrames, "NumberOfFrames");
Assert.AreEqual("MONOCHROME2", pd.PhotometricInterpretation, "PhotometricInterpretation");
Assert.AreEqual(0, pd.PixelRepresentation, "PixelRepresentation");
Assert.AreEqual(1, pd.SamplesPerPixel, "SamplesPerPixel");
Assert.AreEqual(20*30, pd.UncompressedFrameSize, "UncompressedFrameSize");
for (var frame = 0; frame < 3; ++frame)
{
var fd = pd.GetFrame(frame);
Assert.AreEqual(pd.UncompressedFrameSize, fd.Length, "PixelData(frame={0}).Length", frame);
AssertBytesEqual((byte) (0x80 + frame), fd, "PixelData(frame={0})", frame);
}
}
示例9: TestAdvanced_FileOnDisk_16Bits_OW
public void TestAdvanced_FileOnDisk_16Bits_OW()
{
var filename = Path.GetTempFileName();
CreateDicomImage(rows : 20, columns : 30, numberOfFrames : 5).Save(filename);
var dcf = new DicomFile(filename);
dcf.Load(DicomReadOptions.StorePixelDataReferences);
try
{
var pd = new DicomUncompressedPixelData(dcf);
Assert.AreEqual(16, pd.BitsAllocated, "BitsAllocated");
Assert.AreEqual(16, pd.BitsStored, "BitsStored");
Assert.AreEqual(15, pd.HighBit, "HighBit");
Assert.AreEqual(20, pd.ImageHeight, "ImageHeight");
Assert.AreEqual(30, pd.ImageWidth, "ImageWidth");
Assert.AreEqual(5, pd.NumberOfFrames, "NumberOfFrames");
Assert.AreEqual("MONOCHROME2", pd.PhotometricInterpretation, "PhotometricInterpretation");
Assert.AreEqual(0, pd.PixelRepresentation, "PixelRepresentation");
Assert.AreEqual(1, pd.SamplesPerPixel, "SamplesPerPixel");
Assert.AreEqual(20*30*2, pd.UncompressedFrameSize, "UncompressedFrameSize");
var newFrameData = new byte[pd.UncompressedFrameSize];
for (var n = 0; n < newFrameData.Length; ++n)
newFrameData[n] = 0x7F;
pd.SetFrame(1, newFrameData);
pd.UpdateAttributeCollection(dcf.DataSet);
var pixelData = dcf.DataSet[DicomTags.PixelData].Values as byte[];
for (var frame = 0; frame < 5; ++frame)
{
var fd = pd.GetFrame(frame);
var expectedValue = frame == 1 ? (byte) 0x7F : (byte) (0x80 + frame);
Assert.AreEqual(pd.UncompressedFrameSize, fd.Length, "PixelData(frame={0}).Length", frame);
AssertBytesEqual(expectedValue, fd, "PixelData(frame={0})", frame);
AssertBytesEqual(expectedValue, pixelData, frame*pd.UncompressedFrameSize, pd.UncompressedFrameSize, "AttributeValues(frame={0})", frame);
}
}
finally
{
File.Delete(filename);
}
}
示例10: DecodeFrame
public void DecodeFrame(int frame, DicomCompressedPixelData oldPixelData,
DicomUncompressedPixelData newPixelData, DicomCodecParameters parameters)
{
DicomRleCodecParameters rleParams = parameters as DicomRleCodecParameters;
if (rleParams == null)
throw new DicomCodecException("Unexpected RLE Codec parameters");
int pixelCount = oldPixelData.ImageWidth * oldPixelData.ImageHeight;
int numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;
int segmentLength = (pixelCount & 1) == 1 ? pixelCount + 1 : pixelCount;
byte[] segment = new byte[segmentLength];
byte[] frameData = new byte[oldPixelData.UncompressedFrameSize];
IList<DicomFragment> rleData = oldPixelData.GetFrameFragments(frame);
RLEDecoder decoder = new RLEDecoder(rleData);
if (decoder.NumberOfSegments != numberOfSegments)
throw new DicomCodecException("Unexpected number of RLE segments!");
for (int s = 0; s < numberOfSegments; s++)
{
decoder.DecodeSegment(s, segment);
int sample = s / oldPixelData.BytesAllocated;
int sabyte = s % oldPixelData.BytesAllocated;
int pos;
int offset;
if (newPixelData.PlanarConfiguration == 0)
{
pos = sample * oldPixelData.BytesAllocated;
offset = oldPixelData.SamplesPerPixel * oldPixelData.BytesAllocated;
}
else
{
pos = sample * oldPixelData.BytesAllocated * pixelCount;
offset = oldPixelData.BytesAllocated;
}
if (rleParams.ReverseByteOrder)
pos += sabyte;
else
pos += oldPixelData.BytesAllocated - sabyte - 1;
for (int p = 0; p < pixelCount; p++)
{
frameData[pos] = segment[p];
pos += offset;
}
}
newPixelData.AppendFrame(frameData);
}
示例11: TestBasic_FileOnDisk_8Bits_OB
public void TestBasic_FileOnDisk_8Bits_OB()
{
var filename = Path.GetTempFileName();
CreateDicomImage(rows : 20, columns : 30, numberOfFrames : 3, bitsAllocated16 : false, useOB : true).Save(filename);
var dcf = new DicomFile(filename);
dcf.Load(DicomReadOptions.StorePixelDataReferences);
try
{
var pd = new DicomUncompressedPixelData(dcf);
Assert.AreEqual(8, pd.BitsAllocated, "BitsAllocated");
Assert.AreEqual(8, pd.BitsStored, "BitsStored");
Assert.AreEqual(7, pd.HighBit, "HighBit");
Assert.AreEqual(20, pd.ImageHeight, "ImageHeight");
Assert.AreEqual(30, pd.ImageWidth, "ImageWidth");
Assert.AreEqual(3, pd.NumberOfFrames, "NumberOfFrames");
Assert.AreEqual("MONOCHROME2", pd.PhotometricInterpretation, "PhotometricInterpretation");
Assert.AreEqual(0, pd.PixelRepresentation, "PixelRepresentation");
Assert.AreEqual(1, pd.SamplesPerPixel, "SamplesPerPixel");
Assert.AreEqual(20*30, pd.UncompressedFrameSize, "UncompressedFrameSize");
for (var frame = 0; frame < 3; ++frame)
{
var fd = pd.GetFrame(frame);
Assert.AreEqual(pd.UncompressedFrameSize, fd.Length, "PixelData(frame={0}).Length", frame);
AssertBytesEqual((byte) (0x80 + frame), fd, "PixelData(frame={0})", frame);
}
}
finally
{
File.Delete(filename);
}
}
示例12: TestBasic_FileOnDisk_16Bits_BigEndian_OddFrameLength
public void TestBasic_FileOnDisk_16Bits_BigEndian_OddFrameLength()
{
var filename = Path.GetTempFileName();
CreateDicomImage(rows : 19, columns : 29, numberOfFrames : 5, endian : Endian.Big).Save(filename);
var dcf = new DicomFile(filename);
dcf.Load(DicomReadOptions.StorePixelDataReferences);
try
{
var pd = new DicomUncompressedPixelData(dcf);
Assert.AreEqual(16, pd.BitsAllocated, "BitsAllocated");
Assert.AreEqual(16, pd.BitsStored, "BitsStored");
Assert.AreEqual(15, pd.HighBit, "HighBit");
Assert.AreEqual(19, pd.ImageHeight, "ImageHeight");
Assert.AreEqual(29, pd.ImageWidth, "ImageWidth");
Assert.AreEqual(5, pd.NumberOfFrames, "NumberOfFrames");
Assert.AreEqual("MONOCHROME2", pd.PhotometricInterpretation, "PhotometricInterpretation");
Assert.AreEqual(0, pd.PixelRepresentation, "PixelRepresentation");
Assert.AreEqual(1, pd.SamplesPerPixel, "SamplesPerPixel");
Assert.AreEqual(19*29*2, pd.UncompressedFrameSize, "UncompressedFrameSize");
for (var frame = 0; frame < 5; ++frame)
{
var fd = pd.GetFrame(frame);
Assert.AreEqual(pd.UncompressedFrameSize, fd.Length, "PixelData(frame={0}).Length", frame);
AssertBytesEqual((byte) (0x80 + frame), fd, "PixelData(frame={0})", frame);
}
}
finally
{
File.Delete(filename);
}
}
示例13: CreateColorPixelData
protected static void CreateColorPixelData(DicomUncompressedPixelData pd)
{
int rows = pd.ImageHeight;
int cols = pd.ImageWidth;
int minValue = pd.IsSigned ? -(1 << (pd.BitsStored - 1)) : 0;
int maxValue = (1 << pd.BitsStored) + minValue - 1;
const byte noOpByteMask = 0xFF;
var byteMask = (byte)(noOpByteMask >> (pd.BitsAllocated - pd.BitsStored));
// Create a small block of pixels in the test pattern in an integer,
// then copy/tile into the full size frame data
int smallRows = (rows * 3) / 8;
int smallColumns = rows / 4;
int stripSize = rows / 16;
int[] smallPixels = new int[smallRows * smallColumns * 3];
float slope = (float)(maxValue - minValue) / smallColumns;
int pixelOffset = 0;
for (int i = 0; i < smallRows; i++)
{
if (i < stripSize)
{
for (int j = 0; j < smallColumns; j++)
{
smallPixels[pixelOffset] = (int)((j * slope) + minValue);
pixelOffset++;
smallPixels[pixelOffset] = 0;
pixelOffset++;
smallPixels[pixelOffset] = 0;
pixelOffset++;
}
}
else if (i > (smallRows - stripSize))
{
for (int j = 0; j < smallColumns; j++)
{
smallPixels[pixelOffset] = 0;
pixelOffset++;
smallPixels[pixelOffset] = (int)(maxValue - (j * slope));
pixelOffset++;
smallPixels[pixelOffset] = 0;
pixelOffset++;
}
}
else
{
int pixel = minValue + (int)((i - stripSize) * slope);
if (pixel < minValue) pixel = minValue + 1;
if (pixel > maxValue) pixel = maxValue - 1;
int start = (smallColumns / 2) - (i - stripSize) / 2;
int end = (smallColumns / 2) + (i - stripSize) / 2;
for (int j = 0; j < smallColumns; j++)
{
smallPixels[pixelOffset] = 0;
pixelOffset++;
smallPixels[pixelOffset] = 0;
pixelOffset++;
if (j < start)
smallPixels[pixelOffset] = minValue;
else if (j > end)
smallPixels[pixelOffset] = maxValue;
else
smallPixels[pixelOffset] = pixel;
pixelOffset++;
}
}
}
// Now create the actual frame
for (int frame = 0; frame < pd.NumberOfFrames; frame++)
{
// Odd length frames are automatically dealt with by DicomUncompressedPixelData
byte[] frameData = new byte[pd.UncompressedFrameSize];
pixelOffset = 0;
for (int i = 0; i < rows; i++)
{
int smallOffset = (i%smallRows)*smallColumns*3;
for (int j = 0; j < cols*3; j++)
{
frameData[pixelOffset] = (byte) smallPixels[smallOffset + j%(smallColumns*3)];
frameData[pixelOffset] &= byteMask;
pixelOffset++;
}
}
pd.AppendFrame(frameData);
}
}
示例14: Convert8BitSigned
public static int[] Convert8BitSigned(byte[] byteInputData, int pixels, DicomUncompressedPixelData pd)
{
int shiftBits = 32 - pd.BitsStored;
bool bPixelRescale = !string.IsNullOrEmpty(pd.RescaleSlope) &&
!string.IsNullOrEmpty(pd.RescaleIntercept)
&&
(pd.DecimalRescaleSlope != 1m ||
pd.DecimalRescaleIntercept != 0m);
byte pixelMask = 0x00;
for (int x = 0; x < pd.BitsStored; x++)
pixelMask = (byte)((pixelMask << 1) | 0x0001);
int[] intPixels = new int[pixels];
for (int pixelCount = 0; pixelCount < byteInputData.Length; pixelCount++)
{
intPixels[pixelCount] = byteInputData[pixelCount] & pixelMask;
intPixels[pixelCount] = (((intPixels[pixelCount] << shiftBits)) >> shiftBits);
if (bPixelRescale)
intPixels[pixelCount] = intPixels[pixelCount] * (int)pd.DecimalRescaleSlope +
(int)pd.DecimalRescaleIntercept;
}
return intPixels;
}
示例15: CreatePixelData
protected static void CreatePixelData(DicomAttributeCollection dataSet)
{
dataSet[DicomTags.PixelData] = null;
var pd = new DicomUncompressedPixelData(dataSet);
CreatePixelData(pd);
pd.UpdateAttributeCollection(dataSet);
}