public static GrayscaleRenderOptions FromDataset(DicomDataset dataset)
        {
            var bits = BitDepth.FromDataset(dataset);
            var options = new GrayscaleRenderOptions(bits);
            options.RescaleSlope = dataset.Get<double>(DicomTag.RescaleSlope, 1.0);
            options.RescaleIntercept = dataset.Get<double>(DicomTag.RescaleIntercept, 0.0);
            if (dataset.Contains(DicomTag.WindowWidth) && dataset.Get<double>(DicomTag.WindowWidth) != 0.0) {
                options.WindowWidth = dataset.Get<double>(DicomTag.WindowWidth);
                options.WindowCenter = dataset.Get<double>(DicomTag.WindowCenter);
            } else if (dataset.Contains(DicomTag.SmallestImagePixelValue) && dataset.Contains(DicomTag.LargestImagePixelValue)) {
                var smallElement = dataset.Get<DicomElement>(DicomTag.SmallestImagePixelValue);
                var largeElement = dataset.Get<DicomElement>(DicomTag.LargestImagePixelValue);

                int smallValue = 0;
                int largeValue = 0;

                if (smallElement.ValueRepresentation == DicomVR.US) {
                    smallValue = smallElement.Get<ushort>(0);
                    largeValue = smallElement.Get<ushort>(0);
                } else {
                    smallValue = smallElement.Get<short>(0);
                    largeValue = smallElement.Get<short>(0);
                }

                options.WindowWidth = largeValue - smallValue;
                options.WindowCenter = (largeValue + smallValue) / 2.0;
            }
            options.Monochrome1 = dataset.Get<PhotometricInterpretation>(DicomTag.PhotometricInterpretation) == PhotometricInterpretation.Monochrome1;
            return options;
        }
 /// <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);
 }
 /// <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);
 }
 public GenericGrayscalePipeline(GrayscaleRenderOptions options)
 {
     if (options.RescaleSlope != 1.0 || options.RescaleIntercept != 0.0)
         _rescaleLut = new RescaleLUT(options.BitDepth.MinimumValue, options.BitDepth.MaximumValue,
                                      options.RescaleSlope, options.RescaleIntercept);
     _voiLut = new VOILinearLUT(options.WindowCenter, options.WindowWidth);
     _outputLut = new OutputLUT(options.Monochrome1 ? ColorTable.Monochrome1 : ColorTable.Monochrome2);
     if (options.Invert)
         _invertLut = new InvertLUT(_outputLut.MinimumOutputValue, _outputLut.MaximumOutputValue);
 }
 /// <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.VOILUTSequence != null)
     {
         _voiSequenceLut = new VOISequenceLUT(_options);
     }
     _voiLut    = VOILUT.Create(_options);
     _outputLut = new OutputLUT(_options);
     if (_options.Invert)
     {
         _invertLut = new InvertLUT(_outputLut.MinimumOutputValue, _outputLut.MaximumOutputValue);
     }
 }
