Пример #1
0
 public static DicomFile ChangeTransferSyntax(
     this DicomFile file,
     DicomTransferSyntax syntax,
     DicomCodecParams parameters = null)
 {
     return(Clone(file, syntax, parameters));
 }
Пример #2
0
        private static DicomDataset Decode(
            DicomDataset oldDataset,
            DicomTransferSyntax outSyntax,
            IDicomCodec codec,
            DicomCodecParams parameters)
        {
            if (codec == null)
            {
                throw new DicomCodecException("Decoding dataset with transfer syntax: {0} is not supported. See here to get help resolving the reason: https://github.com/fo-dicom/fo-dicom/wiki/Native-codecs-on-.NET",
                                              oldDataset.InternalTransferSyntax);
            }

            var oldPixelData = DicomPixelData.Create(oldDataset);

            var newDataset = oldDataset.Clone();

            newDataset.InternalTransferSyntax = outSyntax;
            var newPixelData = DicomPixelData.Create(newDataset, true);

            codec.Decode(oldPixelData, newPixelData, parameters);

            ProcessOverlays(oldDataset, newDataset);

            newDataset.RecalculateGroupLengths(false);

            return(newDataset);
        }
Пример #3
0
        private static DicomDataset Decode(
            DicomDataset oldDataset,
            DicomTransferSyntax outSyntax,
            IDicomCodec codec,
            DicomCodecParams parameters)
        {
            if (codec == null)
            {
                throw new DicomCodecException("Decoding dataset with transfer syntax: {0} is not supported.",
                                              oldDataset.InternalTransferSyntax);
            }

            var oldPixelData = DicomPixelData.Create(oldDataset);

            var newDataset = oldDataset.Clone();

            newDataset.InternalTransferSyntax = outSyntax;
            var newPixelData = DicomPixelData.Create(newDataset, true);

            codec.Decode(oldPixelData, newPixelData, parameters);

            ProcessOverlays(oldDataset, newDataset);

            newDataset.RecalculateGroupLengths(false);

            return(newDataset);
        }
Пример #4
0
        public override void Encode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            if (oldPixelData.NumberOfFrames == 0) return;

            // IJG eats the extra padding bits. Is there a better way to test for this?
            if (oldPixelData.BitsAllocated == 16 && oldPixelData.BitsStored <= 8)
            {
                // check for embedded overlays?
                newPixelData.BitsAllocated = 8;
            }

            var jparams = parameters as DicomJpegParams ?? GetDefaultParameters() as DicomJpegParams;

            var codec = GetCodec(oldPixelData.BitsStored, jparams);

            var oldNativeData = oldPixelData.ToNativePixelData();
            var newNativeData = newPixelData.ToNativePixelData();
            var jNativeParams = jparams.ToNativeJpegParameters();
            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                codec.Encode(oldNativeData, newNativeData, jNativeParams, frame);
            }
        }
Пример #5
0
        public override void Encode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            if (oldPixelData.NumberOfFrames == 0)
            {
                return;
            }

            // IJG eats the extra padding bits. Is there a better way to test for this?
            if (oldPixelData.BitsAllocated == 16 && oldPixelData.BitsStored <= 8)
            {
                // check for embedded overlays?
                newPixelData.BitsAllocated = 8;
            }

            var jparams = parameters as DicomJpegParams ?? GetDefaultParameters() as DicomJpegParams;

            var codec = GetCodec(oldPixelData.BitsStored, jparams);

            var oldNativeData = oldPixelData.ToNativePixelData();
            var newNativeData = newPixelData.ToNativePixelData();
            var jNativeParams = jparams.ToNativeJpegParameters();

            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                codec.Encode(oldNativeData, newNativeData, jNativeParams, frame);
            }
        }
Пример #6
0
 public static DicomDataset ChangeTransferSyntax(
     this DicomDataset dataset,
     DicomTransferSyntax syntax,
     DicomCodecParams parameters = null)
 {
     return(Clone(dataset, syntax, parameters));
 }
