Exemplo n.º 1
0
        public void Stand_Evenkernel_OutputsError()
        {
            testImg.New("Quarters", new int[] { 6, 6 });
            var stand = new LocalStandardization()
            {
                w1 = 2
            };

            double[,] image = testImg.Image.ToDouble();

            Exception ex = Assert.Throws <Exception>(
                delegate { stand.Standardize(ref image, "Reflect"); });

            Assert.Equal("Kernel width is not odd!", ex.Message);
        }
Exemplo n.º 2
0
        public void Stand_SmallKernelsOverride_Equalsreference()
        {
            testImg.New("Quarters", new int[] { 6, 6 });
            var stand = new LocalStandardization(5, 3, 5, 1);

            double[,] image = testImg.Image.ToDouble();
            stand.Standardize(ref image, "Reflect");

            double[,] refimage = new double[6, 6]
            {
                { 0, -0.713520621472151, -1.0860460420492704, 1.1431629051894177, 0.84311553277412787, -2.2355540831313907E-15 },
                { -0.51110271561126808, -0.858138042569251, -1.2191098967853371, 0.88522909002589645, 0.50327268512720325, -0.79096598944498153 },
                { -0.90778462979852093, -1.1519031239765429, -1.4403470961301064, 0.52956642547784116, -0.023010004835671567, -1.0641502996862582 },
                { 1.0641502996862577, 0.023010004835671564, -0.52956642547784061, 1.4403470961301061, 1.1519031239765429, 0.90778462979852015 },
                { 0.79096598944498064, -0.50327268512720447, -0.88522909002589667, 1.2191098967853371, 0.85813804256925119, 0.51110271561126719 },
                { 0, -0.84311553277412821, -1.1431629051894172, 1.0860460420492706, 0.71352062147215034, 0 }
            };
            Assert.Equal(image, refimage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates LBP features using LBPLibrary Nuget package.
        /// Takes grayscale image as input.
        /// Currently software inputs sum of mean and standard images of surface VOI.
        /// </summary>
        /// <returns>Feature array.</returns>
        public static int[,] LBP(double[,] inputImage)
        {
            // Get default parameters
            Parameters param = new Parameters();

            // Grayscale standardization
            var standrd = new LocalStandardization(param.W_stand[0], param.W_stand[1], param.W_stand[2], param.W_stand[3]);

            standrd.Standardize(ref inputImage, param.Method); // standardize given image

            // LBP calculation
            LBPApplication.PipelineMRELBP(inputImage, param,
                                          out double[,] LBPIL, out double[,] LBPIS, out double[,] LBPIR, out int[] histL, out int[] histS, out int[] histR, out int[] histCenter);

            // Concatenate histograms
            int[] f = Matrix.Concatenate(histCenter, Matrix.Concatenate(histL, Matrix.Concatenate(histS, histR)));
            int[,] features = new int[0, 0];

            return(Matrix.Concatenate(features, f));;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Grading pipeline. Outputs the grades for each VOI as a string and results can be viewed from external grading window.
        /// </summary>
        /// <param name="zone">Name of the zone to be graded.</param>
        /// <param name="sample">Sample name.</param>
        /// <param name="mean">Mean image from the zone's VOI along depth-axis.</param>
        /// <param name="sd">Standard deviation image from the zone's VOI along depth-axis.</param>
        /// <param name="model_path">Path to grading model. Binary data file including values for PCA and regression.</param>
        /// <param name="param_path">Path to LBP parameters.</param>
        /// <returns></returns>
        public static string grade_voi(string zone, string sample, double[,] mean, double[,] sd, string model_path, string param_path)
        {
            // Initialize Grading form
            var grading = new GradingForm(); grading.Show();

            grading.Text = zone;

            // Load grading model
            string path = LoadModel(out Model mod, out Parameters param, model_path, param_path);

            // Sum mean and std images
            var meansd = Elementwise.Add(mean, sd);

            // Grayscale standardization
            var standrd = new LocalStandardization(param.W_stand[0], param.W_stand[1], param.W_stand[2], param.W_stand[3]);

            standrd.Standardize(ref meansd, param.Method); // standardize given image

            // Replace NaN values from standardized image
            bool nans = false;
            var  mu   = LBPLibrary.Functions.Mean(meansd);

            Parallel.For(0, meansd.GetLength(0), i =>
            {
                Parallel.For(0, meansd.GetLength(1), j =>
                {
                    if (double.IsNaN(meansd[i, j]))
                    {
                        meansd[i, j] = 0;
                        nans         = true;
                    }
                });
            });
            if (nans)
            {
                Console.WriteLine("Input includes NaN values!");
            }

            // Show images to user
            grading.UpdateModel(zone); grading.Show();
            grading.UpdateMean(
                DataTypes.DoubleToBitmap(mean),
                DataTypes.DoubleToBitmap(sd),
                DataTypes.DoubleToBitmap(meansd));
            grading.Show();

            //Get LBP features
            grading.UpdateParameters(param);
            double[,] features = LBP(meansd, param, out double[,] LBPIL, out double[,] LBPIS, out double[,] LBPIR, zone);

            grading.UpdateLBP(
                DataTypes.DoubleToBitmap(LBPIL),
                DataTypes.DoubleToBitmap(LBPIS),
                DataTypes.DoubleToBitmap(LBPIR));
            grading.Show();

            //Get grade
            // Calculate PCA and regression
            bool degenerated = FeaturesToGrade(features, mod, path, sample, out string grade);

            Console.WriteLine(grade);
            grading.UpdateGrade(grade, degenerated); grading.Show();
            SaveResult(grade, path, sample);

            return(grade);
        }