Ejemplo n.º 1
0
        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);
        }