Example #1
0
        /// <summary>
        /// Loads default model weights.
        /// Default model file is on project folder named "weights.dat"
        /// </summary>
        /// <param name="mod">Model containing grading variables</param>
        /// <param name="param">Excel containing LBP parameters</param>
        /// <param name="model_path">Path to model</param>
        /// <param name="param_path">Path to parameters</param>
        /// <returns>Grading model and LBP parameters</returns>
        public static string LoadModel(out Model mod, out Parameters param, string model_path, string param_path)
        {
            // Path to files
            string path =
                new DirectoryInfo(Directory.GetCurrentDirectory()) // Get current directory
                .Parent.Parent.Parent.Parent.FullName;             // Move to correct location and add file name

            // Read weights from .dat file
            var reader = new BinaryWriterApp(path + model_path);

            try
            {
                reader.ReadWeights();
            }
            catch (Exception)
            {
                throw new Exception("Could not find weights.dat! Check that default model is on correct folder.");
            }

            // Set model variables
            mod                = new Model();
            mod.nComp          = reader.ncomp;
            mod.eigenVectors   = reader.eigenVectors;
            mod.singularValues = reader.singularValues;
            mod.weights        = reader.weights;
            mod.weightsLog     = reader.weightsLog;
            mod.intercept      = reader.intercept;
            mod.interceptLog   = reader.interceptLog;
            mod.mean           = reader.mean;


            // Load parameters from .csv
            var paramList = DataTypes.ReadCSV(path + param_path).ToInt32();
            var paramFlat = new int[paramList.Length];

            for (int i = 0; i < paramList.Length; i++)
            {
                paramFlat[i] = paramList[0, i];
            }

            // Set parameters
            param = new Parameters()
            {
                W_stand     = new int[] { paramFlat[0], paramFlat[1], paramFlat[2], paramFlat[3] },
                Neighbours  = paramFlat[4],
                LargeRadius = paramFlat[5],
                Radius      = paramFlat[6],
                W_c         = paramFlat[7],
                W_r         = new int[] { paramFlat[8], paramFlat[9] }
            };

            return(path);
        }
Example #2
0
        public void RunLBPCalculateBatch_LBP_dat_EqualsReference()
        {
            var runlbp = new RunLBP(load + @"\Test1", save + @"\Test1");

            Directory.CreateDirectory(@"C:\temp\test\load\Test1");
            Directory.CreateDirectory(@"C:\temp\test\save\Test1");

            runlbp.param.Mre       = false;
            runlbp.param.Scale     = false;
            runlbp.param.W_stand   = new int[] { 5, 3, 2, 1 };
            runlbp.param.ImageType = ".dat";
            // save images
            testImg.New("Quarters", new int[] { 12, 12 });
            var bin = new BinaryWriterApp()
            {
                filename = load + @"\Test1\Test4.dat"
            };

            bin.SaveBinary(testImg.Image.ToDouble());
            bin.filename = load + @"\Test1\Test5.dat";
            bin.SaveBinary(testImg.Image.ToDouble());
            bin.filename = load + @"\Test1\Test6.dat";
            bin.SaveBinary(testImg.Image.ToDouble());

            runlbp.CalculateBatch();
            float[,] result1 = Functions.Load(save + @"\Test1\Test4_LBP.png");
            float[,] result2 = Functions.Load(save + @"\Test1\Test5_LBP.png");
            float[,] result3 = Functions.Load(save + @"\Test1\Test6_LBP.png");

            float[,] refIS = new float[6, 6]
            {
                { 8, 8, 8, 5, 5, 5 },
                { 8, 8, 8, 5, 5, 6 },
                { 8, 8, 8, 5, 5, 6 },
                { 5, 6, 6, 3, 3, 3 },
                { 5, 6, 6, 3, 3, 3 },
                { 6, 6, 6, 3, 3, 3 }
            };
            Assert.Equal(refIS, result1);
            Assert.Equal(refIS, result2);
            Assert.Equal(refIS, result3);
        }
Example #3
0
        /// <summary>
        /// Loads default model weights.
        /// Default model file is on project folder named "weights.dat"
        /// </summary>
        /// <param name="mod">Model containing all variables</param>
        /// <returns>State of loading model</returns>
        public static string LoadModel(ref Model mod)
        {
            // Path to model (weights.dat)
            string filename =
                new DirectoryInfo(Directory.GetCurrentDirectory())               // Get current directory
                .Parent.Parent.Parent.Parent.FullName + @"\Default\weights.dat"; // Move to correct location and add file name

            // Read weights from .dat file
            var reader = new BinaryWriterApp(filename);

            reader.ReadWeights();

            // Update model variables
            mod.nComp          = reader.ncomp;
            mod.eigenVectors   = reader.eigenVectors;
            mod.singularValues = reader.singularValues;
            mod.weights        = reader.weights;

            return("Model loaded");
        }
Example #4
0
        public void RunLBPCalculateSingle_MRE_dat_EqualsReference()
        {
            var runlbp = new RunLBP(load + @"\Test6\Test1.dat", save + @"\Test6");

            Directory.CreateDirectory(@"C:\temp\test\load\Test6");
            Directory.CreateDirectory(@"C:\temp\test\save\Test6");

            testImg.New("Quarters", new int[] { 28, 28 });
            var bin = new BinaryWriterApp()
            {
                filename = load + @"\Test6\Test1.dat"
            };

            bin.SaveBinary(testImg.Image.ToDouble());
            runlbp.param.Mre       = true;
            runlbp.param.Scale     = false;
            runlbp.param.W_stand   = new int[] { 5, 3, 2, 1 };
            runlbp.param.ImageType = ".dat";

            runlbp.CalculateSingle();
            bin.filename    = save + @"\Test6\features.dat";
            float[,] result = Functions.Load(save + @"\Test6\Test1_LBPIS.png");
            bin.ReadLBPFeatures("uint32");
            int[,] features = bin.features;

            float[,] refIS = new float[6, 6]
            {
                { 9, 7, 6, 6, 6, 1 },
                { 8, 1, 9, 6, 6, 1 },
                { 6, 2, 3, 6, 3, 1 },
                { 7, 5, 2, 5, 6, 2 },
                { 7, 2, 2, 9, 7, 8 },
                { 7, 2, 2, 2, 1, 9 }
            };
            Assert.Equal(refIS, result);
        }