Ejemplo n.º 1
0
        private Bitmap DoLSD(OneEye eye)
        {
            image <int> img = new image <int>();   // 隨更new,只要不是null, 在LSD裏會重建

            LSD.doubleTupleList tupleList = LSD.lsd_scale_region(eye.imgDouble, 0.8, ref img);
            int w = (int)img.width;
            int h = (int)img.height;

            try
            {
                Bitmap     lineSegment = new Bitmap(w, h, PixelFormat.Format24bppRgb);
                BitmapData dataOut     = lineSegment.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                unsafe
                {
                    byte *pOut = (byte *)(dataOut.Scan0.ToPointer());
                    for (int y = 0; y < h; y++)
                    {
                        for (int x = 0; x < w; x++)
                        {
                            byte gr = (img.data[x, y] == 0) ? (byte)0 : (byte)200;
                            pOut[0] = pOut[1] = pOut[2] = gr;
                            pOut   += 3;
                        }
                        pOut += dataOut.Stride - w * 3;
                    }
                }
                lineSegment.UnlockBits(dataOut);
                lineSegment.Save("LSD.bmp");
                return(lineSegment);
            }
            catch (Exception ex) { Message("Make LSD:" + ex.Message); }
            return(null);
        }
Ejemplo n.º 2
0
        private Bitmap DoGaussian(OneEye eye)
        {
            LSD.doubleTupleList outList = LSD.doubleTupleList.newTupleList(7);
            image <double>      modgrad;
            List <coord>        list_p;
            // angle tolerance
            double quant  = 2.0;      // Bound to the quantization error on the gradient norm.
            double ang_th = 22.5;     // Gradient angle tolerance in degrees.
            int    n_bins = 1024;     // Number of bins in pseudo-ordering of gradient modulus.
            double prec   = Math.PI * ang_th / 180.0;
            double p      = ang_th / 180.0;
            double rho    = quant / Math.Sin(prec);
            //LSD.image<Double> scaled_image=LSD.gaussian_sampler(eye.imgDouble, 0.8, 0.6);
            image <Double> scaled_image = eye.imgDouble;
            image <Double> angles       = LSD.ll_angle(scaled_image, rho, (uint)n_bins, out modgrad, out list_p);
            image <double> img          = angles;
            int            w            = (int)img.width;
            int            h            = (int)img.height;

            //double normal = double.Epsilon;
            //for (int y = 0; y < h; y++)
            //    for (int x = 0; x < w; x++)
            //    {
            //        if (img.data[x, y] == LSD.NOTDEF) continue;
            //        if (normal < Math.Abs(img.data[x, y])) normal = Math.Abs(img.data[x, y]);
            //    }
            //normal /= 255;
            try
            {
                Bitmap     gaussian = new Bitmap(w, h, PixelFormat.Format24bppRgb);
                BitmapData dataOut  = gaussian.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                unsafe
                {
                    byte *pOut = (byte *)(dataOut.Scan0.ToPointer());
                    for (int y = 0; y < h; y++)
                    {
                        for (int x = 0; x < w; x++)
                        {
                            byte gr;
                            if (img.data[x, y] == LSD.NOTDEF)
                            {
                                gr = 0;
                            }
                            else
                            {
                                gr = 200;
                            }
                            pOut[0] = pOut[1] = pOut[2] = (byte)gr;
                            pOut   += 3;
                        }
                        pOut += dataOut.Stride - w * 3;
                    }
                }
                gaussian.UnlockBits(dataOut);
                gaussian.Save("gaussian.bmp");
                return(gaussian);
            }
            catch (Exception ex) { Message("Make Gaussian:" + ex.Message); }
            return(null);
        }