Example #1
0
        public static unsafe PSF FromBitmap(ImageF image, Point pos)
        {
            PSF thePsf = new PSF();

            ScanLineAnalyzer analyzer = new ScanLineAnalyzer(image, pos.Y, pos.X);
            analyzer.FindBackground();

            thePsf._xmin = analyzer.LeftBackgroundPosition;
            thePsf._xmax = analyzer.RightBackgroundPosition;

            List<double> row = new List<double>();
            for (int x = analyzer.LeftBackgroundPosition; x <= analyzer.RightBackgroundPosition; x++)
            {
                row.Add(image[x, pos.Y]);
            }
            thePsf.iData[0] = row;
            do {
                analyzer.ScanLine--;
                analyzer.Analyze();
                if (analyzer.LeftBackgroundPosition < thePsf.Xmin)
                {
                    thePsf.Xmin = analyzer.LeftBackgroundPosition;
                }
                if (analyzer.RightBackgroundPosition > thePsf.Xmax) {
                    thePsf.Xmax = analyzer.RightBackgroundPosition;
                }

                row = new List<double>();
                for (int x = thePsf.Xmin; x <= thePsf.Xmax; x++)
                {
                    if (x < analyzer.LeftBackgroundPosition || x > analyzer.RightBackgroundPosition)
                    {
                        row.Add(0.0);
                    }
                    else {
                        row.Add(image[x, (int)analyzer.ScanLine]);
                    }
                }
                thePsf.iData.Insert(0, row);
                thePsf._ymin = (int)analyzer.ScanLine;
            } while(!analyzer.IsBackgroundLine);

            analyzer.ScanLine = pos.Y;
            do
            {
                analyzer.ScanLine++;
                analyzer.Analyze();
                if (analyzer.LeftBackgroundPosition < thePsf.Xmin)
                {
                    thePsf.Xmin = analyzer.LeftBackgroundPosition;
                }
                if (analyzer.RightBackgroundPosition > thePsf.Xmax)
                {
                    thePsf.Xmax = analyzer.RightBackgroundPosition;
                }

                row = new List<double>();
                for (int x = thePsf.Xmin; x <= thePsf.Xmax; x++)
                {
                    if (x < analyzer.LeftBackgroundPosition || x > analyzer.RightBackgroundPosition)
                    {
                        row.Add(0.0);
                    }
                    else
                    {
                        row.Add(image[x, (int)analyzer.ScanLine]);
                    }
                }
                thePsf.iData.Add(row);
                thePsf._ymax = (int)analyzer.ScanLine;
            } while (!analyzer.IsBackgroundLine);

            thePsf.Normalize();

            return thePsf;
        }
Example #2
0
        unsafe static public PSF FromBitmap(ImageF image, Point pos)
        {
            PSF thePsf = new PSF();


            ScanLineAnalyzer analyzer = new ScanLineAnalyzer(image, pos.Y, pos.X);

            analyzer.FindBackground();

            thePsf._xmin = analyzer.LeftBackgroundPosition;
            thePsf._xmax = analyzer.RightBackgroundPosition;

            List <double> row = new List <double>();

            for (int x = analyzer.LeftBackgroundPosition; x <= analyzer.RightBackgroundPosition; x++)
            {
                row.Add(image[x, pos.Y]);
            }
            thePsf.iData[0] = row;
            do
            {
                analyzer.ScanLine--;
                analyzer.Analyze();
                if (analyzer.LeftBackgroundPosition < thePsf.Xmin)
                {
                    thePsf.Xmin = analyzer.LeftBackgroundPosition;
                }
                if (analyzer.RightBackgroundPosition > thePsf.Xmax)
                {
                    thePsf.Xmax = analyzer.RightBackgroundPosition;
                }

                row = new List <double>();
                for (int x = thePsf.Xmin; x <= thePsf.Xmax; x++)
                {
                    if (x < analyzer.LeftBackgroundPosition || x > analyzer.RightBackgroundPosition)
                    {
                        row.Add(0.0);
                    }
                    else
                    {
                        row.Add(image[x, (int)analyzer.ScanLine]);
                    }
                }
                thePsf.iData.Insert(0, row);
                thePsf._ymin = (int)analyzer.ScanLine;
            } while(!analyzer.IsBackgroundLine);

            analyzer.ScanLine = pos.Y;
            do
            {
                analyzer.ScanLine++;
                analyzer.Analyze();
                if (analyzer.LeftBackgroundPosition < thePsf.Xmin)
                {
                    thePsf.Xmin = analyzer.LeftBackgroundPosition;
                }
                if (analyzer.RightBackgroundPosition > thePsf.Xmax)
                {
                    thePsf.Xmax = analyzer.RightBackgroundPosition;
                }

                row = new List <double>();
                for (int x = thePsf.Xmin; x <= thePsf.Xmax; x++)
                {
                    if (x < analyzer.LeftBackgroundPosition || x > analyzer.RightBackgroundPosition)
                    {
                        row.Add(0.0);
                    }
                    else
                    {
                        row.Add(image[x, (int)analyzer.ScanLine]);
                    }
                }
                thePsf.iData.Add(row);
                thePsf._ymax = (int)analyzer.ScanLine;
            } while (!analyzer.IsBackgroundLine);

            thePsf.Normalize();

            return(thePsf);
        }