Exemplo n.º 1
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);
                }
            });
        }
Exemplo n.º 2
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);
        }
        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));
        }