/// <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 ChangeTransferSyntax( this DicomFile file, DicomTransferSyntax syntax, DicomCodecParams parameters = null) { var transcoder = new DicomTranscoder(file.FileMetaInfo.TransferSyntax, syntax, parameters, parameters); return transcoder.Transcode(file); }
public override void Encode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { DicomRleNativeCodec.Encode(oldPixelData.ToNativePixelData(), newPixelData.ToNativePixelData()); }
public override void Encode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { DicomJpegCodecImpl.Encode(oldPixelData, newPixelData, parameters as DicomJpegParams); }
/// <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 ChangeTransferSyntax( this DicomDataset dataset, DicomTransferSyntax syntax, DicomCodecParams parameters = null) { var transcoder = new DicomTranscoder(dataset.InternalTransferSyntax, syntax, parameters, parameters); return transcoder.Transcode(dataset); }
/// <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 ChangeTransferSyntax( this DicomFile file, DicomTransferSyntax syntax, DicomCodecParams parameters = null) { var transcoder = new DicomTranscoder(file.FileMetaInfo.TransferSyntax, syntax, parameters, parameters); return(transcoder.Transcode(file)); }
/// <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 ChangeTransferSyntax( this DicomDataset dataset, DicomTransferSyntax syntax, DicomCodecParams parameters = null) { var transcoder = new DicomTranscoder(dataset.InternalTransferSyntax, syntax, parameters, parameters); return(transcoder.Transcode(dataset)); }
public override void Decode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { DicomJpegLsNativeCodec.Decode( oldPixelData.ToNativePixelData(), newPixelData.ToNativePixelData(), parameters.ToNativeJpegLSParameters()); }
public override void Encode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { DicomJpeg2000NativeCodec.Encode( oldPixelData.ToNativePixelData(), newPixelData.ToNativePixelData(), parameters.ToNativeJpeg2000Parameters()); }
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 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); }
/// <summary> /// Loads the pixel data for specified frame and set the internal dataset /// /// </summary> /// <param name="dataset">dataset to load pixeldata from</param> /// <param name="frame">The frame number to create pixeldata for</param> private void Load(DicomDataset dataset, int frame) { Dataset = dataset; if (PixelData == null) { PixelData = DicomPixelData.Create(Dataset); PhotometricInterpretation = PixelData.PhotometricInterpretation; } if (Dataset.InternalTransferSyntax.IsEncapsulated) { // decompress single frame from source dataset DicomCodecParams cparams = null; if (Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess1 || Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) { cparams = new DicomJpegParams { ConvertColorspaceToRGB = true }; } var transcoder = new DicomTranscoder(Dataset.InternalTransferSyntax, DicomTransferSyntax.ExplicitVRLittleEndian); transcoder.InputCodecParams = cparams; transcoder.OutputCodecParams = cparams; var buffer = transcoder.DecodeFrame(Dataset, frame); // clone the dataset because modifying the pixel data modifies the dataset var clone = Dataset.Clone(); clone.InternalTransferSyntax = DicomTransferSyntax.ExplicitVRLittleEndian; var pixelData = DicomPixelData.Create(clone, true); pixelData.AddFrame(buffer); // temporary fix for JPEG compressed YBR images if ((Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess1 || Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) && pixelData.SamplesPerPixel == 3) { pixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb; } _pixelData = PixelDataFactory.Create(pixelData, 0); } else { // pull uncompressed frame from source pixel data _pixelData = PixelDataFactory.Create(PixelData, frame); } _pixelData.Rescale(_scale); _overlays = DicomOverlayData.FromDataset(Dataset).Where(x => x.Type == DicomOverlayType.Graphics && x.Data != null).ToArray(); _currentFrame = frame; CreatePipeline(); }
public override void Encode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { #if NETFX_CORE && !HOLOLENS DicomJpeg2000NativeCodec.Encode( oldPixelData.ToNativePixelData(), newPixelData.ToNativePixelData(), parameters.ToNativeJpeg2000Parameters()); #else DicomJpeg2000CodecImpl.Encode(oldPixelData, newPixelData, parameters as DicomJpeg2000Params); #endif }
public override void Encode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { #if NETFX_CORE DicomJpeg2000NativeCodec.Encode( oldPixelData.ToNativePixelData(), newPixelData.ToNativePixelData(), parameters.ToNativeJpeg2000Parameters()); #else DicomJpeg2000CodecImpl.Encode(oldPixelData, newPixelData, parameters as DicomJpeg2000Params); #endif }
public static NativeJpegLSParameters ToNativeJpegLSParameters(this DicomCodecParams codecParams) { var jlsParams = codecParams as DicomJpegLsParams; if (jlsParams == null) { return(null); } return(new NativeJpegLSParameters { AllowedError = jlsParams.AllowedError, InterleaveMode = (int)jlsParams.InterleaveMode, ColorTransform = (int)jlsParams.ColorTransform }); }
/// <summary> /// The JPEG-LS decoding function /// </summary> /// <param name="oldPixelData">The old pixel data</param> /// <param name="newPixelData">The new pixel data</param> /// <param name="parameters">The compression parameters</param> public override void Decode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++) { var jpegLsData = oldPixelData.GetFrame(frame); var message = String.Empty; var jpegLsParams = new JlsParameters(); var frameData = new byte[newPixelData.UncompressedFrameSize]; var err = JpegLs.Decode(frameData, jpegLsData.Data, jpegLsParams, out message); var buffer = frameData.Length >= 1 * 1024 * 1024 || oldPixelData.NumberOfFrames > 1 ? (IByteBuffer) new TempFileBuffer(frameData) : new MemoryByteBuffer(frameData); newPixelData.AddFrame(EvenLengthBuffer.Create(buffer)); } }
public static NativeJpegParameters ToNativeJpegParameters(this DicomCodecParams codecParams) { var jpegParams = codecParams as DicomJpegParams; if (jpegParams == null) { return(null); } return(new NativeJpegParameters { Quality = jpegParams.Quality, SmoothingFactor = jpegParams.SmoothingFactor, ConvertColorspaceToRGB = jpegParams.ConvertColorspaceToRGB, SampleFactor = (int)jpegParams.SampleFactor, Predictor = jpegParams.Predictor, PointTransform = jpegParams.PointTransform }); }
public static NativeJpeg2000Parameters ToNativeJpeg2000Parameters(this DicomCodecParams codecParams) { var jp2Params = codecParams as DicomJpeg2000Params; if (jp2Params == null) { return(null); } return(new NativeJpeg2000Parameters { Irreversible = jp2Params.Irreversible, Rate = jp2Params.Rate, RateLevels = jp2Params.RateLevels, AllowMCT = jp2Params.AllowMCT, EncodeSignedPixelValuesAsUnsigned = jp2Params.EncodeSignedPixelValuesAsUnsigned, IsVerbose = jp2Params.IsVerbose, UpdatePhotometricInterpretation = jp2Params.UpdatePhotometricInterpretation }); }
public override unsafe void Encode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { throw new InvalidOperationException("Unsupported OS Platform"); } if ((oldPixelData.PhotometricInterpretation == PhotometricInterpretation.YbrPartial422) || (oldPixelData.PhotometricInterpretation == PhotometricInterpretation.YbrPartial420)) { throw new DicomCodecException("Photometric Interpretation '{0}' not supported by JPEG-LS encoder", oldPixelData.PhotometricInterpretation); } DicomJpegLsParams jparams = (DicomJpegLsParams)parameters; if (jparams == null) { jparams = (DicomJpegLsParams)GetDefaultParameters(); } //IMPORT JLSPARAMETERS (DLLIMPORT) JlsParameters jls = new JlsParameters { width = oldPixelData.Width, height = oldPixelData.Height, bitsPerSample = oldPixelData.BitsStored, stride = oldPixelData.BytesAllocated * oldPixelData.Width * oldPixelData.SamplesPerPixel, components = oldPixelData.SamplesPerPixel, interleaveMode = oldPixelData.SamplesPerPixel == 1 ? CharlsInterleaveModeType.None : oldPixelData.PlanarConfiguration == PlanarConfiguration.Interleaved ? CharlsInterleaveModeType.Sample : CharlsInterleaveModeType.Line, colorTransformation = CharlsColorTransformationType.None }; if (TransferSyntax == DicomTransferSyntax.JPEGLSNearLossless) { jls.allowedLossyError = jparams.AllowedError; } for (int frame = 0; frame < oldPixelData.NumberOfFrames; frame++) { IByteBuffer frameData = oldPixelData.GetFrame(frame); //Converting photmetricinterpretation YbrFull or YbrFull422 to RGB if (oldPixelData.PhotometricInterpretation == PhotometricInterpretation.YbrFull) { frameData = PixelDataConverter.YbrFullToRgb(frameData); oldPixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb; } else if (oldPixelData.PhotometricInterpretation == PhotometricInterpretation.YbrFull422) { frameData = PixelDataConverter.YbrFull422ToRgb(frameData, oldPixelData.Width); oldPixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb; } PinnedByteArray frameArray = new PinnedByteArray(frameData.Data); byte[] jpegData = new byte[frameData.Size]; PinnedByteArray jpegArray = new PinnedByteArray(jpegData); uint jpegDataSize = 0; char[] errorMessage = new char[256]; // IMPORT JpegLsEncode unsafe { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { CharlsApiResultType err = JpegLSEncode_Linux64((void *)jpegArray.Pointer, checked ((uint)jpegArray.Count), &jpegDataSize, (void *)frameArray.Pointer, checked ((uint)frameArray.Count), ref jls, errorMessage); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { CharlsApiResultType err = JpegLSEncode_Windows64((void *)jpegArray.Pointer, checked ((uint)jpegArray.Count), &jpegDataSize, (void *)frameArray.Pointer, checked ((uint)frameArray.Count), ref jls, errorMessage); } Array.Resize(ref jpegData, (int)jpegDataSize); IByteBuffer buffer; if (jpegDataSize >= (1 * 1024 * 1024) || oldPixelData.NumberOfFrames > 1) { buffer = new TempFileBuffer(jpegData); } else { buffer = new MemoryByteBuffer(jpegData); } buffer = EvenLengthBuffer.Create(buffer); newPixelData.AddFrame(buffer); } } }
public abstract void Decode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters);
static public DicomDataset Compress(this DicomDataset original, DicomTransferSyntax dicomTransferSyntax, IDicomCodec codec, DicomCodecParams jpegParams) { DicomDataset dataset = new DicomDataset(dicomTransferSyntax); original.CopyTo(dataset); DicomPixelData pixelData = DicomPixelData.Create(dataset, true); DicomPixelData pixelDataSource = DicomPixelData.Create(original, false); codec.Encode(pixelDataSource, pixelData, jpegParams); return(dataset); }
public override void Encode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { throw new DicomCodecException($"Encoding of transfersyntax {TransferSyntax} is not supported"); }
public override void Decode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++) { var encodedData = oldPixelData.GetFrame(frame); var decodedData = ReadImage(encodedData); newPixelData.AddFrame(new StreamByteBuffer(decodedData, 0, (uint)decodedData.Length)); } }
/// <summary> /// The encoding function, which is not implemented, since this application is /// not encoding anything to JPEG-LS /// </summary> /// <param name="oldPixelData">The old pixel data</param> /// <param name="newPixelData">The new pixel data</param> /// <param name="parameters">The compression parameters</param> public override void Encode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { throw new DicomCodecException(String.Format("Encoding of transfer syntax {0} is not implemented", TransferSyntax)); }
private void ChangeSyntax(DicomTransferSyntax syntax, DicomCodecParams param = null) { var file = _file.Clone(syntax, param); OpenFile(file); }
public override void Decode(DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { throw new InvalidOperationException("Unsupported OS Platform"); } for (int frame = 0; frame < oldPixelData.NumberOfFrames; frame++) { IByteBuffer jpegData = oldPixelData.GetFrame(frame); //Converting photmetricinterpretation YbrFull or YbrFull422 to RGB if (oldPixelData.PhotometricInterpretation == PhotometricInterpretation.YbrFull) { jpegData = PixelDataConverter.YbrFullToRgb(jpegData); oldPixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb; } else if (oldPixelData.PhotometricInterpretation == PhotometricInterpretation.YbrFull422) { jpegData = PixelDataConverter.YbrFull422ToRgb(jpegData, oldPixelData.Width); oldPixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb; } PinnedByteArray jpegArray = new PinnedByteArray(jpegData.Data); byte[] frameData = new byte[newPixelData.UncompressedFrameSize]; PinnedByteArray frameArray = new PinnedByteArray(frameData); JlsParameters jls = new JlsParameters(); char[] errorMessage = new char[256]; // IMPORT JpegLsDecode unsafe { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { CharlsApiResultType err = JpegLSDecode_Linux64((void *)frameArray.Pointer, frameData.Length, (void *)jpegArray.Pointer, Convert.ToUInt32(jpegData.Size), ref jls, errorMessage); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { CharlsApiResultType err = JpegLSDecode_Windows64((void *)frameArray.Pointer, frameData.Length, (void *)jpegArray.Pointer, Convert.ToUInt32(jpegData.Size), ref jls, errorMessage); } IByteBuffer buffer; if (frameData.Length >= (1 * 1024 * 1024) || oldPixelData.NumberOfFrames > 1) { buffer = new TempFileBuffer(frameData); } else { buffer = new MemoryByteBuffer(frameData); } buffer = EvenLengthBuffer.Create(buffer); newPixelData.AddFrame(buffer); } } }