Beispiel #6
0
        private void OnKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                _frame++;
                if (_frame >= _image.NumberOfFrames)
                {
                    _frame--;
                }
                DisplayImage(_image);
                return;
            }

            if (e.KeyCode == Keys.Left)
            {
                _frame--;
                if (_frame < 0)
                {
                    _frame++;
                }
                DisplayImage(_image);
                return;
            }

            if (e.KeyCode == Keys.O)
            {
                _image.ShowOverlays = !_image.ShowOverlays;
                DisplayImage(_image);
                return;
            }

            GrayscaleRenderOptions options = null;

            if (e.KeyCode == Keys.D0)
            {
                options = GrayscaleRenderOptions.FromDataset(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D1)
            {
                options = GrayscaleRenderOptions.FromWindowLevel(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D2)
            {
                options = GrayscaleRenderOptions.FromImagePixelValueTags(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D3)
            {
                options = GrayscaleRenderOptions.FromMinMax(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D4)
            {
                options = GrayscaleRenderOptions.FromBitRange(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D5)
            {
                options = GrayscaleRenderOptions.FromHistogram(_image.Dataset, 90);
            }

            if (options != null)
            {
                _image.WindowWidth  = options.WindowWidth;
                _image.WindowCenter = options.WindowCenter;

                DisplayImage(_image);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Initialize new instance of <seealso cref="OutputLUT"/>
 /// </summary>
 /// <param name="options">The grayscale render options containing the grayscale color map.</param>
 public OutputLUT(GrayscaleRenderOptions options)
 {
     _options = options;
 }
Beispiel #8
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOISequenceLUT"/> using the specified VOI LUT Descriptor and Data
 /// </summary>
 /// <param name="options">Render options</param>
 public VOISequenceLUT(GrayscaleRenderOptions options)
 {
     _renderOptions = options;
     Recalculate();
 }
Beispiel #9
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOUTLUT"/>
 /// </summary>
 /// <param name="options">Render options</param>
 public VOILUT(GrayscaleRenderOptions options)
 {
     _renderOptions = options;
     Recalculate();
 }
Beispiel #10
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOISigmoidLUT"/>
 /// </summary>
 /// <param name="options">Render options</param>
 public VOISigmoidLUT(GrayscaleRenderOptions options)
     : base(options)
 {
 }
Beispiel #11
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,
                });
            }
        }
Beispiel #12
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOISigmoidLUT"/>
 /// </summary>
 /// <param name="options">Render options</param>
 public VOISigmoidLUT(GrayscaleRenderOptions options)
     : base(options)
 {
 }
Beispiel #13
0
		/// <summary>
		/// Initialize new instance of <seealso cref="ModalityLUT"/> using the specified slope and intercept parameters
		/// </summary>
		/// <param name="options">Render options</param>
		public ModalityLUT(GrayscaleRenderOptions options) {
			_renderOptions = options;
			_minValue = this[options.BitDepth.MinimumValue];
			_maxValue = this[options.BitDepth.MaximumValue];
		}
Beispiel #14
0
 /// <summary>
 /// Initialize new instance of <seealso cref="OutputLUT"/> 
 /// </summary>
 /// <param name="options">The grayscale render options containing the grayscale color map.</param>
 public OutputLUT(GrayscaleRenderOptions options)
 {
     _options = options;
 }
Beispiel #15
0
 /// <summary>
 /// Initialize new instance of <seealso cref="ModalityRescaleLUT"/> using the specified slope and intercept parameters
 /// </summary>
 /// <param name="options">Render options</param>
 public ModalityRescaleLUT(GrayscaleRenderOptions options)
 {
     _renderOptions     = options;
     MinimumOutputValue = this[options.BitDepth.MinimumValue];
     MaximumOutputValue = this[options.BitDepth.MaximumValue];
 }
Beispiel #16
0
 /// <summary>
 /// Initialize new instance of <seealso cref="ModalityLUT"/> using the specified slope and intercept parameters
 /// </summary>
 /// <param name="options">Render options</param>
 public ModalityLUT(GrayscaleRenderOptions options)
 {
     _renderOptions = options;
     _minValue      = this[options.BitDepth.MinimumValue];
     _maxValue      = this[options.BitDepth.MaximumValue];
 }
Beispiel #17
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOILinearLUT"/>
 /// </summary>
 /// <param name="options">Render options</param>
 public VOILinearLUT(GrayscaleRenderOptions options)
     : base(options)
 {
 }
Beispiel #18
0
        /// <summary>
        /// Create a new VOILUT according to <paramref name="function"/>, <paramref name=" windowCenter"/>
        /// and <paramref name="windowWidth"/>
        /// </summary>
        /// <param name="options">Render options</param>
        /// <returns></returns>
        public static VOILUT Create(GrayscaleRenderOptions options)
        {
            switch (options.VOILUTFunction.ToUpper())
            {
                case "SIGMOID":
                    return new VOISigmoidLUT(options);
                default:
                    break;
            }

            return new VOILinearLUT(options);
        }
Beispiel #19
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOILUT"/>
 /// </summary>
 /// <param name="options">Render options</param>
 protected VOILUT(GrayscaleRenderOptions options)
 {
     _renderOptions = options;
     Recalculate();
 }
Beispiel #20
0
 /// <summary>
 /// Initialize new instance of <seealso cref="VOILinearLUT"/>
 /// </summary>
 /// <param name="options">Render options</param>
 public VOILinearLUT(GrayscaleRenderOptions options)
     : base(options)
 {
 }