Beispiel #1
0
        public void MRELBP_QuarterArray_EqualsPythonReference()
        {
            //testImg.New("Quarters", new int[] { 14, 14 });
            //var param = new Parameters()
            //{
            //    LargeRadius = 2,
            //    Radius = 1
            //};
            testImg.New("Quarters", new int[] { 28, 28 });
            var param = new Parameters();

            LBPApplication.PipelineMRELBP(testImg.Image.ToDouble(), param, // MRELBP pipeline
                                          out double[,] LBPIL, out double[,] LBPIS, out double[,] LBPIR, out int[] histL, out int[] histS, out int[] histR, out int[] histCenter);

            float[,] refIS = new float[6, 6]
            {
                { 3, 4, 4, 5, 5, 6 },
                { 4, 3, 3, 5, 5, 2 },
                { 4, 3, 3, 5, 5, 2 },
                { 6, 3, 3, 5, 5, 4 },
                { 6, 3, 3, 5, 5, 4 },
                { 2, 3, 3, 4, 4, 5 }
            };
            float[,] refIR = new float[6, 6]
            {
                { 8, 8, 8, 8, 8, 9 },
                { 8, 8, 8, 8, 8, 5 },
                { 8, 8, 8, 8, 7, 5 },
                { 8, 8, 8, 8, 7, 9 },
                { 8, 8, 7, 7, 7, 9 },
                { 7, 6, 5, 9, 9, 9 }
            };
            float[,] refIL = new float[6, 6]
            {
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 }
            };
            int[] refSHist = new int[] { 0, 0, 3, 11, 8, 11, 3, 0, 0, 0 };
            int[] refRHist = new int[] { 0, 0, 0, 0, 0, 3, 1, 6, 20, 6 };
            int[] refLHist = new int[] { 0, 0, 0, 18, 0, 18, 0, 0, 0, 0 };
            Assert.Equal(refIS.ToDouble(), LBPIS);
            Assert.Equal(refIR.ToDouble(), LBPIR);
            Assert.Equal(refIL.ToDouble(), LBPIL);
            Assert.Equal(refSHist, histS);
            Assert.Equal(refRHist, histR);
            Assert.Equal(refLHist, histL);
        }
Beispiel #2
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 double[,] LBP(double[,] inputImage, Parameters param, out double[,] LBPIL, out double[,] LBPIS, out double[,] LBPIR, string zone)
        {
            // LBP calculation
            LBPApplication.PipelineMRELBP(inputImage, param,
                                          out LBPIL, out LBPIS, out 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)));

            // Normalize
            double[] fScaled = Elementwise.Divide(f, f.Sum());
            double[,] features = new double[0, 0];

            return(Matrix.Concatenate(features, fScaled));
        }
Beispiel #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));;
        }
Beispiel #4
0
        public void CalculateImage_QuarterArray_EqualsReferenceMappedImages()
        {
            testImg.New("Quarters", new int[] { 28, 28 });
            int w = testImg.Image.GetLength(0), l = testImg.Image.GetLength(1);
            var param = new Parameters();


            LBPApplication.PipelineMRELBP(testImg.Image.ToDouble(), param, // MRELBP pipeline
                                          out double[,] LBPIL, out double[,] LBPIS, out double[,] LBPIR, out int[] histL, out int[] histS, out int[] histR, out int[] histCenter);
            testImg.New("Quarters", new int[] { 12, 12 });
            LBPApplication.PipelineLBP(testImg.Image.ToDouble(), param, // LBP pipeline
                                       out double[,] LBPresult, out int[] LBPhistogram);

            float[,] refLBP = new float[6, 6] // Here, actually columns are written out as rows
            {
                { 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 }
            };
            float[,] refIS = new float[6, 6]
            {
                { 3, 4, 4, 5, 5, 6 },
                { 4, 3, 3, 5, 5, 2 },
                { 4, 3, 3, 5, 5, 2 },
                { 6, 3, 3, 5, 5, 4 },
                { 6, 3, 3, 5, 5, 4 },
                { 2, 3, 3, 4, 4, 5 }
            };
            float[,] refIR = new float[6, 6]
            {
                { 8, 8, 8, 8, 8, 9 },
                { 8, 8, 8, 8, 8, 5 },
                { 8, 8, 8, 8, 7, 5 },
                { 8, 8, 8, 8, 7, 9 },
                { 8, 8, 7, 7, 7, 9 },
                { 7, 6, 5, 9, 9, 9 }
            };
            float[,] refIL = new float[6, 6]
            {
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 },
                { 3, 3, 3, 5, 5, 5 }
            };
            int[] refLBPHist = new int[] { 0, 0, 0, 9, 0, 9, 9, 0, 9, 0 };
            int[] refSHist   = new int[] { 0, 0, 3, 11, 8, 11, 3, 0, 0, 0 };
            int[] refRHist   = new int[] { 0, 0, 0, 0, 0, 3, 1, 6, 20, 6 };
            int[] refLHist   = new int[] { 0, 0, 0, 18, 0, 18, 0, 0, 0, 0 };
            Assert.Equal(refLBP.ToDouble(), LBPresult);
            Assert.Equal(refIS.ToDouble(), LBPIS);
            Assert.Equal(refIR.ToDouble(), LBPIR);
            Assert.Equal(refIL.ToDouble(), LBPIL);
            Assert.Equal(refLBPHist, LBPhistogram);
            Assert.Equal(refSHist, histS);
            Assert.Equal(refRHist, histR);
            Assert.Equal(refLHist, histL);
        }