Пример #7
0
        public override void Encode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            var pixelCount = oldPixelData.Width * oldPixelData.Height;
            var numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;

            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                var frameData = oldPixelData.GetFrame(frame);
                var frameArray = frameData.Data;

                using (var encoder = new RLEEncoder())
                {
                    for (var s = 0; s < numberOfSegments; s++)
                    {
                        encoder.NextSegment();

                        var sample = s / oldPixelData.BytesAllocated;
                        var sabyte = s % oldPixelData.BytesAllocated;

                        int pos;
                        int offset;

                        if (newPixelData.PlanarConfiguration == PlanarConfiguration.Interleaved)
                        {
                            pos = sample * oldPixelData.BytesAllocated;
                            offset = numberOfSegments;
                        }
                        else
                        {
                            pos = sample * oldPixelData.BytesAllocated * pixelCount;
                            offset = oldPixelData.BytesAllocated;
                        }

                        pos += oldPixelData.BytesAllocated - sabyte - 1;

                        for (var p = 0; p < pixelCount; p++)
                        {
                            if (pos >= frameArray.Length)
                            {
                                throw new InvalidOperationException("Read position is past end of frame buffer");
                            }
                            encoder.Encode(frameArray[pos]);
                            pos += offset;
                        }
                        encoder.Flush();
                    }

                    encoder.MakeEvenLength();

                    var data = encoder.GetBuffer();
                    newPixelData.AddFrame(data);
                }
            }
        }
Пример #8
0
        public override void Encode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            var pixelCount       = oldPixelData.Width * oldPixelData.Height;
            var numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;

            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                var frameData  = oldPixelData.GetFrame(frame);
                var frameArray = frameData.Data;

                using (var encoder = new RLEEncoder())
                {
                    for (var s = 0; s < numberOfSegments; s++)
                    {
                        encoder.NextSegment();

                        var sample = s / oldPixelData.BytesAllocated;
                        var sabyte = s % oldPixelData.BytesAllocated;

                        int pos;
                        int offset;

                        if (newPixelData.PlanarConfiguration == PlanarConfiguration.Interleaved)
                        {
                            pos    = sample * oldPixelData.BytesAllocated;
                            offset = numberOfSegments;
                        }
                        else
                        {
                            pos    = sample * oldPixelData.BytesAllocated * pixelCount;
                            offset = oldPixelData.BytesAllocated;
                        }

                        pos += oldPixelData.BytesAllocated - sabyte - 1;

                        for (var p = 0; p < pixelCount; p++)
                        {
                            if (pos >= frameArray.Length)
                            {
                                throw new InvalidOperationException("Read position is past end of frame buffer");
                            }
                            encoder.Encode(frameArray[pos]);
                            pos += offset;
                        }
                        encoder.Flush();
                    }

                    encoder.MakeEvenLength();

                    var data = encoder.GetBuffer();
                    newPixelData.AddFrame(data);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Create a copy of the specified DICOM file with requested transfer syntax.
        /// </summary>
        /// <param name="file">DICOM file to copy.</param>
        /// <param name="syntax">Requested transfer syntax for the created DICOM file.</param>
        /// <param name="parameters">Codec parameters.</param>
        /// <returns>DICOM file with modified transfer syntax.</returns>
        public static DicomFile Clone(
            this DicomFile file,
            DicomTransferSyntax syntax,
            DicomCodecParams parameters = null)
        {
            var transcoder = new DicomTranscoder(file.FileMetaInfo.TransferSyntax, syntax, null, parameters);

            return(transcoder.Transcode(file));
        }
Пример #10
0
        /// <summary>
        /// Create a copy of the specified DICOM dataset with requested transfer syntax.
        /// </summary>
        /// <param name="dataset">DICOM dataset to copy.</param>
        /// <param name="syntax">Requested transfer syntax for the created DICOM dataset.</param>
        /// <param name="parameters">Codec parameters.</param>
        /// <returns>DICOM dataset with modified transfer syntax.</returns>
        public static DicomDataset Clone(
            this DicomDataset dataset,
            DicomTransferSyntax syntax,
            DicomCodecParams parameters = null)
        {
            var transcoder = new DicomTranscoder(dataset.InternalTransferSyntax, syntax, null, parameters);

            return(transcoder.Transcode(dataset));
        }
Пример #11
0
        public override void Decode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            if (oldPixelData.NumberOfFrames == 0)
            {
                return;
            }

            // IJG eats the extra padding bits. Is there a better way to test for this?
            if (newPixelData.BitsAllocated == 16 && newPixelData.BitsStored <= 8)
            {
                // check for embedded overlays here or below?
                newPixelData.BitsAllocated = 8;
            }

            var jparams = parameters as DicomJpegParams ?? GetDefaultParameters() as DicomJpegParams;

            var oldNativeData = oldPixelData.ToNativePixelData();
            int precision;

            try
            {
                try
                {
                    precision = JpegHelper.ScanJpegForBitDepth(oldPixelData);
                }
                catch
                {
                    // if the internal scanner chokes on an image, try again using ijg
                    precision = new Jpeg12Codec(JpegMode.Baseline, 0, 0).ScanHeaderForPrecision(oldNativeData);
                }
            }
            catch
            {
                // the old scanner choked on several valid images...
                // assume the correct encoder was used and let libijg handle the rest
                precision = oldPixelData.BitsStored;
            }

            if (newPixelData.BitsStored <= 8 && precision > 8)
            {
                newPixelData.BitsAllocated = 16;                                                // embedded overlay?
            }
            var codec = GetCodec(precision, jparams);

            var newNativeData = newPixelData.ToNativePixelData();
            var jNativeParams = jparams.ToNativeJpegParameters();

            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                codec.Decode(oldNativeData, newNativeData, jNativeParams, frame);
            }
        }
