public override void Apply(IPresentationImage presentationImage)
        {
            if (!AppliesTo(presentationImage))
            {
                throw new InvalidOperationException("The input presentation image is not supported.");
            }

            IVoiLutManager manager    = ((IVoiLutProvider)presentationImage).VoiLutManager;
            IVoiLut        currentLut = manager.VoiLut;

            if (currentLut is MinMaxPixelCalculatedLinearLut)
            {
                return;
            }

            GrayscalePixelData pixelData = (GrayscalePixelData)((IImageGraphicProvider)presentationImage).ImageGraphic.PixelData;

            IModalityLutProvider modalityLutProvider = presentationImage as IModalityLutProvider;

            if (modalityLutProvider != null)
            {
                manager.InstallVoiLut(new MinMaxPixelCalculatedLinearLut(pixelData, modalityLutProvider.ModalityLut));
            }
            else
            {
                manager.InstallVoiLut(new MinMaxPixelCalculatedLinearLut(pixelData));
            }
        }
Beispiel #2
0
        public void ApplyProbabilityThreshold(int threshold, int opacity)
        {
            if (!this.ProbabilityMapVisible)
            {
                return;
            }

            _threshold = threshold;
            _opacity   = opacity;

            GrayscalePixelData probabilityPixelData = new GrayscalePixelData(
                _imageGraphic.Rows,
                _imageGraphic.Columns,
                _imageGraphic.BitsPerPixel,
                _imageGraphic.BitsStored,
                _imageGraphic.HighBit,
                _imageGraphic.IsSigned,
                _probabilityMap);

            probabilityPixelData.ForEachPixel(
                delegate(int i, int x, int y, int pixelIndex)
            {
                if (probabilityPixelData.GetPixel(pixelIndex) < threshold)
                {
                    _probabilityOverlay.PixelData.SetPixel(pixelIndex, Color.FromArgb(opacity, Color.Red));
                }
                else
                {
                    _probabilityOverlay.PixelData.SetPixel(pixelIndex, Color.Empty);
                }
            });
        }
Beispiel #3
0
        public void ForEachPixel()
        {
            int  columns         = 5;
            int  rows            = 4;
            int  bitsAllocated   = 16;
            int  bitsStored      = 16;
            int  highBit         = 15;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int i = 0;

            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < columns; x++)
                {
                    pixelDataWrapper.SetPixel(x, y, i);
                    i++;
                }
            }

            int left = 1, top = 1, right = 3, bottom = 3;

            int pixelCount = 0;

            pixelDataWrapper.ForEachPixel(left, top, right, bottom,
                                          delegate(int j, int x, int y, int pixelIndex)
            {
                if (j == 0)
                {
                    Assert.AreEqual(6, pixelDataWrapper.GetPixel(pixelIndex));
                }
                else if (j == 1)
                {
                    Assert.AreEqual(7, pixelDataWrapper.GetPixel(pixelIndex));
                }
                else if (j == 3)
                {
                    Assert.AreEqual(11, pixelDataWrapper.GetPixel(pixelIndex));
                }

                pixelCount++;
            });

            Assert.AreEqual(9, pixelCount);
        }
