Exemplo n.º 1
0
        /// <summary>
        /// Initialize new instance of <seealso cref="GenericGrayscalePipeline"/> which consist of the following sequence
        /// Rescale (Modality) LUT -> VOI LUT -> Output LUT and optionally Invert LUT if specified by grayscale options
        /// </summary>
        /// <param name="options">Grayscale options to use in the pipeline</param>
        public GenericGrayscalePipeline(GrayscaleRenderOptions options)
        {
            _options = options;
            if (options.ModalityLUTSequence != null)
            {
                _modalityLut = new ModalitySequenceLUT(_options);
            }
            else if (_options.RescaleSlope != 1.0 || _options.RescaleIntercept != 0.0)
            {
                _modalityLut = new ModalityRescaleLUT(_options);
            }

            if (_options.UseVOILUT && options.VOILUTSequence != null)
            {
                _voiSequenceLut = new VOISequenceLUT(_options);
                _voiLut         = new VOILinearLUT(GrayscaleRenderOptions.CreateLinearOption(_options.BitDepth, _voiSequenceLut.MinimumOutputValue, _voiSequenceLut.MaximumOutputValue));
            }
            else
            {
                _voiLut = VOILUT.Create(_options);
            }

            _outputLut = new OutputLUT(_options);
            if (_options.Invert)
            {
                _invertLut = new InvertLUT(_outputLut.MinimumOutputValue, _outputLut.MaximumOutputValue);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        private static int[] GetIntPixels(DicomImage image)
        {
            var gro    = GrayscaleRenderOptions.FromDataset(image.Dataset);
            var voilut = VOILUT.Create(gro);

            var ipd = PixelDataFactory.Create(image.PixelData, 0);

            int[] outPixelsInt = new int[image.Width * image.Height];
            ipd.Render(voilut, outPixelsInt);
            return(outPixelsInt);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initialize new instance of <seealso cref="GenericGrayscalePipeline"/> which consist of the following sequence
 /// Rescale (Modality) LUT -> VOI LUT -> Output LUT and optionally Invert LUT if specified by grayscale options
 /// </summary>
 /// <param name="options">Grayscale options to use in the pipeline</param>
 public GenericGrayscalePipeline(GrayscaleRenderOptions options)
 {
     if (options.RescaleSlope != 1.0 || options.RescaleIntercept != 0.0)
     {
         _rescaleLut = new ModalityLUT(options);
     }
     _voiLut    = VOILUT.Create(options);
     _outputLut = new OutputLUT(options.Monochrome1 ? ColorTable.Monochrome1 : ColorTable.Monochrome2);
     if (options.Invert)
     {
         _invertLut = new InvertLUT(_outputLut.MinimumOutputValue, _outputLut.MaximumOutputValue);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initialize new instance of <seealso cref="GenericGrayscalePipeline"/> which consist of the following sequence
 /// Rescale (Modality) LUT -> VOI LUT -> Output LUT and optionally Invert LUT if specified by grayscale options
 /// </summary>
 /// <param name="options">Grayscale options to use in the pipeline</param>
 public GenericGrayscalePipeline(GrayscaleRenderOptions options)
 {
     _options = options;
     if (_options.RescaleSlope != 1.0 || _options.RescaleIntercept != 0.0)
     {
         _rescaleLut = new ModalityLUT(_options);
     }
     _voiLut    = VOILUT.Create(_options);
     _outputLut = new OutputLUT(_options);
     if (_options.Invert)
     {
         _invertLut = new InvertLUT(_outputLut.MinimumOutputValue, _outputLut.MaximumOutputValue);
     }
 }
Exemplo n.º 5
0
        void StoreImage(DicomDataset ds, string modality)
        {
            DicomImage di = new DicomImage(ds);

            // store in cached resource
            var idc = new ImageDataContract();

            idc.PatientId = ds.Get <string>(DicomTag.PatientID);

            if (ds.Contains(DicomTag.PixelSpacing))
            {
                idc.PixelSpacing = new VoxelSize()
                {
                    X = Convert.ToSingle(ds.Get <double>(DicomTag.PixelSpacing, 0)),
                    Y = Convert.ToSingle(ds.Get <double>(DicomTag.PixelSpacing, 1)),
                };
            }
            else
            {
                idc.PixelSpacing = new VoxelSize()
                {
                    X = 1.0f,
                    Y = 1.0f,
                };
            }

            idc.ImagePosition = new ImagePosition()
            {
                X = Convert.ToSingle(ds.Get <double>(DicomTag.ImagePositionPatient, 0)),
                Y = Convert.ToSingle(ds.Get <double>(DicomTag.ImagePositionPatient, 1)),
                Z = Convert.ToSingle(ds.Get <double>(DicomTag.ImagePositionPatient, 2)),
            };

            idc.ImageOrientation     = new ImageOrientation();
            idc.ImageOrientation.Row = new DirectionCosine()
            {
                X = Convert.ToSingle(ds.Get <double>(DicomTag.ImageOrientationPatient, 0)),
                Y = Convert.ToSingle(ds.Get <double>(DicomTag.ImageOrientationPatient, 1)),
                Z = Convert.ToSingle(ds.Get <double>(DicomTag.ImageOrientationPatient, 2)),
            };

            idc.ImageOrientation.Column = new DirectionCosine()
            {
                X = Convert.ToSingle(ds.Get <double>(DicomTag.ImageOrientationPatient, 3)),
                Y = Convert.ToSingle(ds.Get <double>(DicomTag.ImageOrientationPatient, 4)),
                Z = Convert.ToSingle(ds.Get <double>(DicomTag.ImageOrientationPatient, 5)),
            };

            idc.Width  = di.Width;
            idc.Height = di.Height;
            idc.Label  = string.Format("{0} {1}",
                                       modality,
                                       ds.GetDateTime(DicomTag.SeriesDate, DicomTag.SeriesTime).ToString());
            idc.SeriesInstanceUID = ds.Get <string>(DicomTag.SeriesInstanceUID);

            // store for association closed event
            _seriesInstanceUIDs.Add(idc.SeriesInstanceUID);

            string for_uid = ds.Get <string>(DicomTag.FrameOfReferenceUID);

            idc.FrameOfReferenceUID = for_uid;

            LocalImageResourceManagerClient
                cache1 = new LocalImageResourceManagerClient();

            idc = cache1.AddImage(idc);
            double repoGb = cache1.GetRepositorySizeGB();

            cache1.Close();

            if (di.PhotometricInterpretation == PhotometricInterpretation.Monochrome1 ||
                di.PhotometricInterpretation == PhotometricInterpretation.Monochrome2)
            {
                var dsForWl = di.Dataset;
                if (_firstImageIn.ContainsKey(idc.SeriesInstanceUID))
                {
                    dsForWl = _firstImageIn[idc.SeriesInstanceUID].Dataset;
                }
                else
                {
                    _firstImageIn.TryAdd(idc.SeriesInstanceUID, di);
                }

                var gro    = GrayscaleRenderOptions.FromDataset(dsForWl);
                var voilut = VOILUT.Create(gro);

                var ipd = PixelDataFactory.Create(di.PixelData, 0);

                int[] outPixelsInt = new int[di.Width * di.Height];
                ipd.Render(voilut, outPixelsInt);

                ushort[] outPixelsUshort = Array.ConvertAll(outPixelsInt,
                                                            new Converter <int, ushort>(inInt => (ushort)(inInt)));
                var handle = idc.PixelBuffer.GetHandle();
                handle.WriteArray <ushort>(0, outPixelsUshort, 0, outPixelsUshort.Length);
                idc.PixelBuffer.ReleaseHandle();
                idc.PixelBuffer.CloseMapping();

                // publish the image stored message
                _endpointInstance.Publish(new ImageStored
                {
                    ImageGuid = idc.ImageId,
                    RepoGb    = repoGb,
                });
            }
        }