Пример #12
0
 /// <summary>
 /// Initializes an instance of <see cref="DicomTranscoder"/>.
 /// </summary>
 /// <param name="inputSyntax">Input transfer syntax.</param>
 /// <param name="outputSyntax">Output transfer syntax.</param>
 /// <param name="inputCodecParams">Input codec parameters.</param>
 /// <param name="outputCodecParams">Output codec parameters.</param>
 public DicomTranscoder(
     DicomTransferSyntax inputSyntax,
     DicomTransferSyntax outputSyntax,
     DicomCodecParams inputCodecParams  = null,
     DicomCodecParams outputCodecParams = null)
 {
     InputSyntax       = inputSyntax;
     OutputSyntax      = outputSyntax;
     InputCodecParams  = inputCodecParams ?? DefaultInputCodecParams(inputSyntax);
     OutputCodecParams = outputCodecParams;
 }
Пример #13
0
 /// <summary>
 /// Initializes an instance of <see cref="DicomTranscoder"/>.
 /// </summary>
 /// <param name="inputSyntax">Input transfer syntax.</param>
 /// <param name="outputSyntax">Output transfer syntax.</param>
 /// <param name="inputCodecParams">Input codec parameters.</param>
 /// <param name="outputCodecParams">Output codec parameters.</param>
 public DicomTranscoder(
     DicomTransferSyntax inputSyntax,
     DicomTransferSyntax outputSyntax,
     DicomCodecParams inputCodecParams = null,
     DicomCodecParams outputCodecParams = null)
 {
     InputSyntax = inputSyntax;
     OutputSyntax = outputSyntax;
     InputCodecParams = inputCodecParams;
     OutputCodecParams = outputCodecParams;
 }
Пример #14
0
        public override void Decode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                var rleData = oldPixelData.GetFrame(frame);

                // Create new frame data of even length
                var frameSize = newPixelData.UncompressedFrameSize;
                if ((frameSize & 1) == 1)
                {
                    ++frameSize;
                }

                var frameData = new MemoryByteBuffer(new byte[frameSize]);

                var pixelCount = oldPixelData.Width * oldPixelData.Height;
                var numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;

                var decoder = new RLEDecoder(rleData);

                if (decoder.NumberOfSegments != numberOfSegments)
                {
                    throw new InvalidOperationException("Unexpected number of RLE segments!");
                }

                for (var s = 0; s < numberOfSegments; s++)
                {
                    var sample = s / newPixelData.BytesAllocated;
                    var sabyte = s % newPixelData.BytesAllocated;

                    int pos, offset;

                    if (newPixelData.PlanarConfiguration == PlanarConfiguration.Interleaved)
                    {
                        pos = sample * newPixelData.BytesAllocated;
                        offset = newPixelData.SamplesPerPixel * newPixelData.BytesAllocated;
                    }
                    else
                    {
                        pos = sample * newPixelData.BytesAllocated * pixelCount;
                        offset = newPixelData.BytesAllocated;
                    }

                    pos += newPixelData.BytesAllocated - sabyte - 1;
                    decoder.DecodeSegment(s, frameData, pos, offset);
                }

                newPixelData.AddFrame(frameData);
            }
        }