Beispiel #4
0
        public void Signed9Bit()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 9;
            int  highBit         = 8;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            pixelData[0] = 255;
            pixelData[1] = 1;

            int actualValue = pixelDataWrapper.GetPixel(0, 0);

            Assert.AreEqual(-1, actualValue);

            int expectedValue = -1;

            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);

            expectedValue = -256;
            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);

            expectedValue = 255;
            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);

            expectedValue = 0;
            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);
        }
		public void TestSimple()
		{
			byte[] data = new byte[25];
			for (byte x = 0; x < 25; ++x)
			{
				data[x] = x;
			}

			GrayscalePixelData pixelData = new GrayscalePixelData(5, 5, 8, 8, 7, false, data);
			MinMaxPixelCalculatedLinearLut lut = new MinMaxPixelCalculatedLinearLut(pixelData);
			lut.MinInputValue = 0;
			lut.MaxInputValue = 255;

			Assert.AreEqual(lut.WindowWidth, 24);
			Assert.AreEqual(lut.WindowCenter, 12);
		}
        /// <summary>
        /// Creates a packed overlay data object from the contents of this overlay plane.
        /// </summary>
        /// <param name="bigEndianWords">A value indciating if the packed overlay data should be encoded as 16-bit words with big endian byte ordering.</param>
        /// <returns>A packed overlay data object.</returns>
        public OverlayData CreateOverlayData(bool bigEndianWords)
        {
            if (_overlayGraphic == null)
            {
                return(null);
            }

            GrayscalePixelData pixelData = _overlayGraphic.PixelData;

            return(OverlayData.CreateOverlayData(
                       pixelData.Rows, pixelData.Columns,
                       pixelData.BitsStored,
                       pixelData.BitsAllocated,
                       pixelData.HighBit,
                       bigEndianWords,
                       pixelData.Raw));
        }
        public void TestSimple()
        {
            byte[] data = new byte[25];
            for (byte x = 0; x < 25; ++x)
            {
                data[x] = x;
            }

            GrayscalePixelData             pixelData = new GrayscalePixelData(5, 5, 8, 8, 7, false, data);
            MinMaxPixelCalculatedLinearLut lut       = new MinMaxPixelCalculatedLinearLut(pixelData);

            lut.MinInputValue = 0;
            lut.MaxInputValue = 255;

            Assert.AreEqual(lut.WindowWidth, 24);
            Assert.AreEqual(lut.WindowCenter, 12);
        }
		public void TestWithModalityLut()
		{
			byte[] data = new byte[25];
			for (byte x = 0; x < 25; ++x)
			{
				data[x] = x;
			}

			ModalityLutLinear modalityLut = new ModalityLutLinear(8, true, 1.0, -10);
			GrayscalePixelData pixelData = new GrayscalePixelData(5, 5, 8, 8, 7, false, data);
			MinMaxPixelCalculatedLinearLut lut = new MinMaxPixelCalculatedLinearLut(pixelData, modalityLut);
			lut.MinInputValue = 0;
			lut.MaxInputValue = 255;

			Assert.AreEqual(lut.WindowWidth, 24);
			Assert.AreEqual(lut.WindowCenter, 2);
		}
        public void TestWithModalityLut()
        {
            byte[] data = new byte[25];
            for (byte x = 0; x < 25; ++x)
            {
                data[x] = x;
            }

            ModalityLutLinear              modalityLut = new ModalityLutLinear(8, true, 1.0, -10);
            GrayscalePixelData             pixelData   = new GrayscalePixelData(5, 5, 8, 8, 7, false, data);
            MinMaxPixelCalculatedLinearLut lut         = new MinMaxPixelCalculatedLinearLut(pixelData, modalityLut);

            lut.MinInputValue = 0;
            lut.MaxInputValue = 255;

            Assert.AreEqual(lut.WindowWidth, 24);
            Assert.AreEqual(lut.WindowCenter, 2);
        }
Beispiel #10
0
        public void SetPixelSigned16()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 16;
            int  highBit         = 15;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int x = 3;
            int y = 4;

            // Test the API
            int testValue = -1234;

            pixelDataWrapper.SetPixel(x, y, testValue);
            int actualValue = pixelDataWrapper.GetPixel(x, y);

            Assert.AreEqual(testValue, actualValue);

            // Make sure it works with unsafe code too
            fixed(byte *pPixelData = pixelDataWrapper.Raw)
            {
                short *pShortPixelData = (short *)pPixelData;
                int    i = y * columns + x;

                actualValue = pShortPixelData[i];
            }

            Assert.AreEqual(testValue, actualValue);
        }
        private bool ComputeHistogram(Roi roi)
        {
            // For now, only allow ROIs of grayscale images
            GrayscalePixelData pixelData = roi.PixelData as GrayscalePixelData;

            if (pixelData == null)
            {
                this.Enabled = false;
                return(false);
            }

            int left   = (int)Math.Round(roi.BoundingBox.Left);
            int right  = (int)Math.Round(roi.BoundingBox.Right);
            int top    = (int)Math.Round(roi.BoundingBox.Top);
            int bottom = (int)Math.Round(roi.BoundingBox.Bottom);

            // If any part of the ROI is outside the bounds of the image,
            // don't allow a histogram to be displayed since it's invalid.
            if (left < 0 || left > pixelData.Columns - 1 ||
                right < 0 || right > pixelData.Columns - 1 ||
                top < 0 || top > pixelData.Rows - 1 ||
                bottom < 0 || bottom > pixelData.Rows - 1)
            {
                this.Enabled = false;
                return(false);
            }

            var roiPixelData = new List <double>(roi.GetPixelValues()).ToArray();

            Histogram histogram = new Histogram(
                _minBin, _maxBin, _numBins, roiPixelData);

            _bins      = histogram.Bins;
            _binLabels = histogram.BinLabels;

            NotifyPropertyChanged("MinBin");
            NotifyPropertyChanged("MaxBin");
            NotifyPropertyChanged("NumBins");

            this.Enabled = true;
            return(true);
        }
