Exemplo n.º 1
0
        /// <summary>
        /// Measures the sharpness.
        /// </summary>
        /// <param name="currentImage">The current image.</param>
        /// <param name="ScaleVal">The scale val.</param>
        /// <returns></returns>
        public HTuple MeasureSharpness(HImage currentImage, HTuple ScaleVal)
        {
            HTuple hv_Sharpness = new HTuple();

            try
            {
                if (currentImage.CountChannels() == 3)
                {
                    currentImage = currentImage.Rgb1ToGray();
                }
                string hv_Type   = null;
                int    hv_Width  = 0;
                int    hv_Height = 0;

                IntPtr imagePtr = currentImage.GetImagePointer1(out hv_Type, out hv_Width, out hv_Height);

                HImage ho_ImageZoomed      = new HImage();
                HImage ho_ImageFFT         = new HImage();
                HImage ho_ImageCorrelation = new HImage();
                HImage ho_ImageFFTInv      = new HImage();


                HTuple hv_ZoomedWidth;
                HTuple hv_ZoomedHeight;

                HTuple IRow = new HTuple(4);

                HTuple ICol = new HTuple(4);
                HTuple hv_SumCorrelation;

                ho_ImageZoomed = currentImage.ZoomImageFactor(ScaleVal, ScaleVal, "constant");
                ho_ImageZoomed.GetImageSize(out hv_ZoomedWidth, out hv_ZoomedHeight);
                ho_ImageFFT         = ho_ImageZoomed.RftGeneric("to_freq", "none", "complex", hv_ZoomedWidth);
                ho_ImageCorrelation = ho_ImageFFT.CorrelationFft(ho_ImageFFT);
                ho_ImageFFTInv      = ho_ImageCorrelation.RftGeneric("from_freq", "n", "real", hv_ZoomedWidth);

                IRow[0] = 0;
                IRow[1] = 1;
                IRow[2] = hv_ZoomedHeight - 1;
                IRow[3] = hv_ZoomedHeight - 2;


                ICol[0] = 1;
                ICol[1] = 0;
                ICol[2] = hv_ZoomedWidth - 2;
                ICol[3] = hv_ZoomedWidth - 1;

                hv_SumCorrelation = ho_ImageFFTInv.GetGrayval(IRow, ICol);

                HTuple hv_Mean;
                HTuple hv_Deviation;

                hv_Mean = ho_ImageZoomed.Intensity(ho_ImageZoomed, out hv_Deviation);

                HTuple hv_Blurness;

                hv_Blurness = ((hv_SumCorrelation / (hv_ZoomedWidth * hv_ZoomedHeight)) - (hv_Mean * hv_Mean)) / (hv_Deviation * hv_Deviation);

                hv_Sharpness = 1000.0 - ((hv_Blurness.TupleMin()) * 1000.0);

                hv_Sharpness = hv_Sharpness * 100;
                hv_Sharpness = hv_Sharpness.TupleRound();
                hv_Sharpness = hv_Sharpness.TupleReal();
                hv_Sharpness = hv_Sharpness / 100;
            }
            catch (Exception ex)
            {
                SetFocusStatusMessage(ex.Message, Color.Pink);
                //this.lblFocusStatus.Text = ex.Message;
                //this.lblFocusStatus.BackColor = Color.Pink;
            }

            return(hv_Sharpness);
        }