Пример #15
0
        public override void Decode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                var rleData = oldPixelData.GetFrame(frame);

                // Create new frame data of even length
                var frameSize = newPixelData.UncompressedFrameSize;
                if ((frameSize & 1) == 1)
                {
                    ++frameSize;
                }

                var frameData = new MemoryByteBuffer(new byte[frameSize]);

                var pixelCount       = oldPixelData.Width * oldPixelData.Height;
                var numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;

                var decoder = new RLEDecoder(rleData);

                if (decoder.NumberOfSegments != numberOfSegments)
                {
                    throw new InvalidOperationException("Unexpected number of RLE segments!");
                }

                for (var s = 0; s < numberOfSegments; s++)
                {
                    var sample = s / newPixelData.BytesAllocated;
                    var sabyte = s % newPixelData.BytesAllocated;

                    int pos, offset;

                    if (newPixelData.PlanarConfiguration == PlanarConfiguration.Interleaved)
                    {
                        pos    = sample * newPixelData.BytesAllocated;
                        offset = newPixelData.SamplesPerPixel * newPixelData.BytesAllocated;
                    }
                    else
                    {
                        pos    = sample * newPixelData.BytesAllocated * pixelCount;
                        offset = newPixelData.BytesAllocated;
                    }

                    pos += newPixelData.BytesAllocated - sabyte - 1;
                    decoder.DecodeSegment(s, frameData, pos, offset);
                }

                newPixelData.AddFrame(frameData);
            }
        }
Пример #16
0
        /// <summary>
        /// Initializes an instance of <see cref="DicomTranscoder"/>.
        /// </summary>
        /// <param name="inputSyntax">Input transfer syntax.</param>
        /// <param name="outputSyntax">Output transfer syntax.</param>
        /// <param name="inputCodecParams">Input codec parameters.</param>
        /// <param name="outputCodecParams">Output codec parameters.</param>
        public DicomTranscoder(
            DicomTransferSyntax inputSyntax,
            DicomTransferSyntax outputSyntax,
            DicomCodecParams inputCodecParams  = null,
            DicomCodecParams outputCodecParams = null)
        {
            InputSyntax       = inputSyntax;
            OutputSyntax      = outputSyntax;
            InputCodecParams  = inputCodecParams ?? DefaultInputCodecParams(inputSyntax);
            OutputCodecParams = outputCodecParams;

            _inputCodec  = new Lazy <IDicomCodec>(() => InitializeCodec(InputSyntax));
            _outputCodec = new Lazy <IDicomCodec>(() => InitializeCodec(OutputSyntax));
        }
Пример #17
0
        public override void Decode(
            DicomPixelData oldPixelData,
            DicomPixelData newPixelData,
            DicomCodecParams parameters)
        {
            if (oldPixelData.NumberOfFrames == 0) return;

            // IJG eats the extra padding bits. Is there a better way to test for this?
            if (newPixelData.BitsAllocated == 16 && newPixelData.BitsStored <= 8)
            {
                // check for embedded overlays here or below?
                newPixelData.BitsAllocated = 8;
            }

            var jparams = parameters as DicomJpegParams ?? GetDefaultParameters() as DicomJpegParams;

            var oldNativeData = oldPixelData.ToNativePixelData();
            int precision;
            try
            {
                try
                {
                    precision = JpegHelper.ScanJpegForBitDepth(oldPixelData);
                }
                catch
                {
                    // if the internal scanner chokes on an image, try again using ijg
                    precision = new Jpeg12Codec(JpegMode.Baseline, 0, 0).ScanHeaderForPrecision(oldNativeData);
                }
            }
            catch
            {
                // the old scanner choked on several valid images...
                // assume the correct encoder was used and let libijg handle the rest
                precision = oldPixelData.BitsStored;
            }

            if (newPixelData.BitsStored <= 8 && precision > 8) newPixelData.BitsAllocated = 16; // embedded overlay?

            var codec = GetCodec(precision, jparams);

            var newNativeData = newPixelData.ToNativePixelData();
            var jNativeParams = jparams.ToNativeJpegParameters();
            for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++)
            {
                codec.Decode(oldNativeData, newNativeData, jNativeParams, frame);
            }
        }