Beispiel #12
0
        public void SetPixelUnsigned8()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 8;
            int  bitsStored      = 8;
            int  highBit         = 7;
            bool isSigned        = false;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int x = 3;
            int y = 4;

            int testValue = 0xab;

            pixelDataWrapper.SetPixel(x, y, testValue);
            int actualValue = pixelDataWrapper.GetPixel(x, y);

            Assert.AreEqual(testValue, actualValue);

            // Make sure it works with unsafe code too
            fixed(byte *pPixelData = pixelDataWrapper.Raw)
            {
                int i = y * columns + x;

                actualValue = pPixelData[i];
            }

            Assert.AreEqual(testValue, actualValue);
        }
        private static double CalculateMean
        (
            RectangleF roiBoundingBox,
            GrayscalePixelData pixelData,
            IModalityLut modalityLut,
            IsPointInRoiDelegate isPointInRoi
        )
        {
            double sum        = 0;
            int    pixelCount = 0;

            var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox));

            pixelData.ForEachPixel(
                boundingBox.Left,
                boundingBox.Top,
                boundingBox.Right,
                boundingBox.Bottom,
                delegate(int i, int x, int y, int pixelIndex)
            {
                if (isPointInRoi(x, y))
                {
                    ++pixelCount;
                    // Make sure we run the raw pixel through the modality LUT
                    // when doing the calculation. Note that the modality LUT
                    // can be something other than a rescale intercept, so we can't
                    // just run the mean through the LUT.
                    int storedValue  = pixelData.GetPixel(pixelIndex);
                    double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue;
                    sum += realValue;
                }
            });

            if (pixelCount == 0)
            {
                return(0);
            }

            return(sum / pixelCount);
        }
        private static double CalculateStandardDeviation
        (
            double mean,
            RectangleF roiBoundingBox,
            GrayscalePixelData pixelData,
            IModalityLut modalityLut,
            IsPointInRoiDelegate isPointInRoi
        )
        {
            double sum        = 0;
            int    pixelCount = 0;

            var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox));

            pixelData.ForEachPixel(
                boundingBox.Left,
                boundingBox.Top,
                boundingBox.Right,
                boundingBox.Bottom,
                delegate(int i, int x, int y, int pixelIndex)
            {
                if (isPointInRoi(x, y))
                {
                    ++pixelCount;
                    int storedValue  = pixelData.GetPixel(pixelIndex);
                    double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue;

                    double deviation = realValue - mean;
                    sum += deviation * deviation;
                }
            });

            if (pixelCount == 0)
            {
                return(0);
            }

            return(Math.Sqrt(sum / pixelCount));
        }
Beispiel #15
0
        public void SetPixelSigned16Grayscale()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 16;
            int  highBit         = 15;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int x = 3;
            int y = 4;

            // Test the API
            int testValue = -1234;

            pixelDataWrapper.SetPixel(x, y, testValue);
            int actualValue = pixelDataWrapper.GetPixel(x, y);

            Assert.AreEqual(testValue, actualValue);

            int index = y * columns + x;

            actualValue = pixelDataWrapper.GetPixel(index);
            Assert.AreEqual(testValue, actualValue);
        }
Beispiel #16
0
        public void Signed5Bit16BitsAllocated()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 5;
            int  highBit         = 4;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            Signed5Bit(pixelData, pixelDataWrapper);
        }