public void GetBinMapping_Testmap_EqualsReferenceMapping() { for (int n = 8; n < 17; n += 4) { var param = new Parameters() { Neighbours = n }; var app = new LBPApplication() { Param = param }; app.GetMapping(); // GetMapping function // Loop for mapping (reference) int[] mappingTable = new int[(int)Math.Pow(2, param.Neighbours)]; for (int i = 0; i < Math.Pow(2, param.Neighbours); i++) { // Binary and shifted binary strings (rotation invariance) string binary = Convert.ToString(i, 2).PadLeft(param.Neighbours, '0'); string binaryShift = binary.Substring(1, binary.Length - 1) + binary.Substring(0, 1); // Convert strings to double arrays int[] binList = new int[binary.Length]; int[] binShiftList = new int[binaryShift.Length]; for (int ii = 0; ii < binary.Length; ii++) { binList[ii] = Convert.ToInt32(binary.Substring(ii, 1)); binShiftList[ii] = Convert.ToInt32(binaryShift.Substring(ii, 1)); } // Calculate sum of different bits (uniformity) int sum = 0; for (int ii = 0; ii < binList.Length; ii++) { if (binList[ii] != binShiftList[ii]) { sum++; } } // Binning if (sum <= 2) { int c = 0; for (int ii = 0; ii < binary.Length; ii++) { c = c + (int)binList[ii]; } mappingTable[i] = c; } else { mappingTable[i] = param.Neighbours + 1; } } Assert.Equal(mappingTable, app.mappingTable); } }
public void GetHistogram_ScaledQuarterArray_FullHistogramBin() { testImg.New("Ones"); int w = testImg.Image.GetLength(0), l = testImg.Image.GetLength(1); var param = new Parameters() { Neighbours = 8 }; LBPApplication app = new LBPApplication { Image = testImg.Image.ToDouble(), LBPILMapped = testImg.Image.ToDouble(), LBPIRMapped = testImg.Image.Add(1).ToDouble(), LBPISMapped = testImg.Image.Add(2).ToDouble(), Param = param, xSize = w, ySize = l, MRE = false }; app.GetMapping(); // Get Mapping table app.GetHistogram(); // Get Histograms int[] histLBP = app.histS; app.LBPISMapped = testImg.Image.Add(3).ToDouble(); app.MRE = true; app.GetHistogram(); Assert.Equal(150, histLBP[3]); Assert.Equal(150, app.histL[1]); Assert.Equal(150, app.histR[2]); Assert.Equal(150, app.histS[4]); }
public void GetMapping_ScaledQuarterArray_EqualsReferenceArray() { testImg.New("Quarters"); testImg.Image = testImg.Image.Multiply(256 / 4).Subtract(1); // Scale to 8-bit range int w = testImg.Image.GetLength(0), l = testImg.Image.GetLength(1); var param = new Parameters() { Neighbours = 8 }; LBPApplication app = new LBPApplication { Image = testImg.Image.ToDouble(), Param = param }; app.GetMapping(); // Get Mapping table double[,] mapped = new double[w, l]; for (int i = 0; i < w; i++) // Apply mapping { for (int j = 0; j < l; j++) { mapped[i, j] = app.mappingTable[(int)app.Image[i, j]]; } } testImg.New("Quarters"); // Create reference array with known values float[,] refArray = testImg.Image; for (int i = 0; i < w; i++) { for (int j = 0; j < l; j++) { if (refArray[i, j] == 1) { refArray[i, j] = 6; } if (refArray[i, j] == 2) { refArray[i, j] = 7; } if (refArray[i, j] == 3) { refArray[i, j] = 7; } if (refArray[i, j] == 4) { refArray[i, j] = 8; } } } Assert.Equal(mapped.ToSingle(), refArray); }
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 app = new LBPApplication { Image = testImg.Image.ToDouble(), Param = param, d = param.LargeRadius + (param.W_r[0] - 1) / 2, MRE = false, }; // Result image size app.xSize = w - 2 * app.d; app.ySize = l - 2 * app.d; app.GetMapping(); // GEt mapping table app.CalculateImage(); double[,] mappedLBP = app.LBPISMapped; app.MRE = true; app.FilterImage(); app.CalculateImage(); double[,] refLBP = new double[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 } }; double[,] refIS = new double[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 } }; double[,] refIR = new double[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 } }; double[,] refIL = new double[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 } }; Assert.Equal(refLBP, mappedLBP); Assert.Equal(refIS, app.LBPISMapped); Assert.Equal(refIR, app.LBPIRMapped); Assert.Equal(refIL, app.LBPILMapped); }