Пример #18
0
        private static DicomDataset Encode(
            DicomDataset oldDataset,
            DicomTransferSyntax outSyntax,
            IDicomCodec codec,
            DicomCodecParams parameters)
        {
            if (codec == null)
            {
                throw new DicomCodecException("Encoding dataset to transfer syntax: {0} is not supported.", outSyntax);
            }

            var oldPixelData = DicomPixelData.Create(oldDataset);

            var newDataset = oldDataset.Clone();

            newDataset.InternalTransferSyntax = outSyntax;
            var newPixelData = DicomPixelData.Create(newDataset, true);

            codec.Encode(oldPixelData, newPixelData, parameters);

            if (outSyntax.IsLossy && newPixelData.NumberOfFrames > 0)
            {
                newDataset.AddOrUpdate(new DicomCodeString(DicomTag.LossyImageCompression, "01"));

                var methods = new List <string>();
                if (newDataset.Contains(DicomTag.LossyImageCompressionMethod))
                {
                    methods.AddRange(newDataset.Get <string[]>(DicomTag.LossyImageCompressionMethod));
                }
                methods.Add(outSyntax.LossyCompressionMethod);
                newDataset.AddOrUpdate(new DicomCodeString(DicomTag.LossyImageCompressionMethod, methods.ToArray()));

                double oldSize = oldPixelData.GetFrame(0).Size;
                double newSize = newPixelData.GetFrame(0).Size;
                var    ratio   = string.Format("{0:0.000}", oldSize / newSize);
                newDataset.AddOrUpdate(new DicomDecimalString(DicomTag.LossyImageCompressionRatio, ratio));
            }

            ProcessOverlays(oldDataset, newDataset);

            newDataset.RecalculateGroupLengths(false);

            return(newDataset);
        }
Пример #19
0
        private static DicomDataset Decode(
            DicomDataset oldDataset,
            DicomTransferSyntax outSyntax,
            IDicomCodec codec,
            DicomCodecParams parameters)
        {
            var oldPixelData = DicomPixelData.Create(oldDataset, false);

            var newDataset = oldDataset.Clone();

            newDataset.InternalTransferSyntax = outSyntax;
            var newPixelData = DicomPixelData.Create(newDataset, true);

            codec.Decode(oldPixelData, newPixelData, parameters);

            ProcessOverlays(oldDataset, newDataset);

            newDataset.RecalculateGroupLengths(false);

            return(newDataset);
        }
Пример #20
0
		private DicomDataset Encode(DicomDataset oldDataset, DicomTransferSyntax inSyntax, IDicomCodec codec, DicomCodecParams parameters) {
			DicomPixelData oldPixelData = DicomPixelData.Create(oldDataset, false);

			DicomDataset newDataset = oldDataset.Clone();
			newDataset.InternalTransferSyntax = codec.TransferSyntax;
			DicomPixelData newPixelData = DicomPixelData.Create(newDataset, true);

			codec.Encode(oldPixelData, newPixelData, parameters);

			if (codec.TransferSyntax.IsLossy && newPixelData.NumberOfFrames > 0) {
				newDataset.Add(new DicomCodeString(DicomTag.LossyImageCompression, "01"));

				List<string> methods = new List<string>();
				if (newDataset.Contains(DicomTag.LossyImageCompressionMethod))
					methods.AddRange(newDataset.Get<string[]>(DicomTag.LossyImageCompressionMethod));
				methods.Add(codec.TransferSyntax.LossyCompressionMethod);
				newDataset.Add(new DicomCodeString(DicomTag.LossyImageCompressionMethod, methods.ToArray()));

				double oldSize = oldPixelData.GetFrame(0).Size;
				double newSize = newPixelData.GetFrame(0).Size;
				string ratio = String.Format("{0:0.000}", oldSize / newSize);
				newDataset.Add(new DicomDecimalString(DicomTag.LossyImageCompressionRatio, ratio));
			}

			ProcessOverlays(oldDataset, newDataset);

			newDataset.RecalculateGroupLengths(false);

			return newDataset;
		}
Пример #21
0
		private DicomDataset Decode(DicomDataset oldDataset, DicomTransferSyntax outSyntax, IDicomCodec codec, DicomCodecParams parameters) {
			DicomPixelData oldPixelData = DicomPixelData.Create(oldDataset, false);

			DicomDataset newDataset = oldDataset.Clone();
			newDataset.InternalTransferSyntax = outSyntax;
			DicomPixelData newPixelData = DicomPixelData.Create(newDataset, true);

			codec.Decode(oldPixelData, newPixelData, parameters);

			ProcessOverlays(oldDataset, newDataset);

			newDataset.RecalculateGroupLengths(false);

			return newDataset;
		}
