예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        public void TestLSD()
        {
            string[] input = new string[]
            {
                "4PGC938",
                "2IYE230",
                "3CIO720",
                "1ICK750",
                "1OHV845",
                "4JZY524",
                "1ICK750",
                "3CIO720",
                "1OHV845",
                "1OHV845",
                "2RLA629",
                "2RLA629",
                "3ATW723",
            };

            LSD.Sort(input, 7);

            Assert.True(input[0] == "1ICK750");
            Assert.True(input[1] == "1ICK750");
            Assert.True(input[2] == "1OHV845");
            Assert.True(input[3] == "1OHV845");
            Assert.True(input[4] == "1OHV845");
            Assert.True(input[5] == "2IYE230");
            Assert.True(input[6] == "2RLA629");
            Assert.True(input[7] == "2RLA629");
            Assert.True(input[8] == "3ATW723");
            Assert.True(input[9] == "3CIO720");
            Assert.True(input[10] == "3CIO720");
            Assert.True(input[11] == "4JZY524");
            Assert.True(input[12] == "4PGC938");
        }
예제 #4
0
        private static void LSDSort()
        {
            var fileName = "LSD.txt";
            var strings  = ReadFile(fileName);

            PrintArray(strings);
            StdOut.Println("After sorting.....");
            LSD.Sort(ref strings, strings[0].Length);
            PrintArray(strings);
        }
예제 #5
0
        public void Run()
        {
            Console.WriteLine("Choose file:");   // Prompt
            Console.WriteLine("1 - words3.txt"); // Prompt
            Console.WriteLine("2 - pi.txt");     // Prompt
            Console.WriteLine("or quit");        // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "words3.txt";
                break;

            case "2":
                fieName = "pi.txt";
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in     = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();

            var n = content.Length;
            // check that strings have fixed length
            var w = content[0].Length;

            for (var i = 0; i < n; i++)
            {
                if (content[i].Length == w)
                {
                    continue;
                }
                Console.WriteLine("Strings must have fixed length");
                Console.ReadLine();
                return;
            }

            LSD.Sort(content, w);

            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(content[i]);
            }

            Console.ReadLine();
        }
예제 #6
0
        public void Test()
        {
            var words = "bed bug dad yes zoo now for tip ilk dim tag jot sob nob sky hut men egg few jay owl joy rap gig wee was wad fee tap tar dug jam all bad yet".Split(' ');

            LSD.Sort(words);

            for (var i = 1; i < words.Length; ++i)
            {
                Assert.True(words[i - 1].CompareTo(words[i]) <= 0);
            }
        }
예제 #7
0
    /**/ public static void main(string[] strarr)
    {
        string      text        = java.lang.String.instancehelper_replaceAll(StdIn.readAll(), "\\s+", " ");
        SuffixArray suffixArray = new SuffixArray(text);
        int         num         = suffixArray.length();
        string      text2       = "";

        for (int i = 1; i < num; i++)
        {
            int num2 = suffixArray.lcp(i);
            if (num2 > java.lang.String.instancehelper_length(text2))
            {
                text2 = java.lang.String.instancehelper_substring(text, suffixArray.index(i), suffixArray.index(i) + num2);
            }
        }
        StdOut.println(new StringBuilder().append("'").append(text2).append("'").toString());
    }
}



public class LSD
{
//[Modifiers(Modifiers.Static | Modifiers.Final | Modifiers.Synthetic)]
    internal static bool s_assertionsDisabled;



    public static void sort(string[] strarr, int i)
    {
        int num  = strarr.Length;
        int num2 = 256;

        string[] array = new string[num];
        for (int j = i - 1; j >= 0; j += -1)
        {
            int[] array2 = new int[num2 + 1];
            for (int k = 0; k < num; k++)
            {
                int[] arg_3D_0 = array2;
                int   num3     = (int)(java.lang.String.instancehelper_charAt(strarr[k], j) + '\u0001');
                int[] array3   = arg_3D_0;
                array3[num3]++;
            }
            for (int k = 0; k < num2; k++)
            {
                int[] arg_63_0 = array2;
                int   num3     = k + 1;
                int[] array3   = arg_63_0;
                array3[num3] += array2[k];
            }
            for (int k = 0; k < num; k++)
            {
                string[] arg_B4_0 = array;
                int[]    arg_94_0 = array2;
                int      num3     = (int)java.lang.String.instancehelper_charAt(strarr[k], j);
                int[]    array3   = arg_94_0;
                int[]    arg_A3_0 = array3;
                int      arg_A1_0 = num3;
                num3 = array3[num3];
                int num4 = arg_A1_0;
                array3 = arg_A3_0;
                int arg_B4_1 = num3;
                array3[num4]       = num3 + 1;
                arg_B4_0[arg_B4_1] = strarr[k];
            }
            for (int k = 0; k < num; k++)
            {
                strarr[k] = array[k];
            }
        }
    }

    public LSD()
    {
    }

    /**/ public static void main(string[] strarr)
    {
        string[] array = StdIn.readAllStrings();
        int      num   = array.Length;
        int      num2  = java.lang.String.instancehelper_length(array[0]);

        for (int i = 0; i < num; i++)
        {
            if (!LSD.s_assertionsDisabled && java.lang.String.instancehelper_length(array[i]) != num2)
            {
                object arg_34_0 = "Strings must have fixed length";

                throw new AssertionError(arg_34_0);
            }
        }
        LSD.sort(array, num2);
        for (int i = 0; i < num; i++)
        {
            StdOut.println(array[i]);
        }
    }