Exemple #1
0
        private void DisplayStatResult(string fileName, Dictionary <int, RasterQuickStatResult> results)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(fileName);
            foreach (int bandNo in results.Keys)
            {
                RasterQuickStatResult result = results[bandNo];
                sb.AppendLine("    BandNo " + bandNo.ToString());
                sb.AppendLine("    MinValue:".PadRight(20) + result.MinValue.ToString("0.####"));
                sb.AppendLine("    MaxValue:".PadRight(20) + result.MaxValue.ToString("0.####"));
                sb.AppendLine("    MeanValue:".PadRight(20) + result.MeanValue.ToString("0.####"));
                sb.AppendLine("    Histogram,Bin=".PadRight(20) + result.HistogramResult.Bin.ToString());
                HistogramResult histResult = result.HistogramResult;
                int             buckets    = histResult.ActualBuckets;
                sb.AppendLine("DN".PadLeft(15) + "Count(Npts)".PadLeft(15) + "Total Count".PadLeft(15) + "Percent".PadLeft(15) + "Acc Percent".PadLeft(15));
                double minValue   = result.MinValue;
                double bin        = histResult.Bin;
                long   accCount   = 0;
                double percent    = 0;
                double accPercent = 0;
                for (int i = 0; i < buckets; i++)
                {
                    accCount   += histResult.Items[i];
                    percent     = 100 * histResult.Items[i] / (float)histResult.PixelCount;
                    accPercent += percent;
                    string sLine = (minValue + i * bin).ToString().PadLeft(15) +
                                   histResult.Items[i].ToString().PadLeft(15) +
                                   accCount.ToString().PadLeft(15) +
                                   percent.ToString("0.####").PadLeft(15) +
                                   accPercent.ToString("0.####").PadLeft(15);
                    sb.AppendLine(sLine);
                }
            }
            richTextBox1.Text = sb.ToString();
        }
Exemple #2
0
        /// <summary>
        /// Vertical histogram of an image.
        /// </summary>
        /// <param name="bmp">the bitmap to be processed.</param>
        /// <param name="showDiagnostics">if true, draws an overlay on the image.</param>
        /// <param name="diagnosticsColor">the color of the overlay.</param>
        /// <returns>a histogramResult representing the vertical histogram.</returns>
        private static HistogramResult VerticalHistogram(Bitmap bmp, bool showDiagnostics, Color diagnosticsColor)
        {
            // Create the return value
            var histResult = new float[bmp.Width];

            var vertSum = new float[bmp.Width];

            // Start the max value at zero
            float maxValue = 0;

            // Start the min value at the absolute maximum
            float minValue = 255;

            // GDI+ still lies to us - the return format is BGR, NOT RGB.
            var bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            var stride = bmData.Stride;
            var scan0  = bmData.Scan0;

            unsafe
            {
                var p = (byte *)(void *)scan0;

                var nOffset = stride - (bmp.Width * 3);
                var nWidth  = bmp.Width * 3;

                for (var y = 0; y < bmp.Height; ++y)
                {
                    for (var x = 0; x < bmp.Width; ++x)
                    {
                        // Add up all the pixel values vertically (average the R,G,B channels)
                        vertSum[x] += (p[0] + (p + 1)[0] + (p + 2)[0]) / 3;

                        p += 3;
                    }

                    p += nOffset;
                }
            }

            bmp.UnlockBits(bmData);

            // Now get the average of the row by dividing the pixel by num pixels
            for (var i = 0; i < bmp.Width; i++)
            {
                histResult[i] = vertSum[i] / bmp.Height;

                // Save the max value for later
                if (histResult[i] > maxValue)
                {
                    maxValue = histResult[i];
                }

                // Save the min value for later
                if (histResult[i] < minValue)
                {
                    minValue = histResult[i];
                }
            }

            // Use GDI+ to draw a lines up the image showing each lines average
            if (showDiagnostics)
            {
                // Set the alpha of the overlay to half transparency
                var alpha = (int)255 / 2;
                var p     = new Pen(Color.FromArgb(alpha, diagnosticsColor));

                // Get the graphics to draw on
                Graphics g;
                g = Graphics.FromImage(bmp);
                for (var i = 0; i < bmp.Width; ++i)
                {
                    // Normalize the drawn histogram to the height of the image
                    var drawLength = (int)(histResult[i] * (bmp.Height / maxValue));
                    g.DrawLine(p, i, bmp.Height, i, bmp.Height - (int)drawLength);
                }

                p.Dispose();
                g.Dispose();
            }

            var retVal = new HistogramResult
            {
                Histogram = histResult,
                Max       = maxValue,
                Min       = minValue
            };

            return(retVal);
        }
 public static AggregateKey CreateAggregateKey(AttributeTransformationModel iom,
                                               SingleDimensionAggregateParameters aggParameters, HistogramResult histogramResult, int brushIndex)
 {
     aggParameters.Dimension = iom.AttributeModel.Index;
     return(new AggregateKey
     {
         AggregateParameterIndex = histogramResult.GetAggregateParametersIndex(aggParameters),
         BrushIndex = brushIndex
     });
 }
Exemple #4
0
 public void Add(HistogramResult statistics)
 {
     _results.Add(statistics);
 }
 public static AggregateKey CreateAggregateKey(AttributeTransformationModel iom, HistogramResult histogramResult,
                                               int brushIndex)
 {
     return(new AggregateKey
     {
         AggregateParameterIndex = histogramResult.GetAggregateParametersIndex(createAggregateParameters(iom)),
         BrushIndex = brushIndex
     });
 }