Пример #22
0
        public static DicomFile ChangeTransferSyntax(this DicomFile file, DicomTransferSyntax syntax, DicomCodecParams parameters = null)
        {
            DicomTranscoder transcoder = new DicomTranscoder(file.FileMetaInfo.TransferSyntax, syntax);

            transcoder.InputCodecParams  = parameters;
            transcoder.OutputCodecParams = parameters;
            return(transcoder.Transcode(file));
        }
Пример #23
0
        public static DicomDataset ChangeTransferSyntax(this DicomDataset dataset, DicomTransferSyntax syntax, DicomCodecParams parameters = null)
        {
            DicomTranscoder transcoder = new DicomTranscoder(dataset.InternalTransferSyntax, syntax);

            transcoder.InputCodecParams  = parameters;
            transcoder.OutputCodecParams = parameters;
            return(transcoder.Transcode(dataset));
        }
Пример #24
0
		private void ChangeSyntax(DicomTransferSyntax syntax, DicomCodecParams param = null) {
			var file = _file.ChangeTransferSyntax(syntax, param);
			OpenFile(file);
		}
Пример #25
0
		public static DicomDataset ChangeTransferSyntax(this DicomDataset dataset, DicomTransferSyntax syntax, DicomCodecParams parameters = null) {
			DicomTranscoder transcoder = new DicomTranscoder(dataset.InternalTransferSyntax, syntax);
			transcoder.InputCodecParams = parameters;
			transcoder.OutputCodecParams = parameters;
			return transcoder.Transcode(dataset);
		}
 public abstract void Decode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters);
Пример #27
0
		public static DicomFile ChangeTransferSyntax(this DicomFile file, DicomTransferSyntax syntax, DicomCodecParams parameters = null) {
			DicomTranscoder transcoder = new DicomTranscoder(file.FileMetaInfo.TransferSyntax, syntax);
			transcoder.InputCodecParams = parameters;
			transcoder.OutputCodecParams = parameters;
			return transcoder.Transcode(file);
		}
Пример #28
0
        private DicomDataset Encode(DicomDataset oldDataset, DicomTransferSyntax inSyntax, IDicomCodec codec, DicomCodecParams parameters)
        {
            DicomPixelData oldPixelData = DicomPixelData.Create(oldDataset, false);

            DicomDataset newDataset = oldDataset.Clone();

            newDataset.InternalTransferSyntax = codec.TransferSyntax;
            DicomPixelData newPixelData = DicomPixelData.Create(newDataset, true);

            codec.Encode(oldPixelData, newPixelData, parameters);

            if (codec.TransferSyntax.IsLossy && newPixelData.NumberOfFrames > 0)
            {
                newDataset.Add(new DicomCodeString(DicomTag.LossyImageCompression, "01"));

                List <string> methods = new List <string>();
                if (newDataset.Contains(DicomTag.LossyImageCompressionMethod))
                {
                    methods.AddRange(newDataset.Get <string[]>(DicomTag.LossyImageCompressionMethod));
                }
                methods.Add(codec.TransferSyntax.LossyCompressionMethod);
                newDataset.Add(new DicomCodeString(DicomTag.LossyImageCompressionMethod, methods.ToArray()));

                double oldSize = oldPixelData.GetFrame(0).Size;
                double newSize = newPixelData.GetFrame(0).Size;
                string ratio   = String.Format("{0:0.000}", oldSize / newSize);
                newDataset.Add(new DicomDecimalString(DicomTag.LossyImageCompressionRatio, ratio));
            }

            ProcessOverlays(oldDataset, newDataset);

            newDataset.RecalculateGroupLengths(false);

            return(newDataset);
        }
Пример #29
0
 public abstract void Encode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters);
Пример #30
0
        private DicomDataset Decode(DicomDataset oldDataset, DicomTransferSyntax outSyntax, IDicomCodec codec, DicomCodecParams parameters)
        {
            DicomPixelData oldPixelData = DicomPixelData.Create(oldDataset, false);

            DicomDataset newDataset = oldDataset.Clone();

            newDataset.InternalTransferSyntax = outSyntax;
            DicomPixelData newPixelData = DicomPixelData.Create(newDataset, true);

            codec.Decode(oldPixelData, newPixelData, parameters);

            newDataset.RecalculateGroupLengths(false);

            return(newDataset);
        }