diff --git a/src/main/java/org/wlld/MatrixTools/MatrixOperation.java b/src/main/java/org/wlld/MatrixTools/MatrixOperation.java index dff2b67..6b4f15e 100644 --- a/src/main/java/org/wlld/MatrixTools/MatrixOperation.java +++ b/src/main/java/org/wlld/MatrixTools/MatrixOperation.java @@ -93,7 +93,7 @@ public class MatrixOperation { } } - public static double errorNub(Matrix matrix, Matrix avgMatrix, int excNub) throws Exception {//求均方误差 + public static double errorNub(Matrix matrix, Matrix avgMatrix) throws Exception {//求均方误差 int y = matrix.getY(); if (matrix.isRowVector() && avgMatrix.isRowVector() && y == avgMatrix.getY()) { double[] subAll = new double[y]; @@ -103,12 +103,11 @@ public class MatrixOperation { double sub = Math.pow(avg - mySelf, 2); subAll[j] = sub; } - Arrays.sort(subAll); double sigma = 0; - for (int i = 0; i < y - excNub; i++) { + for (int i = 0; i < y; i++) { sigma = sigma + subAll[i]; } - return sigma / (y - excNub); + return sigma / y; } else { throw new Exception("this matrix is not rowVector or length different"); } diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index 83c6a24..f01eab2 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -7,8 +7,6 @@ import org.wlld.imageRecognition.border.Border; import org.wlld.imageRecognition.border.Frame; import org.wlld.imageRecognition.border.FrameBody; import org.wlld.imageRecognition.segmentation.ColorFunction; -import org.wlld.imageRecognition.segmentation.DimensionMapping; -import org.wlld.param.Food; import org.wlld.pso.PSO; import org.wlld.tools.ArithUtil; import org.wlld.tools.Frequency; @@ -100,62 +98,44 @@ public class Convolution extends Frequency { public List getCenterColor(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, - boolean isStudy, int tag) throws Exception { + int sqNub) throws Exception { Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixB = threeChannelMatrix.getMatrixB(); + MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig, true); int maxX = matrixR.getX(); int maxY = matrixR.getY(); ColorFunction colorFunction = new ColorFunction(threeChannelMatrix); int[] minBorder = new int[]{0, 0}; - int[] maxBorder = new int[]{maxX, maxY}; + int[] maxBorder = new int[]{maxX - 1, maxY - 1}; //创建粒子群 - PSO pso = new PSO(2, minBorder, maxBorder, 100, 100, + PSO pso = new PSO(2, minBorder, maxBorder, 200, 200, colorFunction, 0.2, 1, 0.5, true, 10, 1); - List positions = pso.start(0, 0); - List feature = new ArrayList<>();//像素特征 + List positions = pso.start(); for (int i = 0; i < positions.size(); i++) { double[] parameter = positions.get(i); //获取取样坐标 int x = (int) parameter[0]; int y = (int) parameter[1]; - double[] rgb = new double[]{matrixR.getNumber(x, y) / 255, matrixG.getNumber(x, y) / 255, - matrixB.getNumber(x, y) / 255}; - feature.add(rgb); + double[] rgb = new double[]{matrixR.getNumber(x, y), matrixG.getNumber(x, y), + matrixB.getNumber(x, y)}; + meanClustering.setColor(rgb); } - if (isStudy) {//进行新维度映射排序 - pso = new PSO(3, null, null, 200, 50, - new DimensionMapping(feature), 0.5, 2, 2, true, 0.5, 0.001); - List mappings = pso.start(0, 0);//最小映射集合 - double[] sigmaMapping = new double[3];//最小映射 - for (int i = 0; i < mappings.size(); i++) { - double[] mapping = mappings.get(i); - for (int j = 0; j < sigmaMapping.length; j++) { - sigmaMapping[j] = sigmaMapping[j] + mapping[j]; - } - } - for (int j = 0; j < sigmaMapping.length; j++) { - sigmaMapping[j] = sigmaMapping[j] / mappings.size(); - } - //保存类别及映射 - Food food = templeConfig.getFood(); - Map allMappings = food.getMappings(); - if (allMappings == null) { - allMappings = new HashMap<>(); - food.setMappings(allMappings); + meanClustering.start(true); + List rgbNorms = meanClustering.getMatrices(); + List features = new ArrayList<>(); + for (int i = 0; i < sqNub; i++) { + double[] rgb = rgbNorms.get(i).getRgb(); + for (int j = 0; j < rgb.length; j++) { + features.add(rgb[j]); } - allMappings.put(tag, sigmaMapping); - //根据映射值进行排序 - - } else { - } - return null; + return features; } - public List getCenterTexture(ThreeChannelMatrix threeChannelMatrix, int size, int poolSize, TempleConfig templeConfig - , int sqNub, int tag) throws Exception { + public List getCenterTexture(ThreeChannelMatrix threeChannelMatrix, int size, TempleConfig templeConfig + , int sqNub, boolean isStudy) throws Exception { MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig, true); Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); @@ -166,8 +146,8 @@ public class Convolution extends Frequency { //局部特征选区筛选 int nub = size * size; int twoNub = nub * 2; - for (int i = 0; i <= xn - size; i++) { - for (int j = 0; j <= yn - size; j++) { + for (int i = 0; i <= xn - size; i += 3) { + for (int j = 0; j <= yn - size; j += 3) { Matrix sonR = matrixR.getSonOfMatrix(i, j, size, size); Matrix sonG = matrixG.getSonOfMatrix(i, j, size, size); Matrix sonB = matrixB.getSonOfMatrix(i, j, size, size); @@ -204,14 +184,29 @@ public class Convolution extends Frequency { List features = new ArrayList<>(); for (int i = 0; i < sqNub; i++) { double[] rgb = rgbNorms.get(i).getRgb(); + if (!isStudy) { + rgb = rgbMapping(rgb, i, templeConfig); + } for (int j = 0; j < rgb.length; j++) { features.add(rgb[j]); } + } // System.out.println(features); return features; } + private double[] rgbMapping(double[] rgb, int index, TempleConfig templeConfig) {//进行映射 + double[] mapping = templeConfig.getFood().getMappingParameter(); + int size = rgb.length; + int allSize = mapping.length / 2; + double[] mappingFeature = new double[size]; + for (int i = 0; i < size; i++) { + int myIndex = size * index + i; + mappingFeature[i] = rgb[i] * mapping[myIndex] + mapping[allSize + myIndex]; + } + return mappingFeature; + } private void normalization(Matrix matrix) throws Exception { for (int i = 0; i < matrix.getX(); i++) { diff --git a/src/main/java/org/wlld/imageRecognition/MappingSort.java b/src/main/java/org/wlld/imageRecognition/MappingSort.java new file mode 100644 index 0000000..a3efc1a --- /dev/null +++ b/src/main/java/org/wlld/imageRecognition/MappingSort.java @@ -0,0 +1,23 @@ +package org.wlld.imageRecognition; + +import org.wlld.imageRecognition.modelEntity.MappingBody; + +import java.util.Comparator; + +/** + * @param + * @DATA + * @Author LiDaPeng + * @Description + */ +public class MappingSort implements Comparator { + @Override + public int compare(MappingBody o1, MappingBody o2) { + if (o1.getMappingNub() > o2.getMappingNub()) { + return -1; + } else if (o1.getMappingNub() < o2.getMappingNub()) { + return 1; + } + return 0; + } +} diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 6e7b088..3fa5093 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -93,10 +93,8 @@ public class Operation {//进行计算 int ySize = maxY - minY; //convolution.imgNormalization(threeChannelMatrix); ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); -// List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(), -// templeConfig.getFeatureNub(), templeConfig); - List feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), - templeConfig.getPoolSize(), templeConfig, templeConfig.getFeatureNub(), tag); + // List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig, templeConfig.getFeatureNub()); + List feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub(), true); if (templeConfig.isShowLog()) { System.out.println(tag + ":" + feature); } @@ -169,10 +167,9 @@ public class Operation {//进行计算 int xSize = maxX - minX; int ySize = maxY - minY; ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); -// List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(), -// templeConfig.getFeatureNub(), templeConfig); - List feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), - templeConfig.getPoolSize(), templeConfig, templeConfig.getFeatureNub(), 0); + //List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig, templeConfig.getFeatureNub()); + List feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub(), false); + if (templeConfig.isShowLog()) { System.out.println(feature); } @@ -202,7 +199,7 @@ public class Operation {//进行计算 break; } regionBody.setType(id); - //System.out.println("类别" + id); + System.out.println("类别" + id); } return regionList; } diff --git a/src/main/java/org/wlld/imageRecognition/border/Knn.java b/src/main/java/org/wlld/imageRecognition/border/Knn.java index 6ffa2fd..bcca245 100644 --- a/src/main/java/org/wlld/imageRecognition/border/Knn.java +++ b/src/main/java/org/wlld/imageRecognition/border/Knn.java @@ -14,6 +14,10 @@ public class Knn {//KNN分类器 this.nub = nub; } + public void setFeatureMap(Map> featureMap) { + this.featureMap = featureMap; + } + public Map> getFeatureMap() { return featureMap; } @@ -96,8 +100,8 @@ public class Knn {//KNN分类器 int type = entry.getKey(); List matrices = entry.getValue(); for (Matrix matrix : matrices) { - double dist = MatrixOperation.errorNub(vector, matrix, 0); - // double dist = MatrixOperation.getEDist(matrix, vector); + //double dist = MatrixOperation.errorNub(vector, matrix); + double dist = MatrixOperation.getEDist(matrix, vector); compare(dists, types, dist, type); } } diff --git a/src/main/java/org/wlld/imageRecognition/modelEntity/MappingBody.java b/src/main/java/org/wlld/imageRecognition/modelEntity/MappingBody.java index dd61a68..27f83a1 100644 --- a/src/main/java/org/wlld/imageRecognition/modelEntity/MappingBody.java +++ b/src/main/java/org/wlld/imageRecognition/modelEntity/MappingBody.java @@ -10,19 +10,13 @@ public class MappingBody { private double[] feature;//特征 private double mappingNub;//映射好的值 - public MappingBody(double[] mapping, double[] feature) { + public MappingBody(double[] feature) { this.feature = feature; double sigma = 0; - for (int i = 0; i < mapping.length; i++) { - sigma = sigma + Math.pow(mapping[i], 2); + for (int i = 0; i < feature.length; i++) { + sigma = sigma + Math.pow(feature[i], 2); } - sigma = Math.sqrt(sigma);//映射维度的莫 - double s = 0; - for (int j = 0; j < feature.length; j++) { - s = s + feature[j] * mapping[j]; - } - mappingNub = s / sigma; - + mappingNub = Math.sqrt(sigma); } public double[] getFeature() { diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/DimensionMapping.java b/src/main/java/org/wlld/imageRecognition/segmentation/DimensionMapping.java deleted file mode 100644 index 68b3b15..0000000 --- a/src/main/java/org/wlld/imageRecognition/segmentation/DimensionMapping.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.wlld.imageRecognition.segmentation; - -import org.wlld.i.PsoFunction; -import org.wlld.tools.Frequency; - -import java.util.List; - -/** - * @param - * @DATA - * @Author LiDaPeng - * @Description 维度映射 - */ -public class DimensionMapping extends Frequency implements PsoFunction { - private List features; - private int size; - - public DimensionMapping(List features) { - this.features = features; - size = features.size(); - } - - @Override - public double getResult(double[] parameter, int id) throws Exception { - double sigma = 0; - for (int i = 0; i < parameter.length; i++) { - sigma = sigma + Math.pow(parameter[i], 2); - } - sigma = Math.sqrt(sigma); - double[] mapping = new double[size];//在新维度的映射集合 - for (int i = 0; i < size; i++) { - double[] feature = features.get(i); - double s = 0; - for (int j = 0; j < feature.length; j++) { - s = s + feature[j] * parameter[j]; - } - mapping[i] = s / sigma; - } - return variance(mapping); - } -} diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/DimensionMappingStudy.java b/src/main/java/org/wlld/imageRecognition/segmentation/DimensionMappingStudy.java new file mode 100644 index 0000000..04eab49 --- /dev/null +++ b/src/main/java/org/wlld/imageRecognition/segmentation/DimensionMappingStudy.java @@ -0,0 +1,153 @@ +package org.wlld.imageRecognition.segmentation; + +import org.wlld.MatrixTools.Matrix; +import org.wlld.i.PsoFunction; +import org.wlld.imageRecognition.RGBNorm; +import org.wlld.imageRecognition.TempleConfig; +import org.wlld.pso.PSO; + +import java.util.*; + + +/** + * @param + * @DATA + * @Author LiDaPeng + * @Description 维度映射 + */ +public class DimensionMappingStudy { + private double getDist(Matrix data1, Matrix data2) throws Exception { + int size = data1.getY(); + double sigma = 0; + for (int i = 0; i < size; i++) { + sigma = sigma + Math.pow(data1.getNumber(0, i) - data2.getNumber(0, i), 2); + } + return Math.sqrt(sigma); + } + + private double compareSame(List testFeatures) throws Exception {//比较同类找最小值 + int size = testFeatures.size(); + double max = 0; + for (int i = 0; i < size; i++) { + Matrix feature = testFeatures.get(i); + double min = -1; + for (int j = 0; j < size; j++) { + if (i != j) { + double dist = getDist(feature, testFeatures.get(j)); + if (min == -1 || dist < min) { + min = dist; + } + } + } + if (min > max) { + max = min; + } + } + return max; + } + + private double compareDifferent(List featureSame, List featureDifferent) throws Exception { + double min = -1;//比较异类取最小值 + for (Matrix myFeature : featureSame) { + for (Matrix feature : featureDifferent) { + double dist = getDist(myFeature, feature); + if (min < 0 || dist < min) { + min = dist; + } + } + } + return min; + } + + class MinType { + private double minDist; + private int type; + } + + public void selfTest(TempleConfig templeConfig) throws Exception {//对模型数据进行自检测 + Map> featureMap = templeConfig.getKnn().getFeatureMap(); + Map maxMap = new HashMap<>();//保存与该类别最大间距 + Map> minMap = new HashMap<>();//保存与该类别最相似的类别,及距离值 + for (Map.Entry> entry : featureMap.entrySet()) { + int key = entry.getKey(); + List minTypes = new ArrayList<>(); + List myFeatures = entry.getValue(); + double sameMax = compareSame(myFeatures);//同类之间的最大值 + maxMap.put(key, sameMax); + for (Map.Entry> entry2 : featureMap.entrySet()) { + int testKey = entry2.getKey(); + if (testKey != key) {//找出最小距离 + List features = entry2.getValue(); + MinType minType = new MinType(); + double minDist = compareDifferent(myFeatures, features);//该类别的最小值 + if (minDist < sameMax) { + minType.minDist = minDist; + minType.type = testKey; + minTypes.add(minType); + } + } + } + minMap.put(key, minTypes); + } + for (Map.Entry entry : maxMap.entrySet()) { + int key = entry.getKey(); + double maxValue = entry.getValue(); + System.out.println("============================================="); + System.out.println("类别:" + key + ",最大类间距为:" + maxValue); + List minTypes = minMap.get(key); + for (int i = 0; i < minTypes.size(); i++) { + MinType minType = minTypes.get(i); + System.out.println("相近类:" + minType.type + ",最小类间距为:" + minType.minDist); + } + } + } + + public void start(TempleConfig templeConfig) throws Exception { + Map> featureMap = templeConfig.getKnn().getFeatureMap(); + FeatureMapping featureMapping = new FeatureMapping(featureMap); + int dimensionNub = templeConfig.getFeatureNub() * 3 * 2;//PSO维度 + //创建粒子群 + PSO pso = new PSO(dimensionNub, null, null, 200, 100, + featureMapping, 0.4, 2, 2, true, 0.2, 0.01); + List mappings = pso.start(); + int size = mappings.size(); + double[] mappingSigma = new double[dimensionNub]; + for (int i = 0; i < size; i++) { + double[] mapping = mappings.get(i); + for (int j = 0; j < mapping.length; j++) { + mappingSigma[j] = mappingSigma[j] + mapping[j]; + } + } + for (int i = 0; i < mappingSigma.length; i++) { + mappingSigma[i] = mappingSigma[i] / size; + } + templeConfig.getFood().setMappingParameter(mappingSigma); + //还要把所有已存在的knn特征完成映射 + featureMapping(featureMap, mappingSigma, templeConfig); + } + + private void featureMapping(Map> featureMap, double[] mapping + , TempleConfig templeConfig) throws Exception { + Map> featureMap2 = new HashMap<>(); + for (Map.Entry> entry : featureMap.entrySet()) { + int key = entry.getKey(); + List features = entry.getValue(); + List mappingFeatures = new ArrayList<>(); + for (Matrix matrix : features) { + mappingFeatures.add(mapping(matrix, mapping)); + } + featureMap2.put(key, mappingFeatures); + } + templeConfig.getKnn().setFeatureMap(featureMap2); + } + + private Matrix mapping(Matrix feature, double[] mapping) throws Exception { + int size = feature.getY(); + Matrix matrix = new Matrix(1, size); + for (int i = 0; i < size; i++) { + double nub = feature.getNumber(0, i) * mapping[i] + mapping[size + i]; + matrix.setNub(0, i, nub); + } + return matrix; + } +} diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/FeatureMapping.java b/src/main/java/org/wlld/imageRecognition/segmentation/FeatureMapping.java new file mode 100644 index 0000000..b71516a --- /dev/null +++ b/src/main/java/org/wlld/imageRecognition/segmentation/FeatureMapping.java @@ -0,0 +1,115 @@ +package org.wlld.imageRecognition.segmentation; + +import org.wlld.MatrixTools.Matrix; +import org.wlld.i.PsoFunction; +import org.wlld.tools.Frequency; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @param + * @DATA + * @Author LiDaPeng + * @Description 特征映射 + */ +public class FeatureMapping extends Frequency implements PsoFunction { + private Map> featureMap;//特征 + + public FeatureMapping(Map> featureMap) { + this.featureMap = featureMap; + } + + @Override + public double getResult(double[] parameter, int id) throws Exception { + + return featuresMapping(parameter); + } + + private double[] mapping(Matrix matrix, double[] parameter) throws Exception { + int size = matrix.getY(); + double[] mapping = new double[size]; + for (int i = 0; i < size; i++) { + mapping[i] = matrix.getNumber(0, i) * parameter[i] + parameter[size + i]; + } + return mapping; + } + + private double getDist(double[] data1, double[] data2) { + int size = data1.length; + double sigma = 0; + for (int i = 0; i < size; i++) { + sigma = sigma + Math.pow(data1[i] - data2[i], 2); + } + return Math.sqrt(sigma); + } + + private double compareSame(List testFeatures) {//比较同类找最大值 + int size = testFeatures.size(); + double max = 0; + for (int i = 0; i < size; i++) { + double min = -1; + double[] feature = testFeatures.get(i); + for (int j = 0; j < size; j++) { + if (i != j) { + double dist = getDist(feature, testFeatures.get(j)); + if (min < 0 || dist < min) { + min = dist; + } + } + } + if (min > max) { + max = min; + } + } + return max; + } + + private double compareDifferent(List featureSame, List featureDifferent) { + double min = -1;//比较异类取最小值 + for (double[] myFeature : featureSame) { + for (double[] feature : featureDifferent) { + double dist = getDist(myFeature, feature); + if (min < 0 || dist < min) { + min = dist; + } + } + } + return min; + } + + private double compareDist(Map> mapping) {//比较距离 + double sigma = 0; + for (Map.Entry> entry : mapping.entrySet()) { + int key = entry.getKey(); + List myFeature = entry.getValue(); + List featureDifferent = new ArrayList<>(); + for (Map.Entry> entry2 : mapping.entrySet()) { + if (entry2.getKey() != key) { + featureDifferent.addAll(entry2.getValue()); + } + } + double sameMax = compareSame(myFeature);//同类最大值 + double differentMin = compareDifferent(myFeature, featureDifferent);//异类最小值 + double sub = differentMin - sameMax; + sigma = sigma + sub; + } + return sigma; + } + + private double featuresMapping(double[] parameter) throws Exception {//对当前所有数据进行映射 + Map> mapping = new HashMap<>(); + for (Map.Entry> entry : featureMap.entrySet()) { + int key = entry.getKey(); + List features = entry.getValue();//当前类别的所有特征 + List featureList = new ArrayList<>(); + for (Matrix matrix : features) { + featureList.add(mapping(matrix, parameter)); + } + mapping.put(key, featureList); + } + return compareDist(mapping); + } +} diff --git a/src/main/java/org/wlld/param/Food.java b/src/main/java/org/wlld/param/Food.java index 025e11e..7c2adf6 100644 --- a/src/main/java/org/wlld/param/Food.java +++ b/src/main/java/org/wlld/param/Food.java @@ -24,14 +24,14 @@ public class Food { private int step = 1;//特征取样步长 private int speciesNub = 24;//种类数 private KNerveManger kNerveManger; - private Map mappings;//类别映射集合 + private double[] mappingParameter;//特征映射 - public Map getMappings() { - return mappings; + public double[] getMappingParameter() { + return mappingParameter; } - public void setMappings(Map mappings) { - this.mappings = mappings; + public void setMappingParameter(double[] mappingParameter) { + this.mappingParameter = mappingParameter; } public KNerveManger getkNerveManger() { diff --git a/src/main/java/org/wlld/pso/PSO.java b/src/main/java/org/wlld/pso/PSO.java index 874f3d6..c10ef53 100644 --- a/src/main/java/org/wlld/pso/PSO.java +++ b/src/main/java/org/wlld/pso/PSO.java @@ -66,7 +66,7 @@ public class PSO { this.allPar = allPar; } - public List start(int fatherX, int fatherY) throws Exception {//开始进行迭代 + public List start() throws Exception {//开始进行迭代 int size = allPar.size(); for (int i = 0; i < times; i++) { for (int j = 0; j < size; j++) { diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index 8474709..a6f68f8 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -8,10 +8,7 @@ import org.wlld.config.Classifier; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; import org.wlld.imageRecognition.*; -import org.wlld.imageRecognition.segmentation.KNerveManger; -import org.wlld.imageRecognition.segmentation.RegionBody; -import org.wlld.imageRecognition.segmentation.RegionMapping; -import org.wlld.imageRecognition.segmentation.Specifications; +import org.wlld.imageRecognition.segmentation.*; import org.wlld.nerveEntity.ModelParameter; import org.wlld.param.Cutting; import org.wlld.param.Food; @@ -68,14 +65,14 @@ public class FoodTest { cutting.setRegionNub(100); cutting.setMaxIou(2); //knn参数 - templeConfig.setKnnNub(15); + templeConfig.setKnnNub(1); //池化比例 templeConfig.setPoolSize(2);//缩小比例 //聚类 templeConfig.setFeatureNub(5);//聚类特征数量 //菜品识别实体类 food.setShrink(5);//缩紧像素 - food.setRegionSize(5); + food.setRegionSize(6); KNerveManger kNerveManger = new KNerveManger(12, 24, 6000); food.setkNerveManger(kNerveManger); food.setRowMark(0.15);//0.12 @@ -156,59 +153,65 @@ public class FoodTest { operation.colorStudy(threeChannelMatrix23, 23, specificationsList, name); operation.colorStudy(threeChannelMatrix24, 24, specificationsList, name); } - System.out.println("========================"); - kNerveManger.startStudy(); - int i = 3; -// ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(name + "a" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix(name + "b" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix(name + "c" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix(name + "d" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix(name + "e" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix(name + "f" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix(name + "g" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix(name + "h" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix9 = picture.getThreeMatrix(name + "i" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix10 = picture.getThreeMatrix(name + "j" + i + ".jpg"); + DimensionMappingStudy dimensionMappingStudy = new DimensionMappingStudy(); + //System.out.println("映射前检查========================"); + dimensionMappingStudy.selfTest(templeConfig);//检查 + dimensionMappingStudy.start(templeConfig);//完成映射 + System.out.println("映射后检查========================"); + dimensionMappingStudy.selfTest(templeConfig);//检查 + //System.out.println("========================"); + // kNerveManger.startStudy(); + int i = 4; + ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(name + "a" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix(name + "b" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix(name + "c" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix(name + "d" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix(name + "e" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix(name + "f" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix(name + "g" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix(name + "h" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix9 = picture.getThreeMatrix(name + "i" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix10 = picture.getThreeMatrix(name + "j" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix11 = picture.getThreeMatrix(name + "k" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix12 = picture.getThreeMatrix(name + "l" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix12 = picture.getThreeMatrix(name + "l" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix13 = picture.getThreeMatrix(name + "m" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix14 = picture.getThreeMatrix(name + "n" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix14 = picture.getThreeMatrix(name + "n" + i + ".jpg"); // -// ThreeChannelMatrix threeChannelMatrix15 = picture.getThreeMatrix(name + "o" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix16 = picture.getThreeMatrix(name + "p" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix17 = picture.getThreeMatrix(name + "q" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix18 = picture.getThreeMatrix(name + "r" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix19 = picture.getThreeMatrix(name + "s" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix20 = picture.getThreeMatrix(name + "t" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix21 = picture.getThreeMatrix(name + "u" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix22 = picture.getThreeMatrix(name + "v" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix23 = picture.getThreeMatrix(name + "w" + i + ".jpg"); - // ThreeChannelMatrix threeChannelMatrix24 = picture.getThreeMatrix(name + "x" + i + ".jpg"); -// operation.colorLook(threeChannelMatrix1, specificationsList); -// operation.colorLook(threeChannelMatrix2, specificationsList); -// operation.colorLook(threeChannelMatrix3, specificationsList); -// operation.colorLook(threeChannelMatrix4, specificationsList); -// operation.colorLook(threeChannelMatrix5, specificationsList); -// operation.colorLook(threeChannelMatrix6, specificationsList); -// operation.colorLook(threeChannelMatrix7, specificationsList); -// operation.colorLook(threeChannelMatrix8, specificationsList); -// operation.colorLook(threeChannelMatrix9, specificationsList); -// operation.colorLook(threeChannelMatrix10, specificationsList); + ThreeChannelMatrix threeChannelMatrix15 = picture.getThreeMatrix(name + "o" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix16 = picture.getThreeMatrix(name + "p" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix17 = picture.getThreeMatrix(name + "q" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix18 = picture.getThreeMatrix(name + "r" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix19 = picture.getThreeMatrix(name + "s" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix20 = picture.getThreeMatrix(name + "t" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix21 = picture.getThreeMatrix(name + "u" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix22 = picture.getThreeMatrix(name + "v" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix23 = picture.getThreeMatrix(name + "w" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix24 = picture.getThreeMatrix(name + "x" + i + ".jpg"); + operation.colorLook(threeChannelMatrix1, specificationsList); + operation.colorLook(threeChannelMatrix2, specificationsList); + operation.colorLook(threeChannelMatrix3, specificationsList); + operation.colorLook(threeChannelMatrix4, specificationsList); + operation.colorLook(threeChannelMatrix5, specificationsList); + operation.colorLook(threeChannelMatrix6, specificationsList); + operation.colorLook(threeChannelMatrix7, specificationsList); + operation.colorLook(threeChannelMatrix8, specificationsList); + operation.colorLook(threeChannelMatrix9, specificationsList); + operation.colorLook(threeChannelMatrix10, specificationsList); operation.colorLook(threeChannelMatrix11, specificationsList); -// operation.colorLook(threeChannelMatrix12, specificationsList); + operation.colorLook(threeChannelMatrix12, specificationsList); operation.colorLook(threeChannelMatrix13, specificationsList); -// operation.colorLook(threeChannelMatrix14, specificationsList); -// operation.colorLook(threeChannelMatrix15, specificationsList); -// operation.colorLook(threeChannelMatrix16, specificationsList); -// operation.colorLook(threeChannelMatrix17, specificationsList); -// operation.colorLook(threeChannelMatrix18, specificationsList); -// operation.colorLook(threeChannelMatrix19, specificationsList); -// operation.colorLook(threeChannelMatrix20, specificationsList); -// operation.colorLook(threeChannelMatrix21, specificationsList); -// operation.colorLook(threeChannelMatrix22, specificationsList); -// operation.colorLook(threeChannelMatrix23, specificationsList); -// operation.colorLook(threeChannelMatrix24, specificationsList); -// + operation.colorLook(threeChannelMatrix14, specificationsList); + operation.colorLook(threeChannelMatrix15, specificationsList); + operation.colorLook(threeChannelMatrix16, specificationsList); + operation.colorLook(threeChannelMatrix17, specificationsList); + operation.colorLook(threeChannelMatrix18, specificationsList); + operation.colorLook(threeChannelMatrix19, specificationsList); + operation.colorLook(threeChannelMatrix20, specificationsList); + operation.colorLook(threeChannelMatrix21, specificationsList); + operation.colorLook(threeChannelMatrix22, specificationsList); + operation.colorLook(threeChannelMatrix23, specificationsList); + operation.colorLook(threeChannelMatrix24, specificationsList); + // test3(threeChannelMatrix1, operation, specificationsList, 1); // test3(threeChannelMatrix2, operation, specificationsList, 2); // test3(threeChannelMatrix3, operation, specificationsList, 3); @@ -232,7 +235,7 @@ public class FoodTest { // test3(threeChannelMatrix21, operation, specificationsList, 21); // test3(threeChannelMatrix22, operation, specificationsList, 22); // test3(threeChannelMatrix23, operation, specificationsList, 23); - //test3(threeChannelMatrix24, operation, specificationsList, 24); +// test3(threeChannelMatrix24, operation, specificationsList, 24); } diff --git a/src/test/java/coverTest/ForestTest.java b/src/test/java/coverTest/ForestTest.java index b306aaa..98f63db 100644 --- a/src/test/java/coverTest/ForestTest.java +++ b/src/test/java/coverTest/ForestTest.java @@ -84,7 +84,6 @@ public class ForestTest { templeConfig.setFeatureNub(3);//聚类特征数量 //菜品识别实体类 food.setShrink(5);//缩紧像素 - food.setTimes(1);//聚类数据增强 food.setRowMark(0.15);//0.12 food.setColumnMark(0.15);//0.25 food.setRegressionNub(20000); diff --git a/src/test/java/coverTest/regionCut/RegionCut.java b/src/test/java/coverTest/regionCut/RegionCut.java index 13c74e3..f2f9b27 100644 --- a/src/test/java/coverTest/regionCut/RegionCut.java +++ b/src/test/java/coverTest/regionCut/RegionCut.java @@ -36,7 +36,7 @@ public class RegionCut { long a = System.currentTimeMillis(); PSO pso = new PSO(2, minBorder, maxBorder, 100, 100, colorFunction, 0.2, 1, 0.5, true, 10, 1); - pso.start(fatherX, fatherY); + pso.start(); long b = System.currentTimeMillis() - a; System.out.println("时间:" + b); // Matrix matrixR = threeChannelMatrix.getMatrixR();