From 8c233bd6cc977d245c58a999ef930397c848da82 Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Wed, 22 Apr 2020 19:45:42 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wlld/imageRecognition/CoverBody.java | 9 ++ .../org/wlld/imageRecognition/MaxPoint.java | 4 + .../org/wlld/imageRecognition/Operation.java | 86 ++++++++++++- .../wlld/imageRecognition/TempleConfig.java | 27 ++++- .../imageRecognition/ThreeChannelMatrix.java | 9 ++ src/test/java/coverTest/CoverTest.java | 114 ++++++++---------- src/test/java/coverTest/FoodTest.java | 77 +++--------- src/test/java/org/wlld/HelloWorld.java | 1 - src/test/java/org/wlld/ModelData.java | 18 +-- 9 files changed, 204 insertions(+), 141 deletions(-) diff --git a/src/main/java/org/wlld/imageRecognition/CoverBody.java b/src/main/java/org/wlld/imageRecognition/CoverBody.java index 7b788d7..f0833b7 100644 --- a/src/main/java/org/wlld/imageRecognition/CoverBody.java +++ b/src/main/java/org/wlld/imageRecognition/CoverBody.java @@ -6,12 +6,21 @@ import java.util.Map; public class CoverBody { private List> feature;//特征 private Map tag;//标注 + private List> cFeature;//卷积特征 private int type; public int getType() { return type; } + public List> getcFeature() { + return cFeature; + } + + public void setcFeature(List> cFeature) { + this.cFeature = cFeature; + } + public void setType(int type) { this.type = type; } diff --git a/src/main/java/org/wlld/imageRecognition/MaxPoint.java b/src/main/java/org/wlld/imageRecognition/MaxPoint.java index de0afbd..02d0c47 100644 --- a/src/main/java/org/wlld/imageRecognition/MaxPoint.java +++ b/src/main/java/org/wlld/imageRecognition/MaxPoint.java @@ -7,6 +7,10 @@ public class MaxPoint implements OutBack { private int id; private double point = -1; + public void setTh(double th) { + point = th; + } + public int getId() { return id; } diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 8476910..dd1f9cb 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -10,6 +10,7 @@ import org.wlld.i.OutBack; import org.wlld.imageRecognition.border.*; import org.wlld.nerveCenter.NerveManager; import org.wlld.nerveCenter.Normalization; +import org.wlld.nerveEntity.Nerve; import org.wlld.nerveEntity.SensoryNerve; import org.wlld.tools.ArithUtil; import org.wlld.tools.IdCreator; @@ -56,6 +57,78 @@ public class Operation {//进行计算 return sub(matrix1); } + public void coverStudyOne(Map matrixMap, int regionSize) throws Exception {//先学卷积核 + Frame frame = new Frame(); + frame.setHeight(regionSize); + frame.setWidth(regionSize); + frame.setLengthHeight(regionSize); + frame.setLengthWidth(regionSize); + List sensoryNerve = templeConfig.getConvolutionNerveManager().getSensoryNerves(); + for (Map.Entry entry : matrixMap.entrySet()) { + Matrix matrix = entry.getValue().getH(); + List frameBodies = convolution.getRegion(matrix, frame); + int key = entry.getKey(); + int size = frameBodies.size(); + for (int i = 0; i < size; i++) { + FrameBody frameBody = frameBodies.get(i); + intoConvolutionNetwork(1, frameBody.getMatrix(), sensoryNerve, true, key, null); + } + } + } + + public void coverStudyTwo(Map matrixMap, int poolSize, int sqNub, int regionSize, + int times) throws Exception { + int size = templeConfig.getSensoryNerves().size(); + List sensoryNerve = templeConfig.getConvolutionNerveManager().getSensoryNerves(); + Frame frame = new Frame(); + frame.setHeight(regionSize); + frame.setWidth(regionSize); + frame.setLengthHeight(regionSize); + frame.setLengthWidth(regionSize); + List coverBodies = new ArrayList<>(); + for (Map.Entry entry : matrixMap.entrySet()) { + List frameBodies = convolution.getRegion(entry.getValue().getH(), frame); + int key = entry.getKey(); + int sizeA = frameBodies.size(); + List> featureList = new ArrayList<>(); + for (int i = 0; i < sizeA; i++) { + FrameBody frameBody = frameBodies.get(i); + MatrixBack matrixBack = new MatrixBack(); + intoConvolutionNetwork(1, frameBody.getMatrix(), sensoryNerve, false, 0, matrixBack); + Matrix matrix1 = matrixBack.getMatrix(); + List feature = getFeatures(matrix1); + featureList.add(feature); + } + CoverBody coverBody = new CoverBody(); + Map tag = new HashMap<>(); + tag.put(entry.getKey(), 1.0); + //聚类RGB特征 + List> lists = convolution.kAvg(entry.getValue(), poolSize, sqNub, regionSize); + coverBody.setcFeature(featureList); + coverBody.setFeature(lists); + coverBody.setTag(tag); + coverBodies.add(coverBody); + } + for (int j = 0; j < times; j++) { + for (int i = 0; i < size; i++) { + List list; + for (CoverBody coverBody : coverBodies) { + List list1 = coverBody.getFeature().get(i); + List list2 = coverBody.getcFeature().get(i); + if (i < list1.size()) { + list = list1; + } else { + list = list2; + } + if (templeConfig.isShowLog()) { + System.out.println("feature:" + list); + } + intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null); + } + } + } + } + public void coverStudy(Map matrixMap, int poolSize, int sqNub, int regionSize, int times) throws Exception { if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { @@ -285,6 +358,17 @@ public class Operation {//进行计算 lvq.insertMatrixBody(matrixBody); } + private List getFeatures(Matrix matrix) throws Exception { + List list = new ArrayList<>(); + for (int i = 0; i < matrix.getX(); i++) { + for (int j = 0; j < matrix.getY(); j++) { + double nub = matrix.getNumber(i, j); + list.add(nub); + } + } + return list; + } + private List getFeature(Matrix matrix) throws Exception {//将特征矩阵转化为集合并除10 List list = new ArrayList<>(); Normalization normalization = templeConfig.getNormalization(); @@ -298,7 +382,6 @@ public class Operation {//进行计算 } else { list.add(0.0); } - } } return list; @@ -588,6 +671,7 @@ public class Operation {//进行计算 private int getClassificationIdByDnn(Matrix myMatrix) throws Exception { List list = getFeature(myMatrix); MaxPoint maxPoint = new MaxPoint(); + maxPoint.setTh(templeConfig.getTh()); long id = IdCreator.get().nextId(); intoDnnNetwork(id, list, templeConfig.getSensoryNerves(), false, null, maxPoint); return maxPoint.getId(); diff --git a/src/main/java/org/wlld/imageRecognition/TempleConfig.java b/src/main/java/org/wlld/imageRecognition/TempleConfig.java index 9f912f3..2e1dff4 100644 --- a/src/main/java/org/wlld/imageRecognition/TempleConfig.java +++ b/src/main/java/org/wlld/imageRecognition/TempleConfig.java @@ -41,7 +41,7 @@ public class TempleConfig { private boolean isHavePosition = false;//是否需要锁定物体位置 private LVQ lvq;//模型需要返回,精准模式下的原型聚类 private Frame frame;//先验边框 - private double th = 0.6;//标准阈值 + private double th = -1;//标准阈值 private boolean boxReady = false;//边框已经学习完毕 private double iouTh = 0.5;//IOU阈值 private int lvqNub = 10;//lvq循环次数,默认30 @@ -255,6 +255,31 @@ public class TempleConfig { } } + public void initCover(boolean initPower, int width, int height, int kNub) throws Exception { + int deep = 0; + Map matrixMap = new HashMap<>();//主键与期望矩阵的映射 + while (width > 5 && height > 5) { + width = width / 3; + height = height / 3; + deep++; + } + int nub = height * width * 3 + kNub; + initNerveManager(true, nub, this.deep, studyPoint); + //加载各识别分类的期望矩阵 + matrixMap.put(0, new Matrix(height, width)); + for (int k = 1; k <= classificationNub; k++) { + Matrix matrix = new Matrix(height, width);//初始化期望矩阵 + double t = k * matrixWidth;//期望矩阵的分类参数数值 + for (int i = 0; i < height; i++) {//给期望矩阵注入期望参数 + for (int j = 0; j < width; j++) { + matrix.setNub(i, j, t); + } + } + matrixMap.put(k, matrix); + } + convolutionNerveManager = initNerveManager(matrixMap, initPower, deep); + } + private void initModelVision(boolean initPower, int width, int height) throws Exception {//初始标准模板视觉 double d; if (width > height) { diff --git a/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java b/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java index bdf330c..8711d9c 100644 --- a/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java +++ b/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java @@ -6,6 +6,15 @@ public class ThreeChannelMatrix { Matrix matrixR; Matrix matrixG; Matrix matrixB; + Matrix H; + + public Matrix getH() { + return H; + } + + public void setH(Matrix h) { + H = h; + } public Matrix getMatrixR() { return matrixR; diff --git a/src/test/java/coverTest/CoverTest.java b/src/test/java/coverTest/CoverTest.java index ec8593e..e1ee301 100644 --- a/src/test/java/coverTest/CoverTest.java +++ b/src/test/java/coverTest/CoverTest.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.wlld.MatrixTools.Matrix; import org.wlld.ModelData; +import org.wlld.config.Classifier; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; import org.wlld.function.Sigmod; @@ -22,7 +23,8 @@ import java.util.Map; */ public class CoverTest { public static void main(String[] args) throws Exception { - cover(); + cover2("D:\\pic\\6/4.jpg"); + //test(null, 2, 2, 20); } public static void insertModel(String model) throws Exception {//注入模型 @@ -40,58 +42,48 @@ public class CoverTest { public static Operation getModel() throws Exception { //覆盖率计算,计算以前,内存中已经注入过模型了 TempleConfig templeConfig = new TempleConfig(); - templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3); + templeConfig.setSensoryNerveNub(3); + //templeConfig.setSoftMax(true); + templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 2); ModelParameter modelParameter = JSONObject.parseObject(ModelData.DATA, ModelParameter.class); templeConfig.insertModel(modelParameter); return new Operation(templeConfig);//初始化运算类 } - public static void test(Operation operation, int poolSize, int sqlNub, int regionSize) throws Exception { + public static void test(Operation operation, int poolSize, int sqlNub, int regionSize, String url) throws Exception { Picture picture = new Picture(); int allNub = 0; int wrong = 0; - for (int i = 1; i < 2; i++) { - allNub += 3; - ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("D:\\share\\jie/1.jpg"); - ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\jie/2.jpg"); - // ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\jie/3.jpg"); - //ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai/d" + i + ".jpg"); - //ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix("D:\\share\\cai/e" + i + ".jpg"); - //ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix("D:\\share\\cai/f" + i + ".jpg"); - //ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix("D:\\share\\cai/g" + i + ".jpg"); - //ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix("D:\\share\\cai/h" + i + ".jpg"); - - Map map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); - Map map2 = operation.coverPoint(threeChannelMatrix2, poolSize, sqlNub, regionSize); - // Map map3 = operation.coverPoint (threeChannelMatrix3, poolSize, sqlNub, regionSize); - //Map map4 = operation.coverPoint(threeChannelMatrix4, poolSize, sqlNub, regionSize); -// Map map5 = operation.coverPoint(threeChannelMatrix5, poolSize, sqlNub, regionSize); -// Map map6 = operation.coverPoint(threeChannelMatrix6, poolSize, sqlNub, regionSize); -// Map map7 = operation.coverPoint(threeChannelMatrix7, poolSize, sqlNub, regionSize); -// Map map8 = operation.coverPoint(threeChannelMatrix8, poolSize, sqlNub, regionSize); - - for (Map.Entry entry : map1.entrySet()) { - int key = entry.getKey(); - double value = entry.getValue(); - System.out.println("1key===" + key + ",value==" + value); - } - System.out.println("============================="); - for (Map.Entry entry : map2.entrySet()) { - int key = entry.getKey(); - double value = entry.getValue(); - System.out.println("2key===" + key + ",value==" + value); - } - System.out.println("============================="); + if (operation == null) { + operation = getModel(); + } + ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(url); + Map map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); + for (Map.Entry entry : map1.entrySet()) { + int key = entry.getKey(); + double value = entry.getValue(); + System.out.println("key===" + key + ",value==" + value); + } -// for (Map.Entry entry : map3.entrySet()) { -// int key = entry.getKey(); -// double value = entry.getValue(); -// System.out.println("3key===" + key + ",value==" + value); -// } -// System.out.println("============================="); + } + public static void cover2(String url) throws Exception { + Picture picture = new Picture(); + TempleConfig templeConfig = new TempleConfig(); + templeConfig.setClassifier(Classifier.DNN); + templeConfig.setTh(0.9); + templeConfig.setSoftMax(true); + templeConfig.init(StudyPattern.Accuracy_Pattern, false, 640, 480, 2); + ModelParameter modelParameter = JSON.parseObject(ModelData.DATA3, ModelParameter.class); + templeConfig.insertModel(modelParameter); + Operation operation = new Operation(templeConfig); + Matrix matrix = picture.getImageMatrixByLocal(url); + int type = operation.toSee(matrix); + if (type != 1) {//不是扰动 + test(null, 2, 3, 18, url); + } else {//是扰动 + System.out.println("是扰动===="); } - } public static void cover() throws Exception { @@ -101,39 +93,31 @@ public class CoverTest { TempleConfig templeConfig = new TempleConfig(); //初始化模板 注意 width height参数是你训练图片的实际尺寸需要改,其他不用动 //创建运算类进行标注 - //templeConfig.setActiveFunction(new Sigmod()); templeConfig.isShowLog(true); templeConfig.setStudyPoint(0.01);//不动 - templeConfig.setSoftMax(true); + //templeConfig.setSoftMax(true); //templeConfig.setDeep(2); - templeConfig.setSensoryNerveNub(2); - templeConfig.setRzType(RZ.L1);//不动 + //templeConfig.setHiddenNerveNub(12); + templeConfig.setSensoryNerveNub(3); + templeConfig.setRzType(RZ.L1);//不动//3 18 templeConfig.setlParam(0.015);//不动 templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 2); Operation operation = new Operation(templeConfig); - for (int i = 1; i < 2; i++) { + for (int i = 1; i < 45; i++) { Map matrixMap = new HashMap<>(); - ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\jie/1.jpg"); - ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\jie/2.jpg"); - // ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\jie/3.jpg"); -// ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai/d" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix("D:\\share\\cai/e" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix("D:\\share\\cai/f" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix("D:\\share\\cai/g" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix("D:\\share\\cai/h" + i + ".jpg"); - matrixMap.put(1, threeChannelMatrix1); - matrixMap.put(2, threeChannelMatrix2); - // matrixMap.put(3, threeChannelMatrix3); -// matrixMap.put(4, threeChannelMatrix4); -// matrixMap.put(5, threeChannelMatrix5); -// matrixMap.put(6, threeChannelMatrix6); -// matrixMap.put(7, threeChannelMatrix7); -// matrixMap.put(8, threeChannelMatrix8); - operation.coverStudy(matrixMap, 2, 2, 40, 20); + //桔梗覆盖 + ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic\\test/b" + i + ".jpg"); + //土壤扰动 + ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\pic\\test/c" + i + ".jpg"); + //ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\pic\\test/d" + i + ".jpg"); + //ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\jie/4.jpg"); + matrixMap.put(1, threeChannelMatrix1);//桔梗覆盖 + matrixMap.put(2, threeChannelMatrix2);//土壤扰动 + //matrixMap.put(3, threeChannelMatrix3);//白地 + operation.coverStudy(matrixMap, 2, 3, 18, 2); } ModelParameter modelParameter = templeConfig.getModel(); String model = JSON.toJSONString(modelParameter); System.out.println(model); - test(operation, 2, 2, 40); } } diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index d813341..1f6acb9 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -2,98 +2,67 @@ package coverTest; import com.alibaba.fastjson.JSON; import org.wlld.MatrixTools.Matrix; -import org.wlld.ModelData; import org.wlld.config.Classifier; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; import org.wlld.imageRecognition.*; -import org.wlld.imageRecognition.segmentation.ImageSegmentation; import org.wlld.nerveEntity.ModelParameter; import org.wlld.tools.ArithUtil; -import java.util.*; - public class FoodTest { public static void main(String[] args) throws Exception { - food(); } public static void food() throws Exception { Picture picture = new Picture(); TempleConfig templeConfig = new TempleConfig(); - templeConfig.setClassifier(Classifier.DNN); templeConfig.isShowLog(true); - templeConfig.setRzType(RZ.L2); - templeConfig.setlParam(0.01);//0.015 - templeConfig.init(StudyPattern.Accuracy_Pattern, true, 400, 400, 3); -// ModelParameter modelParameter1 = JSON.parseObject(ModelData.DATA, ModelParameter.class); -// templeConfig.insertModel(modelParameter1); + templeConfig.setSoftMax(true); + //templeConfig.setStudyPoint(0.01); + templeConfig.setRzType(RZ.L1); + templeConfig.setlParam(0.015);//0.015 + templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 480, 2); Operation operation = new Operation(templeConfig); // 一阶段 - for (int j = 0; j < 2; j++) { - for (int i = 1; i < 101; i++) {//一阶段 + for (int j = 0; j < 5; j++) { + for (int i = 1; i < 45; i++) {//一阶段 System.out.println("study1===================" + i); //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\share\\cai/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\share\\cai/b" + i + ".jpg"); - Matrix c = picture.getImageMatrixByLocal("D:\\share\\cai/c" + i + ".jpg"); - //Matrix d = picture.getImageMatrixByLocal("D:\\share\\cai/d" + i + ".jpg"); - //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 - //第二次学习的时候,第三个参数必须是 true + Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); operation.learning(a, 1, false); operation.learning(b, 2, false); - operation.learning(c, 3, false); - //operation.learning(d, 4, false); } } //二阶段 - for (int i = 1; i < 101; i++) { + for (int i = 1; i < 45; i++) { System.out.println("avg==" + i); - Matrix a = picture.getImageMatrixByLocal("D:\\share\\cai/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\share\\cai/b" + i + ".jpg"); - Matrix c = picture.getImageMatrixByLocal("D:\\share\\cai/c" + i + ".jpg"); - //Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); operation.normalization(a, templeConfig.getConvolutionNerveManager()); operation.normalization(b, templeConfig.getConvolutionNerveManager()); - operation.normalization(c, templeConfig.getConvolutionNerveManager()); - //operation.normalization(d, templeConfig.getConvolutionNerveManager()); } templeConfig.getNormalization().avg(); -// ModelParameter modelParameter2 = templeConfig.getModel(); -// String model2 = JSON.toJSONString(modelParameter2); -// System.out.println(model2); for (int j = 0; j < 10; j++) { - for (int i = 1; i < 101; i++) { + for (int i = 1; i < 45; i++) { System.out.println("j==" + j + ",study2==================" + i); - //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\share\\cai/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\share\\cai/b" + i + ".jpg"); - Matrix c = picture.getImageMatrixByLocal("D:\\share\\cai/c" + i + ".jpg"); - // Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); - //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 - //第二次学习的时候,第三个参数必须是 true + Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); operation.learning(a, 1, true); operation.learning(b, 2, true); - operation.learning(c, 3, true); - //operation.learning(d, 4, true); } } templeConfig.finishStudy();//结束学习 - int wrong = 0; int allNub = 0; - for (int i = 10; i <= 20; i++) { + for (int i = 1; i <= 44; i++) { //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\share\\cai/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\share\\cai/b" + i + ".jpg"); - Matrix c = picture.getImageMatrixByLocal("D:\\share\\cai/c" + i + ".jpg"); - //Matrix d = picture.getImageMatrixByLocal("D:\\share\\picture/d" + i + ".jpg"); - //将图像矩阵和标注加入进行学习,Accuracy_Pattern 模式 进行第二次学习 - //第二次学习的时候,第三个参数必须是 true - allNub += 3; + Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); + allNub += 2; int an = operation.toSee(a); if (an != 1) { wrong++; @@ -102,14 +71,6 @@ public class FoodTest { if (bn != 2) { wrong++; } - int cn = operation.toSee(c); - if (cn != 3) { - wrong++; - } - /*int dn = operation.toSee(d); - if (dn != 4) { - wrong++; - }*/ } double wrongPoint = ArithUtil.div(wrong, allNub); System.out.println("错误率:" + (wrongPoint * 100) + "%"); diff --git a/src/test/java/org/wlld/HelloWorld.java b/src/test/java/org/wlld/HelloWorld.java index 5821ead..98ea321 100644 --- a/src/test/java/org/wlld/HelloWorld.java +++ b/src/test/java/org/wlld/HelloWorld.java @@ -41,7 +41,6 @@ public class HelloWorld { public static void pictureDemo1() throws Exception {//图像学习DEMO //easyAI 包持续更新,现阶段一直在优化 - // Picture picture = new Picture(); //使用精度计算 TempleConfig templeConfig = new TempleConfig(false, true); diff --git a/src/test/java/org/wlld/ModelData.java b/src/test/java/org/wlld/ModelData.java index aaa9fed..5828879 100644 --- a/src/test/java/org/wlld/ModelData.java +++ b/src/test/java/org/wlld/ModelData.java @@ -7,19 +7,7 @@ package org.wlld; */ public class ModelData { //860第一遍 - public static final String DATA = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.7998116372264066,2:0.40380733262931384,3:0.12792574540385118,4:0.5173253947524863,5:0.0832193862838894,6:0.22480554761746102,7:0.2886328632640672,8:0.43864968070463234,9:1.0133412742123433},\"threshold\":2.052658471189923},{\"dendrites\":{1:0.18571072810196898,2:0.5236121650165935,3:0.6324438457326524,4:0.35428949139397004,5:0.0010274009675371916,6:0.19953891991859388,7:0.5153473886182146,8:0.7991055830121385,9:0.6517438268134714},\"threshold\":-0.023860148528099995},{\"dendrites\":{1:0.4462875445805169,2:0.21373521468816753,3:0.3513362870164161,4:0.4658589131864084,5:0.6600864883780445,6:0.4807308956844945,7:0.5024987614580826,8:0.8425974004365171,9:0.5530132481345429},\"threshold\":1.6769523375425797},{\"dendrites\":{1:0.272607565159634,2:0.8145023693247936,3:0.0011300806760706002,4:0.8225914125467462,5:0.20342564183225864,6:0.02048280208495907,7:0.20495999324621458,8:0.7819098337325391,9:0.6435469757774113},\"threshold\":0.19524050754255218},{\"dendrites\":{1:0.44372933504207773,2:0.7770341341769389,3:0.8289077429392738,4:0.2600866815560181,5:0.4270423083757987,6:0.8163772701666817,7:0.003200401270869674,8:0.9277641512957776,9:0.006584547029391698},\"threshold\":0.402025888774396},{\"dendrites\":{1:0.11957486813127685,2:0.2913725119929416,3:0.12505143831416135,4:0.5536654339597304,5:0.6238720045623902,6:0.7099659685960606,7:0.37302633799638923,8:0.002771812100375125,9:0.4818643269460117},\"threshold\":1.5591319689136065},{\"dendrites\":{1:0.8455147852118262,2:0.5874652906190143,3:0.1768252309317145,4:0.11712073512636569,5:0.0010475895035031927,6:0.7088537195962992,7:0.16511030137281624,8:0.662528124756596,9:0.046366349358814396},\"threshold\":0.11413234544959436},{\"dendrites\":{1:0.6706937025952646,2:1.1078840579362257,3:0.9274406551790406,4:0.5507469576846346,5:0.7071110449028108,6:0.3097524577666535,7:0.42509785367272274,8:0.5237744747782946,9:0.7418912123574547},\"threshold\":2.4506974343491517},{\"dendrites\":{1:0.7434747178079518,2:0.5625601972641473,3:0.6216265654062613,4:0.6851898193978103,5:0.2645204403443797,6:0.15602563242048856,7:0.3424921894988635,8:0.8395888407026573,9:0.11256229784651366},\"threshold\":-0.023246504560635168}]],\"dnnAvg\":0.0,\"dymNerveStudies\":[],\"dymOutNerveStudy\":{\"list\":[],\"threshold\":0.0},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:1.8364961793699532,2:0.29768307788631565,3:0.8859280718117206,4:0.2287455997659383,5:0.7845260583328935,6:1.619283476192089,7:0.20757254180971957,8:1.7623932924414805,9:0.17775667590187527},\"threshold\":1.011057361530005},{\"dendrites\":{1:1.2847703301016895,2:0.6719467794120516,3:0.9816772286028187,4:0.17737272089071568,5:0.03867069673565071,6:0.27840732560282816,7:0.33672270015653893,8:1.4579912852402481,9:0.3594324982797614},\"threshold\":0.780920800845333},{\"dendrites\":{1:-0.7722433058398388,2:0.9215279485467684,3:-1.2245261777694134,4:0.5381151956542075,5:0.18855157446303775,6:-0.2815284113424446,7:0.6292512625205571,8:-1.5696334084601273,9:0.2471836009448295},\"threshold\":0.0676676875717388}]}"; - // 1000 全部跑完模型 - public static final String DATA2 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:1.0726469516582375,2:0.2900323080782664,3:0.17114141471329783,4:0.2314574502940457,5:0.7830779803359506,6:0.09599918830622363,7:-0.5564661470580663,8:0.20816937059115256,9:0.7615768602166169,10:0.1560638571363552,11:-0.18151469637476242,12:0.040899006744756265,13:0.2764274859235372,14:0.14897022626100348,15:0.23255577596152344,16:0.09440772794123062},\"threshold\":-2.1867664264382216},{\"dendrites\":{1:-0.33322313653409774,2:0.6350240383340725,3:0.9888450204096775,4:0.21743957060056415,5:0.9901784664203942,6:-0.19915323069620006,7:0.4873394169301697,8:0.015527351276747715,9:0.8433200250065566,10:0.48106814274226467,11:0.9412898933618189,12:0.23206979161755747,13:0.04124560365453406,14:0.13505904932537516,15:0.15586623970851923,16:0.2837776137768952},\"threshold\":1.584931852558341},{\"dendrites\":{1:0.2872741833212156,2:0.2740435118567442,3:0.23744029857847143,4:0.07441391877683538,5:0.2847496413068294,6:0.8504668240233186,7:0.45179184028206854,8:0.1862887616471994,9:0.7248138360642485,10:0.7729210699738696,11:0.8749636623788832,12:0.2599853074552137,13:0.2108637912646668,14:0.1381801053202437,15:0.001222782083895304,16:0.07415219877734464},\"threshold\":-1.3900865693174496},{\"dendrites\":{1:1.0783541160051204,2:0.33070926548504725,3:0.21311826468831974,4:0.06288100406636658,5:0.8920977825830456,6:-0.0954320369676343,7:-0.6341112900668329,8:0.028422165580942745,9:1.0611127683541972,10:0.17906461017749664,11:-0.0711448724884833,12:0.28265436692093293,13:0.08445586386636,14:0.2343145041780869,15:0.21703304056369,16:0.18503890354790686},\"threshold\":-2.1517369497917156},{\"dendrites\":{1:0.29696418726177193,2:0.3017190370950359,3:0.6393700423225641,4:0.019276566103108933,5:-0.2881826822667932,6:0.7813590181217703,7:0.6912186047800181,8:0.22320015393413517,9:0.24401222019959584,10:0.5460963086211945,11:0.7361799155346161,12:0.20659089901519567,13:0.006608141145043067,14:0.2909329496768138,15:0.1356173446070367,16:0.2544679627422998},\"threshold\":-0.45499730886736606},{\"dendrites\":{1:-0.02203654176105024,2:0.1964684109357692,3:0.2546183260668611,4:0.05588607902993757,5:0.6731408181940768,6:1.3361817704883092,7:0.5126336524105402,8:0.1839077487729906,9:1.0799116947582208,10:0.6335662492536746,11:0.8468325837129851,12:0.02365401695449992,13:0.15719591302399005,14:0.10430008448790115,15:0.24929962717673787,16:0.08925533386003841},\"threshold\":-1.6604013930310642},{\"dendrites\":{1:0.2014182652197323,2:-0.1882780867948683,3:0.16867771654476568,4:0.1401156847421454,5:0.11706621028728291,6:0.9575317225894712,7:0.4749653435135051,8:0.15912523210833857,9:0.7070757840756798,10:0.725760011360116,11:1.0630391259177527,12:0.010847011709784598,13:0.18328959544220563,14:0.2329393022171855,15:0.16654577603648107,16:0.13591891353789845},\"threshold\":-0.8591457806717231},{\"dendrites\":{1:0.05281873514804986,2:-1.2549273992936416,3:-1.003297985921287,4:0.1525263981260854,5:-0.5030014611615592,6:1.0517057287226597,7:-0.18965580679773303,8:0.1892108471007988,9:-0.7562402915347771,10:0.694178507679812,11:1.170076845132834,12:0.07472518731898126,13:0.2619133933663768,14:0.14503469636122107,15:7.523921060417027E-4,16:0.169536210163995},\"threshold\":-0.24833968513289456},{\"dendrites\":{1:0.08423847604743089,2:0.05211962497144486,3:0.34072478492464126,4:0.23165907253746323,5:-0.15654863073374548,6:0.4314566366159193,7:0.34887422504936044,8:0.06169918648309871,9:0.2454721905510605,10:0.644332862267291,11:1.1134652126118036,12:0.11562522899477508,13:0.12720901066382662,14:0.10417355718512958,15:0.021547510819832732,16:0.1724390912913507},\"threshold\":0.2916129568752605}],[{\"dendrites\":{1:-0.15854816225500884,2:1.3003725388881837,3:-0.1374646031947635,4:-0.12523274249176056,5:0.3269001259731162,6:-0.12205670130833873,7:0.5467814148773441,8:-1.1346602855423737,9:0.3299620140460315},\"threshold\":0.8648305488464417},{\"dendrites\":{1:0.20821734969220393,2:-0.11645371962139146,3:0.34895707225587547,4:0.1868474232176194,5:0.25478051642494826,6:0.5335576357076008,7:0.28759650038341034,8:0.15775061549620323,9:0.03865374761253424},\"threshold\":-0.3407460202099142},{\"dendrites\":{1:0.5733193743875766,2:-0.0726426093196283,3:0.03610837702783675,4:0.5867509128114917,5:-0.19923059099663923,6:0.03822195201046544,7:-0.009624705886016407,8:-0.19802698713921976,9:-0.2495294730971326},\"threshold\":-1.1772469825541636},{\"dendrites\":{1:0.24344491766585427,2:0.4646767663449006,3:0.26416980711649635,4:0.3446524332646141,5:0.16052830159954015,6:0.20546750464165928,7:0.6164558307432768,8:0.7180638213427298,9:0.2789509921546555},\"threshold\":0.5002960554264994},{\"dendrites\":{1:0.21910929272353258,2:-0.06791506082533606,3:0.5196583347245222,4:0.22569914310322128,5:0.30804308095014316,6:0.7421978160263416,7:0.28996057254466145,8:-0.0016545774649372772,9:-0.027303479741148304},\"threshold\":-0.14542768705217912},{\"dendrites\":{1:0.24511271535810744,2:-0.31050170442838354,3:0.4925638700300686,4:0.27050010150279774,5:0.3395424194589474,6:0.5935490524907139,7:0.283626657391884,8:-0.02556619178209673,9:0.026503340863302458},\"threshold\":0.19340584506407538},{\"dendrites\":{1:0.17971525539607622,2:0.5049120735834614,3:0.22777598703625918,4:0.1525471207875283,5:0.2577969524422507,6:0.1763800610878328,7:0.4482399202371939,8:1.2061377234301673,9:0.35048651191863966},\"threshold\":-0.22808648014461316},{\"dendrites\":{1:0.2650027220267543,2:-0.43889501510467294,3:0.5338945532150466,4:0.24974442562244054,5:0.47087185321190583,6:0.7024467004402177,7:0.399627862485626,8:0.10605853218536754,9:0.06534497184042735},\"threshold\":-0.040408539374054094},{\"dendrites\":{1:0.12108597109723263,2:0.12014598102624065,3:0.34683786717741355,4:0.11328536454744431,5:0.37299535756626917,6:0.31957919646245,7:0.22578612308766005,8:-0.537043737154446,9:0.14148556763170422},\"threshold\":0.4997282946394663}]],\"dnnAvg\":22.9064021073,\"dymNerveStudies\":[{\"list\":[0.9204131967857795,0.33734775184915733,0.267794472922007,0.22984837600924468,0.9478036366939943,0.5096122693628161,0.5288748010489226,0.5775822154498489,0.17207423563789292],\"threshold\":0.0178098080491707},{\"list\":[0.9647661486860237,0.40709405167176993,0.772807212053615,0.3777117779703144,0.30223699178499,0.8761069699741557,0.8102705150583089,0.9807033671322598,0.5933635388258779],\"threshold\":-0.637981161785914},{\"list\":[0.684998591057084,0.551047426169548,0.21168809917178644,0.37395460290770255,0.529357922727241,0.7413132592365504,0.48004412808026287,0.06678471764615757,0.4147740287889953],\"threshold\":-2.410382288552367},{\"list\":[0.12819487471118596,0.6619088335519062,0.4785281792391074,0.10947945156729455,0.6140258070215251,0.144446947899613,0.9897427149114851,0.7653677561186567,0.9647046461705113],\"threshold\":-5.749785590774564}],\"dymOutNerveStudy\":{\"list\":[0.1420194413032101,0.04265095724643442,0.46332729630976366,0.18576229039188252,0.18158522097239505,0.636872994216039,0.7353219355036306,0.40067049106640595,0.6243031762269835],\"threshold\":-15.44906593215222},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:1.3069650433735516,2:-0.04870245731288827,3:0.30189410943394257,4:0.11911521030123885,5:-0.027315373296523178,6:-0.060420500414280556,7:0.11526206127973658,8:-0.07407895517023481,9:-0.024545765099570082},\"threshold\":-1.0702633567721098},{\"dendrites\":{1:-0.824019501946374,2:0.07618790084253624,3:0.14906173721208624,4:0.4734885578764465,5:0.06143767990914905,6:0.049864760222168084,7:0.7735459615747887,8:0.07808591787342545,9:-0.46179186196786465},\"threshold\":-0.06133958835217247},{\"dendrites\":{1:-0.008309346235013525,2:-0.3474275494445811,3:0.486518233795785,4:0.19869564499038656,5:-0.5458211002355086,6:-0.37996758683424864,7:-0.07840493660517152,8:-0.507832171615987,9:0.013997884418729508},\"threshold\":-1.1400794626056399},{\"dendrites\":{1:-0.513223145866014,2:0.21468215773534985,3:-0.03231436393921348,4:-0.6418325130530286,5:0.325659468717365,6:0.36561526393282345,7:-0.7273797698558792,8:0.48677661833488683,9:0.29885525455309503},\"threshold\":0.6640192939357535}]}"; - //5 - public static final String DATA3 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:1.3259385848931655,2:0.47040682776298604,3:0.2626458930710314,4:-0.6931666899516274},\"threshold\":0.1453612348036091},{\"dendrites\":{1:1.1272365640099227,2:-0.7337466876050133,3:1.284322391399613,4:-0.3471114920768559},\"threshold\":-1.0499069028248464},{\"dendrites\":{1:0.016504521661250424,2:-0.10360965006145044,3:1.3652414749205937,4:0.42199222473877945},\"threshold\":-1.4216266119900416},{\"dendrites\":{1:-0.6557724271422759,2:0.5059166113424489,3:0.591672021496659,4:1.5605292204461032},\"threshold\":-1.0324355747309064},{\"dendrites\":{1:0.6802906970222707,2:1.6799412761066854,3:1.3531381462511556,4:1.2615738815960797},\"threshold\":0.7987849092602402},{\"dendrites\":{1:0.558610138859577,2:1.1781048633066742,3:-0.04120451326411118,4:0.8973744836692659},\"threshold\":-0.3364860842210545},{\"dendrites\":{1:1.2201853163931442,2:-0.1319268265505929,3:0.8899349564821847,4:-0.2239436430161853},\"threshold\":-1.4593542524452927},{\"dendrites\":{1:-1.4627108201384893,2:-0.4218087822935181,3:0.8424473913425632,4:1.7381108101943565},\"threshold\":0.009017139220030404},{\"dendrites\":{1:0.21979223862443736,2:-0.09999423845758065,3:1.7493830593593733,4:1.2815060979300226},\"threshold\":-1.2468615252112183}],[{\"dendrites\":{1:-0.06814352458384446,2:0.8654209659798254,3:0.606671878859585,4:0.6690422943293964,5:0.18776993680988208,6:0.4429600106747597,7:0.8007974121988832,8:0.40769292777931043,9:1.089736256954681},\"threshold\":0.11425372893619534},{\"dendrites\":{1:0.4235048601914431,2:0.7301733420440525,3:0.47626065885455093,4:0.20301545827959935,5:-0.14563615295968657,6:0.18938539585886321,7:0.8331177878303199,8:0.08819831079771183,9:1.034007428790719},\"threshold\":0.9035997370956839},{\"dendrites\":{1:-0.0136583263659488,2:1.08540853493493,3:0.6313292218205966,4:0.15616830292219105,5:-0.45257029636590934,6:-0.011821338304250636,7:1.0264664644560217,8:0.09852241171249033,9:0.6153245286623159},\"threshold\":-0.46809655313578014},{\"dendrites\":{1:0.8396468935481934,2:0.24597478533373515,3:0.01709635957889014,4:-0.5157896554506954,5:1.510992017062753,6:0.7053192033802479,7:-0.1301122289133768,8:-1.8114335497652565,9:0.6334010229654464},\"threshold\":0.028096629685495183},{\"dendrites\":{1:0.23731607777021319,2:0.34547711659021174,3:0.5608853822432557,4:-0.09644814573654577,5:0.46901507365465206,6:-0.05164507717178522,7:1.1075376447172733,8:-0.26165687811551763,9:-0.22320027819102847},\"threshold\":-0.5687511270861467},{\"dendrites\":{1:0.10561785365469165,2:0.21097969297409194,3:0.8016626912756442,4:1.0909872287991207,5:0.2527759146699615,6:0.4787114619004488,7:0.9706369146132799,8:-0.061020470316131004,9:1.3341810110225092},\"threshold\":0.4032090222860525},{\"dendrites\":{1:-0.10768669048968336,2:0.30909155387598075,3:0.9041843535141528,4:0.9889376059559655,5:-0.4857743290489738,6:0.7746145317918771,7:1.067237890644749,8:0.9039695592402688,9:0.5859758041389942},\"threshold\":-0.5138621895906719},{\"dendrites\":{1:0.31673036128998944,2:1.2194426935855434,3:0.7450217363929681,4:-0.2915272111515559,5:-0.13306522798783305,6:0.0943981635226951,7:1.0418390678891094,8:0.15647654696126545,9:0.11408175020349469},\"threshold\":-0.1449149617757226},{\"dendrites\":{1:-0.5482449247301743,2:0.8516085836279023,3:1.2361644496454496,4:0.9525331308203848,5:1.4776341546293064,6:-0.6305101936166168,7:0.08278195139673016,8:0.6008344744928618,9:0.537598097839101},\"threshold\":0.7770676119627797}]],\"dnnAvg\":13.3918449779,\"dymNerveStudies\":[{\"list\":[0.3802997191178773,0.8462333264133151,0.3036497890525801,0.6689386465632953,0.9735321423105247,0.03171032455330913,0.9373462916780746,0.09813374876375669,0.6301581389749229],\"threshold\":0.243375767137266},{\"list\":[0.9579864516034587,0.7453204963742909,0.7675279083214079,0.2685283704775936,0.31624489126212485,0.9682768574597324,0.15839748326211833,0.5087439869677978,0.22284068544420677],\"threshold\":-0.0315607192208512},{\"list\":[0.9687831229099197,0.7995117245095982,0.7410761863500637,0.008883753739061362,0.0805261621628518,0.11774125943169367,0.7439291424182288,0.5137881818731225,0.14108782484639681],\"threshold\":-1.655850111381332},{\"list\":[0.8553625742144583,0.6115443829670403,0.4093248404029084,0.9708407229452056,0.3928292015441476,0.5118514829956673,0.2992546905182132,0.7632147750608906,0.7862704478937678],\"threshold\":-2.865071941977669}],\"dymOutNerveStudy\":{\"list\":[0.79718819165002,0.23004903884236327,0.46247637217453164,0.3111780421847602,0.1360181231469869,0.954646485791314,0.2256813071526178,0.13556759374345917,0.9881114501705892],\"threshold\":-5.486450691799499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.10434101602614843,2:-0.059927108794489065,3:0.5288563441427986,4:-1.220281452591742,5:0.5268899063519855,6:-0.1668026589215263,7:0.42610522515961735,8:-0.07609330230866232,9:0.04864756427917784},\"threshold\":0.11315114688098979},{\"dendrites\":{1:0.22728893928451854,2:-0.08476513639000224,3:-0.0429026071263658,4:0.013208858828787608,5:0.16212825171355355,6:0.8671316248600842,7:0.1799041204549389,8:-0.3101603786319704,9:-1.0081053128024589},\"threshold\":0.0013061515535431295},{\"dendrites\":{1:0.04346486976885912,2:-0.39896936099929897,3:-0.060456365659088,4:1.156091647487133,5:0.6399013533886204,6:0.09476612730484273,7:-0.32178474625033576,8:0.21539419974348012,9:1.2154708250027648},\"threshold\":0.2294945820642692},{\"dendrites\":{1:-0.4629707929200189,2:0.018844564819924733,3:0.35301506968074037,4:0.0036245591209093874,5:0.322885182539098,6:-0.3589345967034893,7:-0.6644413037745864,8:0.5837702508565968,9:0.14139736823209761},\"threshold\":-0.08772557762708731}]}"; - //5 2 turn - public static final String DATA4 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.5917560699684765,2:0.4554486309772757,3:-0.21887742229595913,4:-0.6868276845082959},\"threshold\":-0.2524238913404783},{\"dendrites\":{1:0.48172548112383506,2:-0.1955761828390817,3:0.5865455447440502,4:-0.4170280846909415},\"threshold\":-2.706483061497177},{\"dendrites\":{1:0.30758516529598207,2:-0.08378222040503464,3:0.6974126586099952,4:0.0026924699649801412},\"threshold\":-2.7321076155645683},{\"dendrites\":{1:-0.3430645263390683,2:-0.07091888906887905,3:0.6526876925870272,4:1.2567661015487426},\"threshold\":-1.2851785657877595},{\"dendrites\":{1:0.745024471857397,2:1.2216365794077515,3:0.8244695902752506,4:1.0100790784296503},\"threshold\":1.186431588180451},{\"dendrites\":{1:0.5042303362052656,2:0.5210137421011828,3:0.2489388185112416,4:0.16288391047372125},\"threshold\":-0.8293389024650619},{\"dendrites\":{1:0.5249095851322366,2:-0.17402384110026808,3:0.5412138993376147,4:-0.3038635170877526},\"threshold\":-3.1961357489436373},{\"dendrites\":{1:-0.9332712226949142,2:-0.8320227485799006,3:0.5906463628473037,4:1.1526514857291845},\"threshold\":-0.3629752561165897},{\"dendrites\":{1:0.18485806423208168,2:0.28166138846439215,3:0.8843293444145859,4:1.6055591511270648},\"threshold\":-2.053793505125926}],[{\"dendrites\":{1:-0.1034671246286903,2:0.31461176329425566,3:0.2899191573932242,4:0.7624135544342118,5:0.28910353535538535,6:0.39929484898565376,7:0.29338035234413673,8:0.28550464635381695,9:1.1873579471324271},\"threshold\":0.10369566150741943},{\"dendrites\":{1:0.3492344397236351,2:0.6393623742915312,3:0.5435370804552192,4:0.13545066306235476,5:-0.472116168383956,6:0.1392880966752137,7:0.6756837843405995,8:-0.07513247732433441,9:0.6129489652100572},\"threshold\":0.313639398858994},{\"dendrites\":{1:0.17760132233450182,2:0.8429100187492751,3:0.648537954072567,4:0.0809365909132784,5:-0.6850310801223252,6:0.051374986780825936,7:0.8193897837261207,8:-0.04671609310067271,9:0.386201056575497},\"threshold\":-1.1920037573185844},{\"dendrites\":{1:1.0913982994068328,2:0.20200718636538967,3:0.038637677322789124,4:-0.6994454557166421,5:1.6371841918501844,6:0.5785212077384612,7:0.07744324859008798,8:-1.951015423148565,9:-0.10922312377857823},\"threshold\":-0.22205860465771332},{\"dendrites\":{1:0.35370451687552085,2:0.5698163423801003,3:0.616989805655968,4:-0.003738332819281344,5:0.0014134929746160347,6:0.1678683194988737,7:0.8514758250746568,8:-0.29231993459596356,9:0.09045847901734769},\"threshold\":-1.291807053862159},{\"dendrites\":{1:-0.009562938100936743,2:0.09205973085177949,3:0.38783281032761907,4:1.0053290688156278,5:0.39408183786300516,6:0.48572403061321107,7:0.37691791781229733,8:0.10326365602742855,9:1.518878088256713},\"threshold\":0.34937765828195044},{\"dendrites\":{1:-0.01448280594975573,2:0.2618204382185314,3:0.5579129767665085,4:0.6018348727490939,5:-0.3154185480701584,6:0.49001094868757045,7:0.540125184135829,8:0.4016348405013319,9:0.7313880541073778},\"threshold\":-0.6938240778061615},{\"dendrites\":{1:0.4028646808645448,2:0.8829881658941134,3:0.674307291900761,4:-0.06097101656621159,5:-0.2768851742854966,6:0.15770813620068178,7:0.8174591354696867,8:-0.17673743326126887,9:0.1406812792751312},\"threshold\":-0.8545499405632809},{\"dendrites\":{1:-0.26473261204979975,2:0.4817498956197396,3:0.6437337455430177,4:1.3934180254651896,5:1.6561812249362444,6:-0.022726847126333882,7:0.1963009360175778,8:0.5373657025818331,9:0.3168247834616192},\"threshold\":0.546987991629296}]],\"dnnAvg\":13.3918449779,\"dymNerveStudies\":[{\"list\":[0.3802997191178773,0.8462333264133151,0.3036497890525801,0.6689386465632953,0.9735321423105247,0.03171032455330913,0.9373462916780746,0.09813374876375669,0.6301581389749229],\"threshold\":0.243375767137266},{\"list\":[0.9579864516034587,0.7453204963742909,0.7675279083214079,0.2685283704775936,0.31624489126212485,0.9682768574597324,0.15839748326211833,0.5087439869677978,0.22284068544420677],\"threshold\":-0.0315607192208512},{\"list\":[0.9687831229099197,0.7995117245095982,0.7410761863500637,0.008883753739061362,0.0805261621628518,0.11774125943169367,0.7439291424182288,0.5137881818731225,0.14108782484639681],\"threshold\":-1.655850111381332},{\"list\":[0.8553625742144583,0.6115443829670403,0.4093248404029084,0.9708407229452056,0.3928292015441476,0.5118514829956673,0.2992546905182132,0.7632147750608906,0.7862704478937678],\"threshold\":-2.865071941977669}],\"dymOutNerveStudy\":{\"list\":[0.79718819165002,0.23004903884236327,0.46247637217453164,0.3111780421847602,0.1360181231469869,0.954646485791314,0.2256813071526178,0.13556759374345917,0.9881114501705892],\"threshold\":-5.486450691799499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.03515585365525281,2:0.12625680657988014,3:0.36959685020197486,4:-1.3352290674205063,5:0.3608791309220879,6:-0.03472837982524032,7:0.14830289077932363,8:0.1464819578108098,9:0.001547160061495903},\"threshold\":-0.18641737503752512},{\"dendrites\":{1:0.42807692214648113,2:-0.053103125726328616,3:-0.0718767108612509,4:0.021692436887008625,5:0.006666695578927621,6:0.8941481883011424,7:0.09402134377129936,8:-0.16970143771089977,9:-1.2047183227994513},\"threshold\":0.09855407792706118},{\"dendrites\":{1:-0.05924236852552514,2:-0.09991123104606221,3:0.02458685491124864,4:0.9396791399277128,5:0.28597288687951067,6:-0.12151904319494963,7:-0.025940821658146474,8:0.12688272996866998,9:1.2009069027748462},\"threshold\":0.1805167690848419},{\"dendrites\":{1:-0.7828981812014709,2:0.1078786234770949,3:0.37006966389486473,4:-0.0036500336345967736,5:0.358320077925031,6:-0.7742158689241855,7:-0.40594397594334475,8:0.4553415887818529,9:0.16833740169432118},\"threshold\":-0.5129881300001293}]}"; - //5 2 turn2 - public static final String DATA5 = "{\"avg\":0.0,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.32229051169406114,2:-0.6714456320180129,3:0.43299066123867863,4:-0.642678975483748},\"threshold\":-6.833729939277554},{\"dendrites\":{1:0.6445324925135806,2:0.859183062600219,3:1.0197095248199648,4:1.7970734900553953},\"threshold\":-0.07641715121532765},{\"dendrites\":{1:1.8968408358458162,2:2.0117904484322344,3:-0.3091365027114937,4:-0.8125976029926767},\"threshold\":-0.24927337612195355},{\"dendrites\":{1:2.574138697869021,2:2.6962047196796335,3:-0.5184816785204076,4:-1.35951880690742},\"threshold\":-0.004957909455046405},{\"dendrites\":{1:0.33057130967130416,2:-0.6526968071571082,3:0.414832219795702,4:-0.6567744510210094},\"threshold\":-6.895595165074303},{\"dendrites\":{1:0.34922644520961305,2:-0.6176520217204221,3:0.462396867459111,4:-0.6161836508850149},\"threshold\":-7.981769942606722},{\"dendrites\":{1:-0.08133475815497582,2:0.306222905980326,3:1.2008125656334436,4:2.189088375088779},\"threshold\":-3.141079848108155},{\"dendrites\":{1:0.3158219095072537,2:-0.6526744259415028,3:0.42720070639093116,4:-0.6152490593271731},\"threshold\":-7.197314701813571},{\"dendrites\":{1:0.2894753579363113,2:-0.6976540441186309,3:0.45027576241499195,4:-0.5731686414348005},\"threshold\":-6.948350568397406}],[{\"dendrites\":{1:0.6998126049222685,2:-2.085469338844975,3:-2.3604833305052084,4:-3.113787619482046,5:0.693624137684854,6:0.6984207378472278,7:0.35201397342838825,8:0.7188404387262212,9:0.7035327578606533},\"threshold\":-1.6409344449642125},{\"dendrites\":{1:0.804261619394793,2:0.2947834770078834,3:0.2508256036663497,4:0.0692963423130082,5:0.7733018667793679,6:0.7114970483217854,7:0.347766224035084,8:0.6636438220056533,9:0.7779941398331374},\"threshold\":-2.021799327906594},{\"dendrites\":{1:0.7506060476945542,2:0.3764822447134663,3:0.7457174717132103,4:0.5992184243212109,5:0.7007550755441295,6:0.8161396948355651,7:0.4351567885562564,8:0.7761921785721387,9:0.7704935390161876},\"threshold\":-2.4027239168277505},{\"dendrites\":{1:-7.648262368633612E-4,2:0.8397307376503,3:0.3639145974266064,4:0.09662942025105749,5:-0.011589349124885847,6:0.07290052614759715,7:2.421469710894741,8:0.020209532433899148,9:0.0278007187298022},\"threshold\":0.08551025432829719},{\"dendrites\":{1:0.7147628848700701,2:0.04395841334646054,3:0.7583520619023196,4:1.1183302680877008,5:0.6547143569633417,6:0.6752458069732387,7:0.5967015920302173,8:0.7599571212647642,9:0.6662288589343112},\"threshold\":-1.556396153852109},{\"dendrites\":{1:0.7176445312307571,2:0.09320415957673278,3:0.7164063294482812,4:1.0949821364780261,5:0.730600544362099,6:0.7831362803939056,7:0.31958973471591967,8:0.7535284853509937,9:0.6552783264386564},\"threshold\":-1.5938819768042658},{\"dendrites\":{1:0.29036519016028195,2:1.6584058713692973,3:-0.7370217379177736,4:-1.165806205707898,5:0.26902109621213605,6:0.28591919016310907,7:0.7616975153332527,8:0.2954945911031307,9:0.32463957797750853},\"threshold\":0.07097239066838584},{\"dendrites\":{1:0.7028188437738823,2:0.3236277404584568,3:0.3080133447372902,4:0.2507972396688361,5:0.744630640521729,6:0.6864591688197008,7:0.4717940472440348,8:0.68935822152695,9:0.7511574210689694},\"threshold\":-2.1401308077478385},{\"dendrites\":{1:0.7179694253518794,2:0.1193754272654243,3:0.8362186362589676,4:0.9926158532589905,5:0.7687482305880835,6:0.7785259135682171,7:0.47813195163235944,8:0.702449808993823,9:0.6917228070966107},\"threshold\":-1.7946026053832083}]],\"dnnAvg\":13.3918449779,\"dymNerveStudies\":[{\"list\":[0.3802997191178773,0.8462333264133151,0.3036497890525801,0.6689386465632953,0.9735321423105247,0.03171032455330913,0.9373462916780746,0.09813374876375669,0.6301581389749229],\"threshold\":0.243375767137266},{\"list\":[0.9579864516034587,0.7453204963742909,0.7675279083214079,0.2685283704775936,0.31624489126212485,0.9682768574597324,0.15839748326211833,0.5087439869677978,0.22284068544420677],\"threshold\":-0.0315607192208512},{\"list\":[0.9687831229099197,0.7995117245095982,0.7410761863500637,0.008883753739061362,0.0805261621628518,0.11774125943169367,0.7439291424182288,0.5137881818731225,0.14108782484639681],\"threshold\":-1.655850111381332},{\"list\":[0.8553625742144583,0.6115443829670403,0.4093248404029084,0.9708407229452056,0.3928292015441476,0.5118514829956673,0.2992546905182132,0.7632147750608906,0.7862704478937678],\"threshold\":-2.865071941977669}],\"dymOutNerveStudy\":{\"list\":[0.79718819165002,0.23004903884236327,0.46247637217453164,0.3111780421847602,0.1360181231469869,0.954646485791314,0.2256813071526178,0.13556759374345917,0.9881114501705892],\"threshold\":-5.486450691799499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:1.0594893695994547,2:0.11768754679043912,3:0.09718947123758448,4:-0.11745341181914072,5:0.03141232352741326,6:-0.005362306817976925,7:1.1637001707020562,8:0.11115910157022396,9:0.06910336622491631},\"threshold\":0.3418400142276562},{\"dendrites\":{1:0.09198987974047429,2:-0.0029827272896538683,3:-0.0034063859432906527,4:1.1007228431401663,5:0.08177090018586004,6:0.005634699913063491,7:-1.0401823454367372,8:-0.006482421453045148,9:0.06264344686963465},\"threshold\":0.22464966063776265},{\"dendrites\":{1:-1.2917869704196319,2:0.14412825073465582,3:0.1983653395042985,4:-0.11068428776687501,5:0.2045959535032769,6:0.17194080920832264,7:0.20381557070730769,8:0.1563138001120643,9:0.22318567602462783},\"threshold\":-0.1698657175979512},{\"dendrites\":{1:-0.011593636857985236,2:0.1555504263708401,3:0.1187887949365435,4:-1.2633544125640646,5:0.0024792641227992054,6:0.07901925924842323,7:0.01948910020425478,8:0.09291775302457052,9:0.0630836837463161},\"threshold\":-0.7246624032530284}]}"; - //2 0.1 - public static final String DATA6 = "{\"borderMap\":{},\"depthNerves\":[],\"dymNerveStudies\":[{\"list\":[0.8069552113481556,0.9709947341686338,0.8838778668807168,0.6858754757820691,0.019100112280012738,0.8675478242399742,0.31779795357047036,0.438831240616934,0.7834457892763799],\"threshold\":0.839652880616655},{\"list\":[0.2819343042226351,0.9392430985853434,0.11897477128098588,0.9414462009850345,0.9357828227358187,0.8242763362124853,0.5897533297885068,0.6613018520014384,0.14782106837196884],\"threshold\":1.912734137149397},{\"list\":[0.7950299356209136,0.8994152720194233,0.757710289644511,0.9890273982984203,0.6684213522161923,0.9597212014443263,0.42162950011258993,0.1524423462033272,0.6710784474787098],\"threshold\":1.595986359815487},{\"list\":[0.8890190098865085,0.9278430186565028,0.5480879104416314,0.5522431496953174,0.9450374957936978,0.5627594309925331,0.8671171308411209,0.7230267707344997,0.1090669307419706],\"threshold\":2.504113323224686}],\"dymOutNerveStudy\":{\"list\":[0.04267175934492384,0.4514547106491408,0.046546962749144716,0.3504629797545291,0.2783094088271686,0.20570794277064375,0.7299870571145072,0.026151657300823472,0.47053571992281096],\"threshold\":8.56096975117539},\"outNerves\":[]}"; - //2 0.6 - public static final String DATA7 = "{\"borderMap\":{},\"depthNerves\":[],\"dymNerveStudies\":[{\"list\":[0.46173316081373994,0.4486734095170666,0.5029883665752177,0.597600986928206,0.4086387873977577,0.8779142340400046,0.16378077953004444,0.40582618886283484,0.32552136225232164],\"threshold\":0.2562632844306175},{\"list\":[0.7773693672054663,0.4998032282747368,0.5655034730629183,0.07366584261304943,0.9072008562364543,0.636108878788075,0.34388911329160443,0.057250457882118355,0.14325548820175782],\"threshold\":0.2719773200084111},{\"list\":[0.44084568625407994,0.9036050484740112,0.35363401279417217,0.44929011369320904,0.15355220827685778,0.7038226814943652,0.035940861653564915,0.11030056068876015,0.16106743745708696],\"threshold\":0.4858929366389904},{\"list\":[0.573021920573834,0.36173948006294054,0.4851225558555259,0.6551851006862296,0.02350569383822143,0.22903995583183123,0.7866925330329656,0.5370829087777349,0.314080216017122],\"threshold\":0.1522300406859472}],\"dymOutNerveStudy\":{\"list\":[0.9732205668914665,0.010102049212183939,0.5626877976156922,0.13973973457906597,0.684161397063244,0.19497578735439747,0.2814815486171073,0.5839054007704529,0.2943331072996984],\"threshold\":1.246060142517065},\"outNerves\":[]}"; - // 4, 0.5 - public static final String DATA8 = "{\"avg\":0.688330945,\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.39899388824098486,2:0.32960557837442445,3:0.11266893828788044,4:0.5966588542457621,5:0.8179231937404853,6:1.0721460686389899,7:1.0535891617717308,8:-0.06708300756161786,9:0.6009303335371129},\"threshold\":0.3290672343833506},{\"dendrites\":{1:1.3131906569610412,2:0.39871140962159307,3:0.7820258043718898,4:1.034355754544882,5:0.5413285370333182,6:0.43386879731916006,7:0.031864849924297035,8:0.7843558005305893,9:0.4116169383576065},\"threshold\":0.20559307045629807},{\"dendrites\":{1:0.6358419862747227,2:0.4530510417028857,3:0.2255410676375776,4:-0.017831134890761744,5:-0.02150431315611135,6:-0.028736773936412264,7:1.2450035317911803,8:1.074253921713497,9:0.918590629404905},\"threshold\":0.8883830034151425},{\"dendrites\":{1:0.5658367413800204,2:0.18612855962077635,3:0.806830323516408,4:0.6799853394843707,5:0.09889604274593422,6:0.8768940882540113,7:0.742289663475406,8:0.42638480668573914,9:0.41647395846908947},\"threshold\":0.788656434678499},{\"dendrites\":{1:0.43248363561359304,2:0.9590108074571237,3:0.9229651983885123,4:0.4200120632806405,5:0.6533790829834876,6:0.6781192483071677,7:0.08247248144556245,8:0.4320728382687308,9:1.4722551124016996},\"threshold\":0.31889293915658534},{\"dendrites\":{1:0.17172269620555847,2:0.9176663823616902,3:0.8655630018192855,4:0.7583740780448002,5:1.1568602295052346,6:0.7773427957347633,7:0.8126874983922108,8:0.8001733341539945,9:0.32636818856414956},\"threshold\":0.10454426811850605},{\"dendrites\":{1:0.08756758803947876,2:0.6538395054432116,3:0.73383794136427,4:0.7500918933070371,5:0.2712898623819152,6:0.9964333100606054,7:1.05969231660771,8:1.1116930140829318,9:0.6177717722693132},\"threshold\":0.46011232402916363},{\"dendrites\":{1:1.1507434297061867,2:0.7392385210465305,3:0.5945545686558946,4:1.158229484463775,5:0.28028992922774626,6:0.9529038312573855,7:0.04622437006440129,8:-0.010149848564122255,9:0.330536538292763},\"threshold\":0.32962923180576936},{\"dendrites\":{1:0.19680055431783122,2:0.2076887351659502,3:0.3169857286704577,4:0.6821437889749971,5:0.6103718441019571,6:0.8828003352592116,7:0.7251770426009678,8:0.981527248001705,9:0.5512698914155161},\"threshold\":0.47359079594468934}],[{\"dendrites\":{1:0.2849648255333415,2:0.16454599222972566,3:0.6549650003781033,4:0.30677169706479096,5:0.9768509355218115,6:0.6968191007506185,7:0.28075534873191027,8:0.514605686262016,9:0.7844513096736475},\"threshold\":1.1022596744782691},{\"dendrites\":{1:0.7886998790918762,2:0.9728921871099554,3:0.22191177206143559,4:0.33806425008179297,5:0.20511670885089117,6:0.8524130481561659,7:0.630697343480684,8:0.34877708473495284,9:0.19412360109569735},\"threshold\":0.9692894043364393},{\"dendrites\":{1:0.15278051082535848,2:0.9616898709308044,3:0.16836605153322617,4:0.2174772192404885,5:0.7862577734632401,6:0.7455905352623635,7:0.22837277734617956,8:0.7377199258818403,9:0.262888555679365},\"threshold\":0.24500664530411237},{\"dendrites\":{1:0.5781864971975521,2:1.0121857846457798,3:0.16094683897028053,4:0.9219013140299144,5:0.16137728606113882,6:0.36422992082281663,7:0.6904113722556231,8:0.5143078636191872,9:0.47472349074814046},\"threshold\":-0.09299787254781887},{\"dendrites\":{1:0.8994959627929455,2:0.5938200656996768,3:0.6325451254250231,4:0.647275004712014,5:0.7905613028420317,6:0.31259575764664593,7:0.35912159305875874,8:0.6856656755407313,9:0.48176342379685066},\"threshold\":1.1980607257346556},{\"dendrites\":{1:0.8702668942593413,2:0.7499831684031865,3:0.6551111842933962,4:0.31043026544777813,5:0.9390888056236212,6:0.8893106929976472,7:0.26599700778628227,8:0.43192738461529884,9:0.3167663588790644},\"threshold\":1.4778098247745721},{\"dendrites\":{1:1.0500445501570306,2:0.9543879850541988,3:0.6542264679132695,4:0.532764488741532,5:0.5940156087691861,6:0.8599489482575502,7:0.6870543409889751,8:0.5783278800628991,9:0.21526723139755796},\"threshold\":1.4413920481124665},{\"dendrites\":{1:0.6226370892241806,2:0.7555473642733175,3:0.7657088253308317,4:0.32938352002078514,5:1.0246614833708212,6:0.8494264724060984,7:0.9927910601725581,8:0.3586629337091575,9:0.7975477105298318},\"threshold\":1.2019687373515053},{\"dendrites\":{1:0.7914471237575227,2:0.40298416853400904,3:0.5316491485543681,4:0.6646985627577175,5:0.44469635431584803,6:0.9027904766282123,7:0.996752836437721,8:0.18326300478156912,9:0.09913428137336622},\"threshold\":1.0997837904732184}]],\"dnnAvg\":0.0,\"dymNerveStudies\":[],\"dymOutNerveStudy\":{\"list\":[],\"threshold\":0.0},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.7561310927520215,2:0.051387638420168615,3:0.06967965236740019,4:-0.16015728204174906,5:0.5408123437172906,6:0.9877032247008244,7:0.9270448987709509,8:0.7317110240649859,9:0.05694856625141945},\"threshold\":2.3727368747260056},{\"dendrites\":{1:-0.22616996075367432,2:-0.49337369144801224,3:0.09561731246570918,4:0.19665844854471454,5:-0.8221421529589507,6:-0.5633723347716219,7:-0.7610172077909856,8:-0.7499396544646417,9:-0.6200240946004351},\"threshold\":-2.3645896851139265}]}"; + public static final String DATA = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:1.103021931841435,2:0.008117825146474612,3:-0.5801381644735911},\"threshold\":-0.04604396529644694},{\"dendrites\":{1:-0.004998519741717762,2:-0.003483298437174885,3:0.018993261832870787},\"threshold\":-0.32951360179091793},{\"dendrites\":{1:2.870324566654314E-5,2:4.589681105047324E-5,3:1.2456556132035707E-4},\"threshold\":0.8000871050992708},{\"dendrites\":{1:6.67080709848635E-5,2:7.862026359664721E-5,3:6.470033476822349E-5},\"threshold\":0.7896727671522821},{\"dendrites\":{1:-0.0012702614249627026,2:0.0022383690704509207,3:0.31448187463133553},\"threshold\":0.022556503073887072},{\"dendrites\":{1:5.7912831661746086E-5,2:3.717748460880913E-5,3:6.131251509303038E-6},\"threshold\":0.3589157959954072},{\"dendrites\":{1:5.599048901285378E-4,2:-0.0013939893716091176,3:2.938990649131207E-4},\"threshold\":-0.3812454342463484},{\"dendrites\":{1:1.3402498571093426,2:-4.91682893792913E-4,3:-0.9378347908226979},\"threshold\":-0.20796827991402647},{\"dendrites\":{1:4.4564586692496426E-5,2:2.360680253987367E-5,3:2.2157014085313395E-5},\"threshold\":0.2874466546307969}]],\"dnnAvg\":0.0,\"dymNerveStudies\":[],\"dymOutNerveStudy\":{\"list\":[],\"threshold\":0.0},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:-1.2288220610075753,2:0.5438935563121664,3:-0.02703809379002783,4:-0.0266312481289741,5:0.8596619884426345,6:-0.004449306522342083,7:-0.11315306178151219,8:-1.093352358174863,9:-1.216369094309366E-4},\"threshold\":-0.14503806800607366},{\"dendrites\":{1:0.7736596891659404,2:-0.0024548243713413487,3:0.0109603566121264,4:0.010822855591324683,5:0.016520925365228218,6:0.00536667616407971,7:0.5881848872837132,8:1.516661986701985,9:0.004724112705921934},\"threshold\":-0.7485389008811241}]}"; + public static final String DATA2 = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.9156354255387174,2:0.8125274451863921,3:0.3615535454080259,4:0.09515646614224252,5:-0.006167951588132063,6:0.7007758820647632,7:-0.038886123193204766,8:0.998551102091073,9:0.5973498456659254,10:0.015882895797322875,11:0.2583005838751566,12:-0.3021358925679116,13:0.5038595486717854,14:0.5011833836057619,15:0.6917662166563002,16:1.553930506195548,17:0.5917721863801528,18:0.6233111138821827,19:0.525247832842735,20:0.5108182095108328,21:0.5667298274954142,22:0.6372783054515596,23:0.11501654542165579,24:0.9113395266895495,25:-0.2855500400653184,26:0.21757845363903872,27:0.5101614887137298,28:0.01021848581445577,29:0.6030687449247121,30:0.002435697144397292,31:0.24059286620815065,32:1.002087146653553,33:0.6338256478400186,34:0.004779168644007213,35:0.1304141409889401},\"threshold\":0.5836921401870699},{\"dendrites\":{1:0.08625551810031744,2:0.6345759612952547,3:0.3575919001218449,4:0.2871924546354964,5:1.4546055247915937,6:0.03649187465080839,7:0.40869193773696616,8:-0.24001501787087662,9:0.23105324522286141,10:0.696072527493177,11:0.24279571896869998,12:0.504129369852856,13:0.260249860687681,14:0.20356089774590186,15:-0.04047404485375756,16:-0.4308572402320148,17:0.9331233840622011,18:0.12074461550761922,19:0.38957988376240155,20:0.8224834893516982,21:0.19534508218760585,22:1.0204485689897196,23:0.6412341798103814,24:0.5468752031103918,25:0.890842369435221,26:0.03266992361063095,27:0.5747514966140805,28:0.5313643344588567,29:-0.0400826761653666,30:0.5110551740539728,31:0.49201580085643987,32:-0.14466866328118203,33:1.1503021797097346,34:0.4922827967695276,35:0.31012536334285234},\"threshold\":0.602940258012709},{\"dendrites\":{1:0.8103532480426182,2:0.8197678496276032,3:0.7203066163428514,4:0.3850324203912271,5:-0.1372935958257047,6:0.07603101101409447,7:-0.06355765917652192,8:0.38426433618555583,9:0.49721064915976276,10:0.3311465570664806,11:0.8225429588932153,12:0.11344817980368907,13:0.017241301659374434,14:0.42451080632575433,15:-0.29223026349916414,16:0.515299488722252,17:0.1036358900534614,18:1.0541286443507467,19:0.450876668436343,20:-0.13110839067214874,21:0.14512427971622766,22:-0.24303811142931928,23:0.38210542834526434,24:0.9378076035865255,25:-0.038308119846504216,26:0.8447893036870062,27:1.0160555510261584,28:0.17150197545074547,29:0.18954955271778634,30:0.7236331579889875,31:0.6459034107952953,32:0.2924780613174092,33:0.5614308710538785,34:0.22343851639768503,35:0.10197504097286825},\"threshold\":0.11959676208739431},{\"dendrites\":{1:0.9837858419630495,2:0.45424797326162814,3:0.5893916386413408,4:0.4127702832851598,5:-0.0067465517628135345,6:0.6037334350963892,7:0.21176691150789295,8:0.6528833634415865,9:0.7088206843211601,10:0.19559750390154224,11:0.3313176392796089,12:0.861554290733756,13:-0.13910101262667193,14:0.819430667902879,15:0.9592155457639877,16:0.38852300221176134,17:0.9418806452623761,18:0.21116973495051397,19:1.0025392470768941,20:0.1867800385302861,21:0.17065088558464117,22:1.001836573992451,23:0.407559144658943,24:0.7432571230631019,25:0.7749759909746943,26:0.3254788815173017,27:0.3644307069125431,28:0.24912932523294326,29:0.9307041678759556,30:0.699048059614266,31:0.728704552084487,32:0.913943969766506,33:0.5802104781957471,34:0.6573867838531485,35:-0.04321768769880419},\"threshold\":0.4241006108808708},{\"dendrites\":{1:0.19920169441025076,2:0.283905497627178,3:0.690922866830004,4:0.41239608343984385,5:0.4744057296320321,6:0.030631568422444078,7:0.6499170122378747,8:-0.08811933932229582,9:0.10903212095036993,10:0.02458926864699401,11:0.921835491387858,12:0.6175302318420931,13:0.26633796337480325,14:0.3038976335968196,15:-0.15232041199299576,16:0.6349681424513026,17:0.8160043058981271,18:0.8495900937317006,19:0.9580085109476663,20:0.6743276238614023,21:-0.25341457067920964,22:0.025191028965877067,23:0.14677306305999596,24:0.5482296659326563,25:-0.028874022258026356,26:0.3286318410570052,27:0.051188531290815555,28:-0.052605032413628336,29:0.1897969918926036,30:-0.12276949211978622,31:0.16483973543702135,32:1.1810343055554207,33:0.34684602580065005,34:0.7762813829921015,35:0.6858180991892883},\"threshold\":0.14997943028292604},{\"dendrites\":{1:1.0974969151084395,2:0.936967646573873,3:0.39795640786753256,4:0.6402322890977816,5:0.4235845844093391,6:0.7677386113872484,7:0.5961996152534333,8:1.2521757289422184,9:0.4571123579303345,10:0.6361448727632808,11:0.24530754368780872,12:-0.05548152126223768,13:0.44149083806368306,14:0.32674272498608026,15:0.755811640527441,16:0.6747984705118185,17:0.3169864956155609,18:0.5346485128344831,19:0.37463119727580596,20:0.5041963482770885,21:0.3390878707844756,22:0.2696533095790938,23:-0.06118972414932952,24:0.3854038830087774,25:0.4338621752642365,26:0.546503710940206,27:0.261857461595586,28:0.4021994590872773,29:1.3334702096310247,30:0.6158636952839264,31:0.27105580593749395,32:1.061174337637762,33:0.2696890868311552,34:0.8564067556854029,35:0.13520811427252727},\"threshold\":0.6335548635763375},{\"dendrites\":{1:0.04835136137796232,2:-0.12686613242421027,3:0.29637166829430056,4:0.24239594528518588,5:0.6134369761388886,6:0.8608974422845553,7:0.3555939708275826,8:-0.17673327153200372,9:0.20987985717400512,10:0.28434221264693776,11:0.2409307076515411,12:0.46375890629856736,13:0.33196605543509144,14:0.5389882054887085,15:0.7152113524904163,16:0.2616228256933283,17:0.5478744524261299,18:0.349557833469607,19:0.5563688454271275,20:0.29244488310108935,21:-0.22674418274199645,22:0.6028340470378245,23:0.546318250810038,24:0.4873862063999614,25:0.8679487465056529,26:0.12813451400352888,27:0.2129675370736518,28:0.5659760228070683,29:0.27797659313753653,30:0.3189347143655221,31:0.8489647174550218,32:0.6943892965772299,33:0.5302023116100267,34:0.5448209001444516,35:0.15042321133246547},\"threshold\":0.7575553837019298},{\"dendrites\":{1:0.9521559184882041,2:0.8619876679443739,3:0.3010609850191267,4:-0.0344509620673846,5:-0.13759914581506963,6:0.40683592536961516,7:0.04690124151380615,8:1.0173368876184483,9:1.199433904190157,10:0.4020424935128357,11:1.1958338920119842,12:0.05359902926297085,13:0.442506767107261,14:0.7764453647831739,15:-0.08096907617664022,16:1.3753301108977356,17:0.43527810675353035,18:1.1397264549932902,19:0.7905417085543797,20:0.7058375612624342,21:-0.02196427108225332,22:0.15238638798818877,23:0.4882825263529862,24:0.07921604329059662,25:0.278679757741462,26:1.210113345271487,27:1.0993656920048847,28:0.5958992053877409,29:0.4061152733225028,30:0.8584275568372073,31:0.4836873521126818,32:0.5590150412216057,33:1.0279330847860175,34:0.20304021037346687,35:0.9057015731366597},\"threshold\":0.2636878588337292},{\"dendrites\":{1:0.3322458387264257,2:0.8352550103352013,3:0.4067735050592622,4:0.5394489572931047,5:0.737987816959301,6:0.9631207497943103,7:0.2821845920912778,8:0.272401617466448,9:0.663976675476805,10:0.6681964207675661,11:0.3971170903004289,12:0.5357989962983247,13:0.45414120659852764,14:0.6723064702417859,15:0.6582726171317375,16:0.7500572877220858,17:0.3569196121274252,18:0.8122555103066491,19:0.7257151381110599,20:0.3352859260653776,21:-0.024637165566452294,22:0.4524190974573769,23:0.19362832411698944,24:0.24745991191937128,25:0.20575841528270228,26:0.08841266098021185,27:0.05612495088844542,28:0.6476611370144862,29:-0.09643675312783118,30:0.05948708239762503,31:0.8589994302466895,32:0.15953621440855548,33:0.17931218782276984,34:0.4651222837904641,35:0.004389470421472894},\"threshold\":0.6584309718490976}]],\"dnnAvg\":7.554722039,\"dymNerveStudies\":[{\"list\":[0.7420409276352997,0.8209894775060258,0.046279559652834035,0.2936342988849149,0.9239862253994111,0.8279839821942477,0.5566128258076107,0.4631584041045016,0.3250473974710636],\"threshold\":0.752790247857131},{\"list\":[0.6158870331633205,0.45181557957592455,0.9927584363539438,0.2539274540818277,0.3110487406058071,0.8469758106978404,0.5000763100115186,0.4759398013126066,0.004937624215994196],\"threshold\":0.675708942194237},{\"list\":[0.31519447106663656,0.7033543461517842,0.1197621502905899,0.949040645006429,0.5391405760278829,0.913965279996319,0.1803104237409392,0.6413209250564212,0.006057944455254094],\"threshold\":0.2866779367535988}],\"dymOutNerveStudy\":{\"list\":[0.1158193701005863,0.5824115065035881,0.36215110848792853,0.8583226875995783,0.3238312394598135,0.6278868364142066,0.27896792952427796,0.012391816984186454,0.8681656707005733],\"threshold\":0.566356763152684},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.6362626356594226,2:-0.5608378341349095,3:0.3362922496151163,4:-0.1695991697074301,5:0.39865913495868316,6:0.4740429836922996,7:-0.2402634391468057,8:0.18779392729575706,9:-0.1334378297625433},\"threshold\":-1.1128222688220462},{\"dendrites\":{1:-0.3693618239647306,2:0.35723369329162236,3:-0.30735171421731877,4:0.04034420090683381,5:-0.16861236716900796,6:-0.3044638907372062,7:0.3572034137732162,8:-0.2621799230535107,9:0.18654670947721513},\"threshold\":-0.349780825974247}]}"; + public static final String DATA3 = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:-2.5251148565550023,2:-1.003570719561788,3:1.6975644199381885,4:2.5323398672845583,5:2.3874263625058183,6:0.6829118367231888,7:0.49768459879512467,8:-0.6733376780336395,9:0.04984169680754189,10:2.4228409910699296,11:2.293931806969596,12:2.978390554100732,13:1.2709510528209076,14:1.2692679718672784,15:-0.8259767386539492,16:-0.17156203438447973,17:0.3666944848265921,18:2.980321968275187,19:1.7015983651496678,20:1.8473408382445857,21:1.728170076077504,22:-0.7880932530104598,23:0.531807387678715,24:-1.2089155005557692,25:2.248150377783179,26:1.1071807452994082,27:1.2735564404601813,28:1.5874736441275294,29:-0.37461175300010363,30:-1.6084102474115292,31:-0.7816488893441771,32:-0.8190250219655663,33:-0.5818982152806249,34:-1.1371221786980996,35:0.7920002461208991},\"threshold\":0.8352061261650687},{\"dendrites\":{1:-1.6522276708735337,2:-0.06613864863682462,3:2.291349828888748,4:3.064694240209468,5:2.050640563786143,6:0.5999518687352614,7:0.7903336722119232,8:-1.126217250762454,9:0.5935794971223087,10:2.309509840887944,11:2.466390639777298,12:3.6999205913305357,13:0.8990824276554668,14:1.172729845202995,15:-1.0018447495606477,16:-0.32474721113300464,17:0.4017203301446451,18:2.8120948026302894,19:2.427353883387211,20:2.378512430320538,21:0.36029230045478944,22:-0.2082319902169387,23:-0.13095732198671484,24:-0.7827502373935092,25:3.4884827880259257,26:1.1289234373741157,27:0.14469446466435135,28:0.2904599363716831,29:0.9435618905297677,30:-2.4327445232757676,31:-1.8031045509413968,32:-0.907160383180506,33:-1.9344741478017693,34:-1.2821903764754452,35:-0.6519935752361722},\"threshold\":0.8535121001276607},{\"dendrites\":{1:-3.344560889682295,2:-1.7341112161626904,3:2.3596139699252197,4:3.239657616577649,5:2.344073421742823,6:-0.864465349355562,7:0.2735541699007227,8:0.2402292797951271,9:0.43639967249157674,10:2.4999287215176484,11:1.8013124377381158,12:3.2293458570072375,13:-0.21129648785711136,14:1.8134506625820854,15:-0.029742890111701423,16:-0.03958868397310825,17:-0.004150330208522215,18:2.4738643563314717,19:-0.07868741098339904,20:1.5276232809727226,21:0.15585795776565925,22:0.14652532503062396,23:0.32831643366109786,24:-2.4370713424478563,25:3.0722734039144743,26:0.23149201646383044,27:-0.2943333628750922,28:0.5119390145367937,29:2.001183649617545,30:-2.4218442553955324,31:-0.9225115346359314,32:-2.737322631909422,33:-1.7736793864192444,34:-2.9097909323698894,35:-0.8578230733485318},\"threshold\":1.078532015943764},{\"dendrites\":{1:-0.8477798393080196,2:0.21332046651859068,3:1.0258367675925057,4:1.649329778687257,5:1.8465146353715067,6:0.3906381755535643,7:0.2209909475163917,8:0.1514609569966888,9:0.6255969447705335,10:1.6081713547038645,11:1.1215225942963716,12:1.8316617784323705,13:1.595817496096903,14:1.0910125109818853,15:0.7376059203361619,16:0.2984918453155582,17:1.3683391833365663,18:1.7607020321715425,19:1.620574846109713,20:1.5004549425317233,21:0.7870799209105356,22:0.026365763470332794,23:0.38990155938616433,24:0.6378761158573902,25:2.3056381961567896,26:0.742505237106305,27:0.9592386015797898,28:0.9149948619578854,29:0.6055710920012422,30:0.07298587945857254,31:0.14727598891741298,32:0.5104145864654174,33:0.460903877540078,34:0.15775436764003303,35:0.5122314711523057},\"threshold\":0.2513895130991223},{\"dendrites\":{1:1.3979681407277194,2:1.2680385211010994,3:-0.5203237939611295,4:0.22522197176455813,5:1.4381306008150425,6:1.6070586718760833,7:0.03530870917635697,8:0.666988586317534,9:0.08776373490830147,10:0.6558350860268168,11:0.3863300416799854,12:-0.2229887531681513,13:1.2953308844291815,14:-0.15770285359511746,15:1.0019326772577208,16:-0.41030177436747534,17:1.5635867170546913,18:-0.021217735234708546,19:1.9461500341104716,20:0.5624545773829133,21:0.5886302799243184,22:0.375616219125374,23:0.034898054730968464,24:3.0251803808242936,25:0.029092339247154896,26:1.2855700740752671,27:1.7393234531521629,28:1.4246154092779797,29:-1.0545201975754914,30:2.7905134560580755,31:2.7601833618716807,32:2.6228424263228733,33:2.765283271752947,34:2.2019516835815764,35:0.28631642536176083},\"threshold\":0.28003347800339207},{\"dendrites\":{1:1.4824488246324559,2:0.7972850502739568,3:1.0402341058838436,4:0.37805384184374585,5:1.6678795726372044,6:2.0848516517652813,7:0.9900994637424818,8:0.7087940119883813,9:0.858654474045366,10:0.8402246928410694,11:1.0347149416212642,12:1.3406112070431528,13:1.9927199243883889,14:1.922919179203566,15:0.14792002433005602,16:-0.001108178227135237,17:1.3080807120398648,18:-0.1227551137335028,19:1.8128961113815738,20:2.172555854498166,21:1.5851428265680558,22:0.126392292515587,23:0.44789533399435566,24:1.2744612608235721,25:0.07230841564866224,26:1.0472412730453946,27:2.0122883490267087,28:1.5007712025961708,29:-1.5421980558994752,30:0.9925766108096791,31:0.09858722313001236,32:1.1963565462608328,33:1.236693569033577,34:1.7345016712410775,35:0.33792344127211743},\"threshold\":0.14861684532254454},{\"dendrites\":{1:0.08638242143547943,2:0.21924340959967578,3:1.6771876303176803,4:1.7098056236095118,5:1.7361554680779092,6:1.7958101373037294,7:0.9708154906865056,8:-0.6685311998859165,9:-0.17777213166988434,10:1.1955138936126433,11:1.4048818680546655,12:2.023863793981773,13:1.8473650995450983,14:1.9792115975026447,15:-0.4291072517876565,16:0.0415443677454331,17:1.3147711725246505,18:1.406520658754414,19:1.7813683400777234,20:2.351753683582591,21:2.1934296791960888,22:-0.6767582357293731,23:0.12679733277307637,24:0.22324794007977083,25:1.694387022869795,26:1.9206812787894265,27:1.5999527389667645,28:1.1436800667807372,29:-1.3963062840247271,30:0.07187543163259891,31:-0.07064120359366607,32:0.576793841990995,33:0.5125815083398187,34:0.22769307746651854,35:0.33449055252691995},\"threshold\":0.688809017120084},{\"dendrites\":{1:1.4384725242890433,2:0.6794328423983236,3:0.7335640766522609,4:0.46623181057022917,5:2.1329191400264293,6:2.1561236399092647,7:1.8088618349433137,8:0.6605029262166586,9:0.08948442958203862,10:1.0545519577197704,11:0.5020219097886542,12:1.22735688117773,13:2.32559171516994,14:1.9275218253220057,15:-0.4568367119186096,16:0.36735536244349787,17:1.2367321547765695,18:-0.19716340711160635,19:1.3688025565828688,20:1.787310721062028,21:2.1625243813640496,22:-0.7508387609807388,23:0.24720375835695765,24:0.34661625418092523,25:0.6874788018222535,26:0.20751542445734728,27:0.8454546479866272,28:1.3646109733502259,29:-0.809396220196817,30:1.4161688048750636,31:0.281482214112868,32:0.6281602859863034,33:-0.010724710544755172,34:1.2965159885481903,35:0.9336101931398596},\"threshold\":0.894234668665694},{\"dendrites\":{1:3.3868627206534057,2:2.0420791921993717,3:0.596431320202737,4:-0.06066359198646402,5:2.94321182192757,6:2.550582117069899,7:1.673525904565925,8:1.099381954900851,9:0.32868856896254,10:0.41404632186707707,11:0.20096386827455698,12:-0.06106408784849395,13:4.001842856113677,14:2.684592507146888,15:0.06577198013726712,16:0.3532685124340426,17:1.8378952202335996,18:-0.41760137499771355,19:2.550175354999244,20:2.0992426850328445,21:2.7231769784467144,22:-1.0159107211841174,23:0.426332924048691,24:2.1021226529831796,25:-0.3358783774497558,26:0.865898783154753,27:2.3755281718048904,28:1.3995367238671061,29:-3.386595781889268,30:3.1305225057475425,31:1.091246176237584,32:2.595887461578013,33:2.886145044942326,34:3.507716675518195,35:1.6789072656661113},\"threshold\":0.08348386400899895}]],\"dnnAvg\":7.7573404347,\"dymNerveStudies\":[{\"list\":[0.36596350757473395,0.9743771456688652,0.3345919443555121,0.09589506895163691,0.8074743350745449,0.1467548122550928,0.5452333225695593,0.4069480147004165,0.8791156996109215],\"threshold\":1.135640286780224},{\"list\":[0.3063677514981339,0.08055922298071905,0.8112435986260279,0.4187719355607248,0.8478974014784709,0.7929100145737933,0.8214723385213866,0.8493723327296772,0.8204199062085575],\"threshold\":0.681236646965117},{\"list\":[0.21179286394891217,0.6770457867219297,0.09202682127488837,0.010991261153074139,0.6767987628791162,0.7207962368447218,0.3054687239646886,0.7590993711418521,0.25354667983273105],\"threshold\":1.869269033696416}],\"dymOutNerveStudy\":{\"list\":[0.6370600231934174,0.858360809944063,0.9836513981530407,0.9904278565486508,0.6126106876433631,0.45533526446338635,0.6231320559052893,0.6071457259551392,0.20775843741304434],\"threshold\":3.126392367978499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:-0.3950961762571424,2:0.8662827700466347,3:-0.03374080599713339,4:0.0709588447712534,5:0.5623920970141028,6:0.5222608442291498,7:0.5199488882449715,8:0.13963339035744346,9:0.8241114854428533},\"threshold\":0.0296611912661046},{\"dendrites\":{1:1.2749426399366968,2:-3.91302584521E-4,3:1.1408513146166548,4:0.7873453477568866,5:0.04576874885891934,6:0.11500176677752398,7:0.7147855891628966,8:0.2018519618190637,9:-0.05537151161506089},\"threshold\":1.091054555158593}]}"; } From 201139e03bd6161ba547c5677d1b70f276592a5e Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Wed, 29 Apr 2020 19:17:37 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E6=B0=B4?= =?UTF-8?q?=E5=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/wlld/MatrixTools/Matrix.java | 1 - src/main/java/org/wlld/config/Kernel.java | 2 + .../wlld/imageRecognition/Convolution.java | 27 +- .../org/wlld/imageRecognition/MaxPoint.java | 13 + .../org/wlld/imageRecognition/Operation.java | 12 + .../org/wlld/imageRecognition/border/LVQ.java | 2 +- .../segmentation/ImageSegmentation.java | 49 ---- .../segmentation/Watershed.java | 231 ++++++++++++++++++ src/main/java/org/wlld/tools/Frequency.java | 2 +- src/test/java/coverTest/CoverTest.java | 105 ++++---- src/test/java/coverTest/FoodTest.java | 53 ++-- src/test/java/org/wlld/ModelData.java | 4 +- 12 files changed, 371 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/org/wlld/imageRecognition/segmentation/ImageSegmentation.java create mode 100644 src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java diff --git a/src/main/java/org/wlld/MatrixTools/Matrix.java b/src/main/java/org/wlld/MatrixTools/Matrix.java index f5a8753..035bf3a 100644 --- a/src/main/java/org/wlld/MatrixTools/Matrix.java +++ b/src/main/java/org/wlld/MatrixTools/Matrix.java @@ -398,7 +398,6 @@ public class Matrix { if (this.x >= x && this.y >= y) { matrix[x][y] = number; } else { - System.out.println("myX==" + this.x + ",myY==" + this.y + ",x==" + x + ",y==" + y); throw new Exception("matrix length too little"); } } diff --git a/src/main/java/org/wlld/config/Kernel.java b/src/main/java/org/wlld/config/Kernel.java index 5fe4363..a7f3d44 100644 --- a/src/main/java/org/wlld/config/Kernel.java +++ b/src/main/java/org/wlld/config/Kernel.java @@ -8,6 +8,8 @@ public class Kernel { private static final String Horizontal_Number = "[-1,-2,-1]#[0,0,0]#[1,2,1]#";//横卷积核 private static final String All_Number = "[1,-2,1]#[-2,4,-2]#[1,-2,1]#";//角卷积 private static final String All_Number2 = "[-1,0,-1]#[0,4,0]#[-1,0,-1]#"; + public static final int rainNub = 10;//分水岭初始降雨点的数量 + public static final int th = 150;//分水岭灰度阈值 public static Matrix Vertical; public static Matrix Horizontal; public static Matrix All; diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index 6e62f50..13388c0 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -40,7 +40,7 @@ public class Convolution extends Frequency { return matrix; } - private List regionThreeChannelMatrix(ThreeChannelMatrix threeChannelMatrix, int size) { + private List regionThreeChannelMatrix(ThreeChannelMatrix threeChannelMatrix, int size) { List threeChannelMatrixList = new ArrayList<>(); Matrix matrixRAll = threeChannelMatrix.getMatrixR(); Matrix matrixGAll = threeChannelMatrix.getMatrixG(); @@ -62,7 +62,18 @@ public class Convolution extends Frequency { return threeChannelMatrixList; } - public List> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub +// public static void main(String[] args) throws Exception { +// Picture picture = new Picture(); +// for (int i = 1; i < 10; i++) { +// ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai/a" + i + ".jpg"); +// ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai/b" + i + ".jpg"); +// kc(threeChannelMatrix1, 2, 3, 40); +// kc(threeChannelMatrix2, 2, 3, 40); +// System.out.println("============================================"); +// } +// } + + public List> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub , int regionSize) throws Exception { RGBSort rgbSort = new RGBSort(); List> features = new ArrayList<>(); @@ -100,13 +111,13 @@ public class Convolution extends Frequency { for (int t = 0; t < dm.length; t++) { dm[t] = rgbNorms.get(t).getNorm(); } - //System.out.println(Arrays.toString(dm)); + System.out.println(Arrays.toString(dm)); features.add(feature); } return features; } - public List> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub + public List> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub , int regionSize) throws Exception { Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); @@ -117,7 +128,7 @@ public class Convolution extends Frequency { RGBSort rgbSort = new RGBSort(); int x = matrixR.getX(); int y = matrixR.getY(); - meanClustering = new MeanClustering(sqNub); + MeanClustering meanClustering = new MeanClustering(sqNub); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { double[] color = new double[]{matrixR.getNumber(i, j) / 255, matrixG.getNumber(i, j) / 255, matrixB.getNumber(i, j) / 255}; @@ -145,9 +156,9 @@ public class Convolution extends Frequency { for (int i = 0; i < sqNub; i++) { features[i] = rgbNorms.get(i).getNorm(); } - // System.out.println(Arrays.toString(features)); + System.out.println(Arrays.toString(features)); minNorm = ArithUtil.div(minNorm, 2); - return checkImage(matrixR, matrixG, matrixB, minNorm, regionSize, features); + return null;//checkImage(matrixR, matrixG, matrixB, minNorm, regionSize, features); } private List> checkImage(Matrix matrixR, Matrix matrixG, Matrix matrixB, double minNorm, int size @@ -314,7 +325,7 @@ public class Convolution extends Frequency { return myMatrix; } - protected Matrix late(Matrix matrix, int size) throws Exception {//迟化处理 + protected Matrix late(Matrix matrix, int size) throws Exception {//迟化处理 int xn = matrix.getX(); int yn = matrix.getY(); int x = xn / size;//求导后矩阵的行数 diff --git a/src/main/java/org/wlld/imageRecognition/MaxPoint.java b/src/main/java/org/wlld/imageRecognition/MaxPoint.java index 02d0c47..f0edf8e 100644 --- a/src/main/java/org/wlld/imageRecognition/MaxPoint.java +++ b/src/main/java/org/wlld/imageRecognition/MaxPoint.java @@ -6,6 +6,16 @@ import org.wlld.i.OutBack; public class MaxPoint implements OutBack { private int id; private double point = -1; + private int pid = 0;//指定ID的概率 + private double pPoint = 0; + + public void setPid(int pid) { + this.pid = pid; + } + + public double getpPoint() { + return pPoint; + } public void setTh(double th) { point = th; @@ -17,6 +27,9 @@ public class MaxPoint implements OutBack { @Override public void getBack(double out, int id, long eventId) { + if (pid > 0 && id == pid) { + pPoint = out; + } if (out > point) { point = out; this.id = id; diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index dd1f9cb..04a3429 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -643,6 +643,17 @@ public class Operation {//进行计算 return iou; } + public double toSeeById(Matrix matrix, int id) throws Exception {//返回某一个分类的概率 + intoConvolutionNetwork(2, matrix, templeConfig.getConvolutionNerveManager().getSensoryNerves(), + false, 0, matrixBack); + List list = getFeature(matrixBack.getMatrix()); + MaxPoint maxPoint = new MaxPoint(); + maxPoint.setPid(id); + long t = IdCreator.get().nextId(); + intoDnnNetwork(t, list, templeConfig.getSensoryNerves(), false, null, maxPoint); + return maxPoint.getpPoint(); + } + //图像视觉 Accuracy 模式 public int toSee(Matrix matrix) throws Exception { if (templeConfig.getStudyPattern() == StudyPattern.Accuracy_Pattern) { @@ -685,6 +696,7 @@ public class Operation {//进行计算 for (Map.Entry entry : matrixK.entrySet()) { Matrix matrix = entry.getValue(); double dist = MatrixOperation.getEDist(matrix, myVector); + System.out.println("距离===" + dist + ",类别==" + entry.getKey()); if (minDist == 0 || dist < minDist) { minDist = dist; id = entry.getKey(); diff --git a/src/main/java/org/wlld/imageRecognition/border/LVQ.java b/src/main/java/org/wlld/imageRecognition/border/LVQ.java index 877879b..21f1114 100644 --- a/src/main/java/org/wlld/imageRecognition/border/LVQ.java +++ b/src/main/java/org/wlld/imageRecognition/border/LVQ.java @@ -16,7 +16,7 @@ public class LVQ { private int typeNub;//原型聚类个数,即分类个数(需要模型返回) private MatrixBody[] model;//原型向量(需要模型返回) private List matrixList = new ArrayList<>(); - private double studyPoint = 0.1;//量化学习率 + private double studyPoint = 0.01;//量化学习率 private int length;//向量长度(需要返回) private boolean isReady = false; private int lvqNub; diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/ImageSegmentation.java b/src/main/java/org/wlld/imageRecognition/segmentation/ImageSegmentation.java deleted file mode 100644 index 44d85a0..0000000 --- a/src/main/java/org/wlld/imageRecognition/segmentation/ImageSegmentation.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.wlld.imageRecognition.segmentation; - -import org.wlld.MatrixTools.Matrix; -import org.wlld.imageRecognition.ThreeChannelMatrix; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author lidapeng - * @description 阈值分区 - * @date 10:25 上午 2020/1/13 - */ -public class ImageSegmentation { - private Matrix matrixR; - private Matrix matrixG; - private Matrix matrixB; - private Map regionBodyList = new HashMap<>(); - private int id = 1; - - public ImageSegmentation(ThreeChannelMatrix threeChannelMatrix) throws Exception { - matrixR = threeChannelMatrix.getMatrixR(); - matrixG = threeChannelMatrix.getMatrixG(); - matrixB = threeChannelMatrix.getMatrixB(); - int x = matrixR.getX(); - int y = matrixR.getY(); - for (int i = 0; i < x; i++) { - for (int j = 0; j < y; j++) { - double r = matrixR.getNumber(i, j); - double g = matrixG.getNumber(i, j); - double b = matrixB.getNumber(i, j); - - } - } - } - - public int getMin(double[] array) { - double min = array[0]; - int minIdx = 0; - for (int i = 1; i < array.length; i++) { - if (array[i] < min) { - minIdx = i; - min = array[i]; - } - } - return minIdx; - } - -} diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java new file mode 100644 index 0000000..647fc8c --- /dev/null +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -0,0 +1,231 @@ +package org.wlld.imageRecognition.segmentation; + +import org.wlld.MatrixTools.Matrix; +import org.wlld.config.Kernel; +import org.wlld.imageRecognition.border.FrameBody; + +import java.util.*; + +/** + * @author lidapeng + * @description 分水岭 + * @date 10:25 上午 2020/1/13 + */ +public class Watershed { + private Matrix matrix;//灰度图像 + private Matrix rainfallMap;//降雨图 + private int rainNub = Kernel.rainNub;//默认降雨点的数量 + private int th = Kernel.th;//灰度阈值 + private List pointList = new ArrayList<>(); + private int xMax; + private int yMax; + + class Point { + private int x; + private int y; + private boolean isLow;//已经到最低处了 + private boolean isFull;//已经满了 + } + + public Watershed(Matrix matrix) throws Exception { + if (matrix != null) { + this.matrix = matrix; + rainfallMap = new Matrix(matrix.getX(), matrix.getY()); + xMax = rainfallMap.getX() - 1; + yMax = rainfallMap.getY() - 1; + } else { + throw new Exception("matrix is null"); + } + } + + private double[] getPixels(int x, int y) throws Exception { + //八方向取值 + double left = -1;//左边 + double leftTop = -1;//左上 + double leftBottom = -1;//左下 + double right = -1;//右边 + double rightTop = -1;//右上 + double rightBottom = -1;//右下 + double top = -1;//上边 + double bottom = -1;//下边 + if (x == 0) { + top = 255; + leftTop = 255; + rightTop = 255; + } + if (y == 0) { + leftTop = 255; + left = 255; + leftBottom = 255; + } + if (x == xMax) { + leftBottom = 255; + bottom = 255; + rightBottom = 255; + } + if (y == yMax) { + rightTop = 255; + right = 255; + rightBottom = 255; + } + if (top == -1 && rainfallMap.getNumber(x - 1, y) == 0) { + top = matrix.getNumber(x - 1, y); + } + if (left == -1 && rainfallMap.getNumber(x, y - 1) == 0) { + left = matrix.getNumber(x, y - 1); + } + if (bottom == -1 && rainfallMap.getNumber(x + 1, y) == 0) { + bottom = matrix.getNumber(x + 1, y); + } + if (right == -1 && rainfallMap.getNumber(x, y + 1) == 0) { + right = matrix.getNumber(x, y + 1); + } + if (leftTop == -1 && rainfallMap.getNumber(x - 1, y - 1) == 0) { + leftTop = matrix.getNumber(x - 1, y - 1); + } + if (leftBottom == -1 && rainfallMap.getNumber(x + 1, y - 1) == 0) { + leftBottom = matrix.getNumber(x + 1, y - 1); + } + if (rightTop == -1 && rainfallMap.getNumber(x - 1, y + 1) == 0) { + rightTop = matrix.getNumber(x - 1, y + 1); + } + if (rightBottom == -1 && rainfallMap.getNumber(x + 1, y + 1) == 0) { + rightBottom = matrix.getNumber(x + 1, y + 1); + } + return new double[]{top, left, bottom, right, leftTop, leftBottom, rightBottom, rightTop}; + } + + private int[] rain(int x, int y, boolean isFirst) throws Exception {//先往下降,直到不能再降了为止 + //有两种情况停止:1,最小值是自身。2,周围已经灌满水了,包括自身 + double[] pixels = getPixels(x, y); + int[] point = new int[8]; + double mySelf = matrix.getNumber(x, y); + int index = getMinIndex(pixels, mySelf);//最低点下标 + //System.out.println("x==" + x + "y==" + y + ",arrays==" + Arrays.toString(pixels) + ",index==" + index); + int row; + int column; + if (index > 0) {//存在可向下蔓延的点 + for (int i = 0; i < 8; i++) { + int t = index & (1 << i); + if (t > 0) { + row = x; + column = y; + switch (i) { + case 0://上 + row = x - 1; + break; + case 1://左 + column = y - 1; + break; + case 2://下 + row = x + 1; + break; + case 3://右 + column = y + 1; + break; + case 4://左上 + column = y - 1; + row = x - 1; + break; + case 5://左下 + column = y - 1; + row = x + 1; + break; + case 6://右下 + column = y + 1; + row = x + 1; + break; + case 7://右上 + column = y + 1; + row = x - 1; + break; + } + int pixel = row << 12 | column; + //等待继续往下沉降的点 + point[i] = pixel; + //System.out.println("y===" + y); + //降雨图修改 + rainfallMap.setNub(row, column, 1); + } + } + } else {//我自己就是最小了 + + } + return point; + } + + private void pull(List list, int[] points) { + for (int point : points) { + if (point != 0) { + list.add(point); + } + } + } + + private void fall(int i, int j) throws Exception { + List list = new ArrayList<>(); + list.add((i << 12) | j); + boolean isFirst = true; + do { + List list2 = new ArrayList<>(); + for (int pixel : list) { + int x = pixel >> 12; + int y = pixel & 0xfff; + int[] nodes = rain(x, y, isFirst); + isFirst = false; + pull(list2, nodes); + } + list = list2; + } while (list.size() > 0); + + } + + public void rainfall() throws Exception {//开始降雨 + int x = matrix.getX(); + int y = matrix.getY(); + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + if (rainfallMap.getNumber(i, j) == 0) {//进行降雨 + fall(i, j); + } + } + } + //进行区域提取 + int xSize = x / 30; + int ySize = y / 30; + System.out.println("xSize==" + xSize + ",ySize==" + ySize); + sigmaPixel(xSize, ySize); + } + + private void sigmaPixel(int xSize, int ySize) throws Exception { + int x = matrix.getX(); + int y = matrix.getY(); + int size = xSize * ySize; + for (int i = 0; i <= x - xSize; i += xSize) { + for (int j = 0; j <= y - ySize; j += ySize) { + Matrix myMatrix = rainfallMap.getSonOfMatrix(i, j, xSize, ySize); + int sigma = 0; + for (int t = 0; t < xSize; t++) { + for (int f = 0; f < ySize; f++) { + if (myMatrix.getNumber(t, f) > 0.1) { + sigma++; + } + } + } + double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标 + System.out.println("cover==" + cover + ",x==" + i + ",y==" + j); + } + } + } + + private int getMinIndex(double[] array, double mySelf) {//获取最小值 + int minIdx = 0; + for (int i = 0; i < array.length; i++) { + double nub = array[i]; + if (nub > -1 && nub < mySelf) { + minIdx = minIdx | (1 << i); + } + } + return minIdx; + } +} diff --git a/src/main/java/org/wlld/tools/Frequency.java b/src/main/java/org/wlld/tools/Frequency.java index aa4fa69..6a41a20 100644 --- a/src/main/java/org/wlld/tools/Frequency.java +++ b/src/main/java/org/wlld/tools/Frequency.java @@ -14,7 +14,7 @@ public abstract class Frequency {//统计频数 return allNub; } - public double getEDist(double[] x1, double[] x2) {//返回两个等长数组之间的欧式距离 + public static double getEDist(double[] x1, double[] x2) {//返回两个等长数组之间的欧式距离 double[] y = new double[x1.length]; for (int i = 0; i < y.length; i++) { y[i] = x1[i] - x2[i]; diff --git a/src/test/java/coverTest/CoverTest.java b/src/test/java/coverTest/CoverTest.java index e1ee301..4026955 100644 --- a/src/test/java/coverTest/CoverTest.java +++ b/src/test/java/coverTest/CoverTest.java @@ -23,8 +23,19 @@ import java.util.Map; */ public class CoverTest { public static void main(String[] args) throws Exception { - cover2("D:\\pic\\6/4.jpg"); - //test(null, 2, 2, 20); +// TempleConfig templeConfig = new TempleConfig(); +// templeConfig.setClassifier(Classifier.DNN); +// templeConfig.setTh(0); +// templeConfig.setSoftMax(true); +// templeConfig.init(StudyPattern.Accuracy_Pattern, false, 640, 480, 2); +// ModelParameter modelParameter = JSON.parseObject(ModelData.DATA3, ModelParameter.class); +// templeConfig.insertModel(modelParameter); +// Operation operation = new Operation(templeConfig); +// for (int i = 1; i < 100; i++) { +// cover2(operation, "D:\\pic\\6\\a/a" + i + ".jpg"); +// } + //test(null, 2, 3, 40, "c", 3); + cover(); } public static void insertModel(String model) throws Exception {//注入模型 @@ -43,47 +54,50 @@ public class CoverTest { //覆盖率计算,计算以前,内存中已经注入过模型了 TempleConfig templeConfig = new TempleConfig(); templeConfig.setSensoryNerveNub(3); - //templeConfig.setSoftMax(true); - templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 2); + templeConfig.setSoftMax(true); + templeConfig.setDeep(2); + templeConfig.setHiddenNerveNub(9); + templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4); ModelParameter modelParameter = JSONObject.parseObject(ModelData.DATA, ModelParameter.class); templeConfig.insertModel(modelParameter); return new Operation(templeConfig);//初始化运算类 } - public static void test(Operation operation, int poolSize, int sqlNub, int regionSize, String url) throws Exception { + public static void test(Operation operation, int poolSize, int sqlNub, int regionSize, + String name, int t) throws Exception { Picture picture = new Picture(); - int allNub = 0; int wrong = 0; if (operation == null) { operation = getModel(); } - ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(url); - Map map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); - for (Map.Entry entry : map1.entrySet()) { - int key = entry.getKey(); - double value = entry.getValue(); - System.out.println("key===" + key + ",value==" + value); + for (int i = 1; i < 100; i++) { + String na = "D:\\share\\cai/" + name + i + ".jpg"; + //System.out.println("name======================" + na); + ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na); + Map map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); + int id = 0; + double point = 0; + for (Map.Entry entry : map1.entrySet()) { + int key = entry.getKey(); + double value = entry.getValue(); + // System.out.println("key==" + key + ",value==" + value); + if (value > point) { + point = value; + id = key; + } + } + if (id != t) { + wrong++; + } } - + System.out.println("错误率:" + wrong + "%"); } - public static void cover2(String url) throws Exception { + public static void cover2(Operation operation, String url) throws Exception { Picture picture = new Picture(); - TempleConfig templeConfig = new TempleConfig(); - templeConfig.setClassifier(Classifier.DNN); - templeConfig.setTh(0.9); - templeConfig.setSoftMax(true); - templeConfig.init(StudyPattern.Accuracy_Pattern, false, 640, 480, 2); - ModelParameter modelParameter = JSON.parseObject(ModelData.DATA3, ModelParameter.class); - templeConfig.insertModel(modelParameter); - Operation operation = new Operation(templeConfig); Matrix matrix = picture.getImageMatrixByLocal(url); - int type = operation.toSee(matrix); - if (type != 1) {//不是扰动 - test(null, 2, 3, 18, url); - } else {//是扰动 - System.out.println("是扰动===="); - } + double type = operation.toSeeById(matrix, 1); + System.out.println("type==" + type); } public static void cover() throws Exception { @@ -94,30 +108,31 @@ public class CoverTest { //初始化模板 注意 width height参数是你训练图片的实际尺寸需要改,其他不用动 //创建运算类进行标注 templeConfig.isShowLog(true); - templeConfig.setStudyPoint(0.01);//不动 - //templeConfig.setSoftMax(true); + templeConfig.setStudyPoint(0.005);//不动 + templeConfig.setSoftMax(true); //templeConfig.setDeep(2); - //templeConfig.setHiddenNerveNub(12); - templeConfig.setSensoryNerveNub(3); + //templeConfig.setHiddenNerveNub(9); + templeConfig.setSensoryNerveNub(4); templeConfig.setRzType(RZ.L1);//不动//3 18 - templeConfig.setlParam(0.015);//不动 - templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 2); + templeConfig.setlParam(0.01);//不动 + templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4); Operation operation = new Operation(templeConfig); - for (int i = 1; i < 45; i++) { + for (int i = 1; i < 100; i++) { Map matrixMap = new HashMap<>(); - //桔梗覆盖 - ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic\\test/b" + i + ".jpg"); - //土壤扰动 - ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\pic\\test/c" + i + ".jpg"); - //ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\pic\\test/d" + i + ".jpg"); - //ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\jie/4.jpg"); - matrixMap.put(1, threeChannelMatrix1);//桔梗覆盖 - matrixMap.put(2, threeChannelMatrix2);//土壤扰动 - //matrixMap.put(3, threeChannelMatrix3);//白地 - operation.coverStudy(matrixMap, 2, 3, 18, 2); + ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai/a" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai/b" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\cai/c" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai/d" + i + ".jpg"); + + matrixMap.put(1, threeChannelMatrix1); + matrixMap.put(2, threeChannelMatrix2); + matrixMap.put(3, threeChannelMatrix3); + matrixMap.put(4, threeChannelMatrix4); + operation.coverStudy(matrixMap, 5, 4, 10, 2); } ModelParameter modelParameter = templeConfig.getModel(); String model = JSON.toJSONString(modelParameter); System.out.println(model); + // test(operation, 2, 3, 40, "d", 4); } } diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index 1f6acb9..ee7c340 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -6,13 +6,22 @@ import org.wlld.config.Classifier; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; import org.wlld.imageRecognition.*; +import org.wlld.imageRecognition.segmentation.Watershed; import org.wlld.nerveEntity.ModelParameter; import org.wlld.tools.ArithUtil; public class FoodTest { public static void main(String[] args) throws Exception { - food(); + //food(); + rain(); + } + + public static void rain() throws Exception {//降雨 + Picture picture = new Picture(); + Matrix matrix = picture.getImageMatrixByLocal("D:\\share\\cai/i1.jpg"); + Watershed watershed = new Watershed(matrix); + watershed.rainfall(); } public static void food() throws Exception { @@ -21,36 +30,38 @@ public class FoodTest { templeConfig.setClassifier(Classifier.DNN); templeConfig.isShowLog(true); templeConfig.setSoftMax(true); - //templeConfig.setStudyPoint(0.01); + templeConfig.setTh(0); + //templeConfig.setMatrixWidth(5); + templeConfig.setStudyPoint(0.02); templeConfig.setRzType(RZ.L1); - templeConfig.setlParam(0.015);//0.015 + templeConfig.setlParam(0.016);//0.015 templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 480, 2); Operation operation = new Operation(templeConfig); // 一阶段 - for (int j = 0; j < 5; j++) { - for (int i = 1; i < 45; i++) {//一阶段 + for (int j = 0; j < 2; j++) { + for (int i = 1; i < 233; i++) {//一阶段 System.out.println("study1===================" + i); //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\pic\\6\\b/b" + i + ".jpg"); operation.learning(a, 1, false); operation.learning(b, 2, false); } } - //二阶段 - for (int i = 1; i < 45; i++) { + // 二阶段 + for (int i = 1; i < 233; i++) { System.out.println("avg==" + i); - Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\pic\\6\\b/b" + i + ".jpg"); operation.normalization(a, templeConfig.getConvolutionNerveManager()); operation.normalization(b, templeConfig.getConvolutionNerveManager()); } templeConfig.getNormalization().avg(); - for (int j = 0; j < 10; j++) { - for (int i = 1; i < 45; i++) { + for (int j = 0; j < 5; j++) { + for (int i = 1; i < 233; i++) { System.out.println("j==" + j + ",study2==================" + i); - Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\pic\\6\\b/b" + i + ".jpg"); operation.learning(a, 1, true); operation.learning(b, 2, true); } @@ -58,19 +69,14 @@ public class FoodTest { templeConfig.finishStudy();//结束学习 int wrong = 0; int allNub = 0; - for (int i = 1; i <= 44; i++) { + for (int i = 1; i <= 232; i++) { //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\rao/c" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\rao/f" + i + ".jpg"); - allNub += 2; + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); + allNub++; int an = operation.toSee(a); if (an != 1) { wrong++; } - int bn = operation.toSee(b); - if (bn != 2) { - wrong++; - } } double wrongPoint = ArithUtil.div(wrong, allNub); System.out.println("错误率:" + (wrongPoint * 100) + "%"); @@ -78,4 +84,5 @@ public class FoodTest { String model = JSON.toJSONString(modelParameter); System.out.println(model); } + } diff --git a/src/test/java/org/wlld/ModelData.java b/src/test/java/org/wlld/ModelData.java index 5828879..c5ce1aa 100644 --- a/src/test/java/org/wlld/ModelData.java +++ b/src/test/java/org/wlld/ModelData.java @@ -7,7 +7,7 @@ package org.wlld; */ public class ModelData { //860第一遍 - public static final String DATA = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:1.103021931841435,2:0.008117825146474612,3:-0.5801381644735911},\"threshold\":-0.04604396529644694},{\"dendrites\":{1:-0.004998519741717762,2:-0.003483298437174885,3:0.018993261832870787},\"threshold\":-0.32951360179091793},{\"dendrites\":{1:2.870324566654314E-5,2:4.589681105047324E-5,3:1.2456556132035707E-4},\"threshold\":0.8000871050992708},{\"dendrites\":{1:6.67080709848635E-5,2:7.862026359664721E-5,3:6.470033476822349E-5},\"threshold\":0.7896727671522821},{\"dendrites\":{1:-0.0012702614249627026,2:0.0022383690704509207,3:0.31448187463133553},\"threshold\":0.022556503073887072},{\"dendrites\":{1:5.7912831661746086E-5,2:3.717748460880913E-5,3:6.131251509303038E-6},\"threshold\":0.3589157959954072},{\"dendrites\":{1:5.599048901285378E-4,2:-0.0013939893716091176,3:2.938990649131207E-4},\"threshold\":-0.3812454342463484},{\"dendrites\":{1:1.3402498571093426,2:-4.91682893792913E-4,3:-0.9378347908226979},\"threshold\":-0.20796827991402647},{\"dendrites\":{1:4.4564586692496426E-5,2:2.360680253987367E-5,3:2.2157014085313395E-5},\"threshold\":0.2874466546307969}]],\"dnnAvg\":0.0,\"dymNerveStudies\":[],\"dymOutNerveStudy\":{\"list\":[],\"threshold\":0.0},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:-1.2288220610075753,2:0.5438935563121664,3:-0.02703809379002783,4:-0.0266312481289741,5:0.8596619884426345,6:-0.004449306522342083,7:-0.11315306178151219,8:-1.093352358174863,9:-1.216369094309366E-4},\"threshold\":-0.14503806800607366},{\"dendrites\":{1:0.7736596891659404,2:-0.0024548243713413487,3:0.0109603566121264,4:0.010822855591324683,5:0.016520925365228218,6:0.00536667616407971,7:0.5881848872837132,8:1.516661986701985,9:0.004724112705921934},\"threshold\":-0.7485389008811241}]}"; + public static final String DATA = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.0020304986725699875,2:0.10379403134255444,3:0.6287738152527322},\"threshold\":-0.013039049858902418},{\"dendrites\":{1:0.009147717193496609,2:0.5171480630674181,3:0.07024321085598545},\"threshold\":0.3835537617870677},{\"dendrites\":{1:0.011602795293701885,2:0.6969887303241205,3:0.029915231070745535},\"threshold\":0.24842710692475475},{\"dendrites\":{1:0.004314648309356629,2:0.2774802794419887,3:0.3044946060426335},\"threshold\":0.5701864607985},{\"dendrites\":{1:1.6311469584806588,2:0.5459078494569916,3:-0.11586056714457237},\"threshold\":0.6658399434484007},{\"dendrites\":{1:0.04237452864183608,2:1.7034579816123145,3:0.22574166595355413},\"threshold\":1.8805515163580113},{\"dendrites\":{1:0.019435718292224964,2:0.5087213529333345,3:0.28672202220038917},\"threshold\":0.46120853942194867},{\"dendrites\":{1:0.5271980845882384,2:0.4729005635595556,3:-0.023195453516951844},\"threshold\":0.00578668268494179},{\"dendrites\":{1:-0.552305748938011,2:0.8475348259423108,3:1.3472703636188004},\"threshold\":1.392151682067366}],[{\"dendrites\":{1:0.25288000241376574,2:0.06450358237186028,3:0.5046347957825427,4:0.21528656235967294,5:0.6939232706227578,6:0.4595750252294177,7:0.49415648249977806,8:0.6459916977916105,9:0.35306303887346807},\"threshold\":0.7004528362367957},{\"dendrites\":{1:0.1645156004370013,2:0.5690293246225958,3:0.7133259777627303,4:0.6131265758028632,5:0.07714440799272212,6:0.14708642006827452,7:0.5003388329552009,8:0.6758274616936393,9:0.3127431896910309},\"threshold\":0.2663373689460049},{\"dendrites\":{1:0.23964800006811435,2:0.5225792788893102,3:0.12930489495140296,4:0.16930119368297783,5:0.7600128194880553,6:0.7376696960376283,7:0.3382812966086453,8:0.7849321091589967,9:0.10991006490009754},\"threshold\":0.5056040454442194},{\"dendrites\":{1:0.041119150156730636,2:0.3346196350559196,3:0.2826249487228152,4:0.1802786962613548,5:0.08643792513466173,6:0.6410798980605507,7:0.7403945395626602,8:0.21567057436725043,9:0.6287072823115364},\"threshold\":0.4588569521222759},{\"dendrites\":{1:0.0011664718434862098,2:0.23756177346551408,3:0.5036776829974416,4:0.7212997504096563,5:-0.29346432073368217,6:0.9448332142896997,7:0.7585392966533047,8:0.002695441947128464,9:1.2705642996587019},\"threshold\":0.9694977930390324},{\"dendrites\":{1:0.10071472235629521,2:0.0022650657200771686,3:0.6468438734018197,4:0.21528424377444566,5:0.20619983100752548,6:0.7198001658633856,7:0.4410560166683465,8:0.3227377659119746,9:0.5115950768156629},\"threshold\":0.5263572012576768},{\"dendrites\":{1:0.7697733418428502,2:0.5124195345888053,3:0.3125834036661561,4:0.37033362631525857,5:0.002649706805399057,6:0.5577243110726287,7:0.045880320471866104,8:0.40960867460214817,9:0.41822833569438583},\"threshold\":0.48228377813513934},{\"dendrites\":{1:0.11281551989751622,2:0.3342903034927963,3:0.3353781904164797,4:-4.378591638446594E-4,5:1.0021597933253101,6:0.7893392484630952,7:0.3649955048651297,8:0.4294334712863012,9:0.10290835810256865},\"threshold\":0.6254716054589782},{\"dendrites\":{1:0.6537306663769156,2:0.3086234737977303,3:0.013895733110138041,4:0.11762090824985005,5:-0.5815895796103001,6:1.337374847787431,7:0.27254311770901773,8:-2.6868162889639E-4,9:1.2801491534316676},\"threshold\":0.7642933853728607}]],\"dnnAvg\":0.0,\"dymNerveStudies\":[],\"dymOutNerveStudy\":{\"list\":[],\"threshold\":0.0},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.01252748740395147,2:0.3510902525503022,3:-0.05376494874511102,4:-0.3174095645136935,5:-0.19895867053482108,6:-0.09713906112316183,7:-0.042606157892249155,8:-0.6365378265660547,9:-0.0890178455802909},\"threshold\":1.031788938492251},{\"dendrites\":{1:0.7672973829093716,2:0.29737599835650413,3:1.1293564390097313,4:-0.06014816479264548,5:-0.7857554443312225,6:0.32760555564057525,7:0.08286304807960662,8:0.7815153927096252,9:-0.8168204332127076},\"threshold\":0.912845723311604},{\"dendrites\":{1:0.4948448701971685,2:0.17912924410374617,3:0.23454899486057917,4:1.0410152721961028,5:0.5560984359423662,6:0.833443989823426,7:0.5974207622212677,8:0.81011956764272,9:0.2994861922578987},\"threshold\":0.702591312798831},{\"dendrites\":{1:-0.013638363105609098,2:-0.012406912345502475,3:-0.0737824571833817,4:0.34277110454831927,5:1.4616563338773294,6:0.3082167282191121,7:0.0053824491469858125,8:-0.008124981504839746,9:1.7877699433796186},\"threshold\":-0.746035157755337}]}"; public static final String DATA2 = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:0.9156354255387174,2:0.8125274451863921,3:0.3615535454080259,4:0.09515646614224252,5:-0.006167951588132063,6:0.7007758820647632,7:-0.038886123193204766,8:0.998551102091073,9:0.5973498456659254,10:0.015882895797322875,11:0.2583005838751566,12:-0.3021358925679116,13:0.5038595486717854,14:0.5011833836057619,15:0.6917662166563002,16:1.553930506195548,17:0.5917721863801528,18:0.6233111138821827,19:0.525247832842735,20:0.5108182095108328,21:0.5667298274954142,22:0.6372783054515596,23:0.11501654542165579,24:0.9113395266895495,25:-0.2855500400653184,26:0.21757845363903872,27:0.5101614887137298,28:0.01021848581445577,29:0.6030687449247121,30:0.002435697144397292,31:0.24059286620815065,32:1.002087146653553,33:0.6338256478400186,34:0.004779168644007213,35:0.1304141409889401},\"threshold\":0.5836921401870699},{\"dendrites\":{1:0.08625551810031744,2:0.6345759612952547,3:0.3575919001218449,4:0.2871924546354964,5:1.4546055247915937,6:0.03649187465080839,7:0.40869193773696616,8:-0.24001501787087662,9:0.23105324522286141,10:0.696072527493177,11:0.24279571896869998,12:0.504129369852856,13:0.260249860687681,14:0.20356089774590186,15:-0.04047404485375756,16:-0.4308572402320148,17:0.9331233840622011,18:0.12074461550761922,19:0.38957988376240155,20:0.8224834893516982,21:0.19534508218760585,22:1.0204485689897196,23:0.6412341798103814,24:0.5468752031103918,25:0.890842369435221,26:0.03266992361063095,27:0.5747514966140805,28:0.5313643344588567,29:-0.0400826761653666,30:0.5110551740539728,31:0.49201580085643987,32:-0.14466866328118203,33:1.1503021797097346,34:0.4922827967695276,35:0.31012536334285234},\"threshold\":0.602940258012709},{\"dendrites\":{1:0.8103532480426182,2:0.8197678496276032,3:0.7203066163428514,4:0.3850324203912271,5:-0.1372935958257047,6:0.07603101101409447,7:-0.06355765917652192,8:0.38426433618555583,9:0.49721064915976276,10:0.3311465570664806,11:0.8225429588932153,12:0.11344817980368907,13:0.017241301659374434,14:0.42451080632575433,15:-0.29223026349916414,16:0.515299488722252,17:0.1036358900534614,18:1.0541286443507467,19:0.450876668436343,20:-0.13110839067214874,21:0.14512427971622766,22:-0.24303811142931928,23:0.38210542834526434,24:0.9378076035865255,25:-0.038308119846504216,26:0.8447893036870062,27:1.0160555510261584,28:0.17150197545074547,29:0.18954955271778634,30:0.7236331579889875,31:0.6459034107952953,32:0.2924780613174092,33:0.5614308710538785,34:0.22343851639768503,35:0.10197504097286825},\"threshold\":0.11959676208739431},{\"dendrites\":{1:0.9837858419630495,2:0.45424797326162814,3:0.5893916386413408,4:0.4127702832851598,5:-0.0067465517628135345,6:0.6037334350963892,7:0.21176691150789295,8:0.6528833634415865,9:0.7088206843211601,10:0.19559750390154224,11:0.3313176392796089,12:0.861554290733756,13:-0.13910101262667193,14:0.819430667902879,15:0.9592155457639877,16:0.38852300221176134,17:0.9418806452623761,18:0.21116973495051397,19:1.0025392470768941,20:0.1867800385302861,21:0.17065088558464117,22:1.001836573992451,23:0.407559144658943,24:0.7432571230631019,25:0.7749759909746943,26:0.3254788815173017,27:0.3644307069125431,28:0.24912932523294326,29:0.9307041678759556,30:0.699048059614266,31:0.728704552084487,32:0.913943969766506,33:0.5802104781957471,34:0.6573867838531485,35:-0.04321768769880419},\"threshold\":0.4241006108808708},{\"dendrites\":{1:0.19920169441025076,2:0.283905497627178,3:0.690922866830004,4:0.41239608343984385,5:0.4744057296320321,6:0.030631568422444078,7:0.6499170122378747,8:-0.08811933932229582,9:0.10903212095036993,10:0.02458926864699401,11:0.921835491387858,12:0.6175302318420931,13:0.26633796337480325,14:0.3038976335968196,15:-0.15232041199299576,16:0.6349681424513026,17:0.8160043058981271,18:0.8495900937317006,19:0.9580085109476663,20:0.6743276238614023,21:-0.25341457067920964,22:0.025191028965877067,23:0.14677306305999596,24:0.5482296659326563,25:-0.028874022258026356,26:0.3286318410570052,27:0.051188531290815555,28:-0.052605032413628336,29:0.1897969918926036,30:-0.12276949211978622,31:0.16483973543702135,32:1.1810343055554207,33:0.34684602580065005,34:0.7762813829921015,35:0.6858180991892883},\"threshold\":0.14997943028292604},{\"dendrites\":{1:1.0974969151084395,2:0.936967646573873,3:0.39795640786753256,4:0.6402322890977816,5:0.4235845844093391,6:0.7677386113872484,7:0.5961996152534333,8:1.2521757289422184,9:0.4571123579303345,10:0.6361448727632808,11:0.24530754368780872,12:-0.05548152126223768,13:0.44149083806368306,14:0.32674272498608026,15:0.755811640527441,16:0.6747984705118185,17:0.3169864956155609,18:0.5346485128344831,19:0.37463119727580596,20:0.5041963482770885,21:0.3390878707844756,22:0.2696533095790938,23:-0.06118972414932952,24:0.3854038830087774,25:0.4338621752642365,26:0.546503710940206,27:0.261857461595586,28:0.4021994590872773,29:1.3334702096310247,30:0.6158636952839264,31:0.27105580593749395,32:1.061174337637762,33:0.2696890868311552,34:0.8564067556854029,35:0.13520811427252727},\"threshold\":0.6335548635763375},{\"dendrites\":{1:0.04835136137796232,2:-0.12686613242421027,3:0.29637166829430056,4:0.24239594528518588,5:0.6134369761388886,6:0.8608974422845553,7:0.3555939708275826,8:-0.17673327153200372,9:0.20987985717400512,10:0.28434221264693776,11:0.2409307076515411,12:0.46375890629856736,13:0.33196605543509144,14:0.5389882054887085,15:0.7152113524904163,16:0.2616228256933283,17:0.5478744524261299,18:0.349557833469607,19:0.5563688454271275,20:0.29244488310108935,21:-0.22674418274199645,22:0.6028340470378245,23:0.546318250810038,24:0.4873862063999614,25:0.8679487465056529,26:0.12813451400352888,27:0.2129675370736518,28:0.5659760228070683,29:0.27797659313753653,30:0.3189347143655221,31:0.8489647174550218,32:0.6943892965772299,33:0.5302023116100267,34:0.5448209001444516,35:0.15042321133246547},\"threshold\":0.7575553837019298},{\"dendrites\":{1:0.9521559184882041,2:0.8619876679443739,3:0.3010609850191267,4:-0.0344509620673846,5:-0.13759914581506963,6:0.40683592536961516,7:0.04690124151380615,8:1.0173368876184483,9:1.199433904190157,10:0.4020424935128357,11:1.1958338920119842,12:0.05359902926297085,13:0.442506767107261,14:0.7764453647831739,15:-0.08096907617664022,16:1.3753301108977356,17:0.43527810675353035,18:1.1397264549932902,19:0.7905417085543797,20:0.7058375612624342,21:-0.02196427108225332,22:0.15238638798818877,23:0.4882825263529862,24:0.07921604329059662,25:0.278679757741462,26:1.210113345271487,27:1.0993656920048847,28:0.5958992053877409,29:0.4061152733225028,30:0.8584275568372073,31:0.4836873521126818,32:0.5590150412216057,33:1.0279330847860175,34:0.20304021037346687,35:0.9057015731366597},\"threshold\":0.2636878588337292},{\"dendrites\":{1:0.3322458387264257,2:0.8352550103352013,3:0.4067735050592622,4:0.5394489572931047,5:0.737987816959301,6:0.9631207497943103,7:0.2821845920912778,8:0.272401617466448,9:0.663976675476805,10:0.6681964207675661,11:0.3971170903004289,12:0.5357989962983247,13:0.45414120659852764,14:0.6723064702417859,15:0.6582726171317375,16:0.7500572877220858,17:0.3569196121274252,18:0.8122555103066491,19:0.7257151381110599,20:0.3352859260653776,21:-0.024637165566452294,22:0.4524190974573769,23:0.19362832411698944,24:0.24745991191937128,25:0.20575841528270228,26:0.08841266098021185,27:0.05612495088844542,28:0.6476611370144862,29:-0.09643675312783118,30:0.05948708239762503,31:0.8589994302466895,32:0.15953621440855548,33:0.17931218782276984,34:0.4651222837904641,35:0.004389470421472894},\"threshold\":0.6584309718490976}]],\"dnnAvg\":7.554722039,\"dymNerveStudies\":[{\"list\":[0.7420409276352997,0.8209894775060258,0.046279559652834035,0.2936342988849149,0.9239862253994111,0.8279839821942477,0.5566128258076107,0.4631584041045016,0.3250473974710636],\"threshold\":0.752790247857131},{\"list\":[0.6158870331633205,0.45181557957592455,0.9927584363539438,0.2539274540818277,0.3110487406058071,0.8469758106978404,0.5000763100115186,0.4759398013126066,0.004937624215994196],\"threshold\":0.675708942194237},{\"list\":[0.31519447106663656,0.7033543461517842,0.1197621502905899,0.949040645006429,0.5391405760278829,0.913965279996319,0.1803104237409392,0.6413209250564212,0.006057944455254094],\"threshold\":0.2866779367535988}],\"dymOutNerveStudy\":{\"list\":[0.1158193701005863,0.5824115065035881,0.36215110848792853,0.8583226875995783,0.3238312394598135,0.6278868364142066,0.27896792952427796,0.012391816984186454,0.8681656707005733],\"threshold\":0.566356763152684},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:0.6362626356594226,2:-0.5608378341349095,3:0.3362922496151163,4:-0.1695991697074301,5:0.39865913495868316,6:0.4740429836922996,7:-0.2402634391468057,8:0.18779392729575706,9:-0.1334378297625433},\"threshold\":-1.1128222688220462},{\"dendrites\":{1:-0.3693618239647306,2:0.35723369329162236,3:-0.30735171421731877,4:0.04034420090683381,5:-0.16861236716900796,6:-0.3044638907372062,7:0.3572034137732162,8:-0.2621799230535107,9:0.18654670947721513},\"threshold\":-0.349780825974247}]}"; - public static final String DATA3 = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:-2.5251148565550023,2:-1.003570719561788,3:1.6975644199381885,4:2.5323398672845583,5:2.3874263625058183,6:0.6829118367231888,7:0.49768459879512467,8:-0.6733376780336395,9:0.04984169680754189,10:2.4228409910699296,11:2.293931806969596,12:2.978390554100732,13:1.2709510528209076,14:1.2692679718672784,15:-0.8259767386539492,16:-0.17156203438447973,17:0.3666944848265921,18:2.980321968275187,19:1.7015983651496678,20:1.8473408382445857,21:1.728170076077504,22:-0.7880932530104598,23:0.531807387678715,24:-1.2089155005557692,25:2.248150377783179,26:1.1071807452994082,27:1.2735564404601813,28:1.5874736441275294,29:-0.37461175300010363,30:-1.6084102474115292,31:-0.7816488893441771,32:-0.8190250219655663,33:-0.5818982152806249,34:-1.1371221786980996,35:0.7920002461208991},\"threshold\":0.8352061261650687},{\"dendrites\":{1:-1.6522276708735337,2:-0.06613864863682462,3:2.291349828888748,4:3.064694240209468,5:2.050640563786143,6:0.5999518687352614,7:0.7903336722119232,8:-1.126217250762454,9:0.5935794971223087,10:2.309509840887944,11:2.466390639777298,12:3.6999205913305357,13:0.8990824276554668,14:1.172729845202995,15:-1.0018447495606477,16:-0.32474721113300464,17:0.4017203301446451,18:2.8120948026302894,19:2.427353883387211,20:2.378512430320538,21:0.36029230045478944,22:-0.2082319902169387,23:-0.13095732198671484,24:-0.7827502373935092,25:3.4884827880259257,26:1.1289234373741157,27:0.14469446466435135,28:0.2904599363716831,29:0.9435618905297677,30:-2.4327445232757676,31:-1.8031045509413968,32:-0.907160383180506,33:-1.9344741478017693,34:-1.2821903764754452,35:-0.6519935752361722},\"threshold\":0.8535121001276607},{\"dendrites\":{1:-3.344560889682295,2:-1.7341112161626904,3:2.3596139699252197,4:3.239657616577649,5:2.344073421742823,6:-0.864465349355562,7:0.2735541699007227,8:0.2402292797951271,9:0.43639967249157674,10:2.4999287215176484,11:1.8013124377381158,12:3.2293458570072375,13:-0.21129648785711136,14:1.8134506625820854,15:-0.029742890111701423,16:-0.03958868397310825,17:-0.004150330208522215,18:2.4738643563314717,19:-0.07868741098339904,20:1.5276232809727226,21:0.15585795776565925,22:0.14652532503062396,23:0.32831643366109786,24:-2.4370713424478563,25:3.0722734039144743,26:0.23149201646383044,27:-0.2943333628750922,28:0.5119390145367937,29:2.001183649617545,30:-2.4218442553955324,31:-0.9225115346359314,32:-2.737322631909422,33:-1.7736793864192444,34:-2.9097909323698894,35:-0.8578230733485318},\"threshold\":1.078532015943764},{\"dendrites\":{1:-0.8477798393080196,2:0.21332046651859068,3:1.0258367675925057,4:1.649329778687257,5:1.8465146353715067,6:0.3906381755535643,7:0.2209909475163917,8:0.1514609569966888,9:0.6255969447705335,10:1.6081713547038645,11:1.1215225942963716,12:1.8316617784323705,13:1.595817496096903,14:1.0910125109818853,15:0.7376059203361619,16:0.2984918453155582,17:1.3683391833365663,18:1.7607020321715425,19:1.620574846109713,20:1.5004549425317233,21:0.7870799209105356,22:0.026365763470332794,23:0.38990155938616433,24:0.6378761158573902,25:2.3056381961567896,26:0.742505237106305,27:0.9592386015797898,28:0.9149948619578854,29:0.6055710920012422,30:0.07298587945857254,31:0.14727598891741298,32:0.5104145864654174,33:0.460903877540078,34:0.15775436764003303,35:0.5122314711523057},\"threshold\":0.2513895130991223},{\"dendrites\":{1:1.3979681407277194,2:1.2680385211010994,3:-0.5203237939611295,4:0.22522197176455813,5:1.4381306008150425,6:1.6070586718760833,7:0.03530870917635697,8:0.666988586317534,9:0.08776373490830147,10:0.6558350860268168,11:0.3863300416799854,12:-0.2229887531681513,13:1.2953308844291815,14:-0.15770285359511746,15:1.0019326772577208,16:-0.41030177436747534,17:1.5635867170546913,18:-0.021217735234708546,19:1.9461500341104716,20:0.5624545773829133,21:0.5886302799243184,22:0.375616219125374,23:0.034898054730968464,24:3.0251803808242936,25:0.029092339247154896,26:1.2855700740752671,27:1.7393234531521629,28:1.4246154092779797,29:-1.0545201975754914,30:2.7905134560580755,31:2.7601833618716807,32:2.6228424263228733,33:2.765283271752947,34:2.2019516835815764,35:0.28631642536176083},\"threshold\":0.28003347800339207},{\"dendrites\":{1:1.4824488246324559,2:0.7972850502739568,3:1.0402341058838436,4:0.37805384184374585,5:1.6678795726372044,6:2.0848516517652813,7:0.9900994637424818,8:0.7087940119883813,9:0.858654474045366,10:0.8402246928410694,11:1.0347149416212642,12:1.3406112070431528,13:1.9927199243883889,14:1.922919179203566,15:0.14792002433005602,16:-0.001108178227135237,17:1.3080807120398648,18:-0.1227551137335028,19:1.8128961113815738,20:2.172555854498166,21:1.5851428265680558,22:0.126392292515587,23:0.44789533399435566,24:1.2744612608235721,25:0.07230841564866224,26:1.0472412730453946,27:2.0122883490267087,28:1.5007712025961708,29:-1.5421980558994752,30:0.9925766108096791,31:0.09858722313001236,32:1.1963565462608328,33:1.236693569033577,34:1.7345016712410775,35:0.33792344127211743},\"threshold\":0.14861684532254454},{\"dendrites\":{1:0.08638242143547943,2:0.21924340959967578,3:1.6771876303176803,4:1.7098056236095118,5:1.7361554680779092,6:1.7958101373037294,7:0.9708154906865056,8:-0.6685311998859165,9:-0.17777213166988434,10:1.1955138936126433,11:1.4048818680546655,12:2.023863793981773,13:1.8473650995450983,14:1.9792115975026447,15:-0.4291072517876565,16:0.0415443677454331,17:1.3147711725246505,18:1.406520658754414,19:1.7813683400777234,20:2.351753683582591,21:2.1934296791960888,22:-0.6767582357293731,23:0.12679733277307637,24:0.22324794007977083,25:1.694387022869795,26:1.9206812787894265,27:1.5999527389667645,28:1.1436800667807372,29:-1.3963062840247271,30:0.07187543163259891,31:-0.07064120359366607,32:0.576793841990995,33:0.5125815083398187,34:0.22769307746651854,35:0.33449055252691995},\"threshold\":0.688809017120084},{\"dendrites\":{1:1.4384725242890433,2:0.6794328423983236,3:0.7335640766522609,4:0.46623181057022917,5:2.1329191400264293,6:2.1561236399092647,7:1.8088618349433137,8:0.6605029262166586,9:0.08948442958203862,10:1.0545519577197704,11:0.5020219097886542,12:1.22735688117773,13:2.32559171516994,14:1.9275218253220057,15:-0.4568367119186096,16:0.36735536244349787,17:1.2367321547765695,18:-0.19716340711160635,19:1.3688025565828688,20:1.787310721062028,21:2.1625243813640496,22:-0.7508387609807388,23:0.24720375835695765,24:0.34661625418092523,25:0.6874788018222535,26:0.20751542445734728,27:0.8454546479866272,28:1.3646109733502259,29:-0.809396220196817,30:1.4161688048750636,31:0.281482214112868,32:0.6281602859863034,33:-0.010724710544755172,34:1.2965159885481903,35:0.9336101931398596},\"threshold\":0.894234668665694},{\"dendrites\":{1:3.3868627206534057,2:2.0420791921993717,3:0.596431320202737,4:-0.06066359198646402,5:2.94321182192757,6:2.550582117069899,7:1.673525904565925,8:1.099381954900851,9:0.32868856896254,10:0.41404632186707707,11:0.20096386827455698,12:-0.06106408784849395,13:4.001842856113677,14:2.684592507146888,15:0.06577198013726712,16:0.3532685124340426,17:1.8378952202335996,18:-0.41760137499771355,19:2.550175354999244,20:2.0992426850328445,21:2.7231769784467144,22:-1.0159107211841174,23:0.426332924048691,24:2.1021226529831796,25:-0.3358783774497558,26:0.865898783154753,27:2.3755281718048904,28:1.3995367238671061,29:-3.386595781889268,30:3.1305225057475425,31:1.091246176237584,32:2.595887461578013,33:2.886145044942326,34:3.507716675518195,35:1.6789072656661113},\"threshold\":0.08348386400899895}]],\"dnnAvg\":7.7573404347,\"dymNerveStudies\":[{\"list\":[0.36596350757473395,0.9743771456688652,0.3345919443555121,0.09589506895163691,0.8074743350745449,0.1467548122550928,0.5452333225695593,0.4069480147004165,0.8791156996109215],\"threshold\":1.135640286780224},{\"list\":[0.3063677514981339,0.08055922298071905,0.8112435986260279,0.4187719355607248,0.8478974014784709,0.7929100145737933,0.8214723385213866,0.8493723327296772,0.8204199062085575],\"threshold\":0.681236646965117},{\"list\":[0.21179286394891217,0.6770457867219297,0.09202682127488837,0.010991261153074139,0.6767987628791162,0.7207962368447218,0.3054687239646886,0.7590993711418521,0.25354667983273105],\"threshold\":1.869269033696416}],\"dymOutNerveStudy\":{\"list\":[0.6370600231934174,0.858360809944063,0.9836513981530407,0.9904278565486508,0.6126106876433631,0.45533526446338635,0.6231320559052893,0.6071457259551392,0.20775843741304434],\"threshold\":3.126392367978499},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:-0.3950961762571424,2:0.8662827700466347,3:-0.03374080599713339,4:0.0709588447712534,5:0.5623920970141028,6:0.5222608442291498,7:0.5199488882449715,8:0.13963339035744346,9:0.8241114854428533},\"threshold\":0.0296611912661046},{\"dendrites\":{1:1.2749426399366968,2:-3.91302584521E-4,3:1.1408513146166548,4:0.7873453477568866,5:0.04576874885891934,6:0.11500176677752398,7:0.7147855891628966,8:0.2018519618190637,9:-0.05537151161506089},\"threshold\":1.091054555158593}]}"; + public static final String DATA3 = "{\"borderMap\":{},\"depthNerves\":[[{\"dendrites\":{1:-0.47578283876922645,2:0.25361035284142036,3:0.7160439370706159,4:-0.03652656814825689,5:0.5783154673848899,6:0.4557900211183697,7:-0.06853946060004582,8:-0.5374787320598601,9:0.20091879707311303,10:-0.3697292921364848,11:0.24421154625259003,12:0.7582213900307538,13:-0.16974850783889242,14:-0.03940152303695751,15:0.23548348509020806,16:0.6014403221431438,17:0.35547817426678835,18:0.6210766149436667,19:0.26661415646699016,20:0.5583825616604929,21:0.7483676828561064,22:0.5433917218716718,23:-0.001230749600167296,24:0.025078251683870224,25:0.7310410655153967,26:1.1950042573501287,27:0.8515019982596593,28:0.9102698700244091,29:1.0133982064290885,30:0.9474458177617898,31:1.5632191354900822,32:1.4417984314692034,33:0.7419019819844954,34:1.06298014529452,35:1.167628325311264},\"threshold\":0.712475201604175},{\"dendrites\":{1:0.2210460759140201,2:0.10223856175333884,3:0.45349666425709756,4:0.8103257564178863,5:0.16426429375417612,6:0.8420988456642566,7:0.38907779227389877,8:0.9152142382519965,9:0.18250158260269114,10:0.4028456472534935,11:0.3839459334826135,12:0.1490231416621912,13:0.6018867186959436,14:0.8099431338323142,15:0.4654933372601952,16:1.0995537737021426,17:0.6529169801467233,18:1.0307149405799736,19:0.6476317719294152,20:1.2259121514458717,21:0.12307669371573933,22:0.12733691928692567,23:0.773417381020008,24:0.6901303514511037,25:0.48350374777193333,26:0.12776876394777975,27:0.9419085398202361,28:0.6879484698599551,29:0.5205369243501949,30:0.6982716804952239,31:0.454229134449188,32:0.42574281737535263,33:0.3266206257916909,34:0.1679765029330681,35:0.4614502309217239},\"threshold\":0.7324226818966374},{\"dendrites\":{1:0.49415775697954645,2:0.8374454637518293,3:-0.043333533988261584,4:-0.2989568883551582,5:0.9991337119437482,6:0.012470631234929032,7:0.25283384743731074,8:0.16449428960048917,9:0.9845817775615111,10:-0.00165813398656474,11:-0.563910161485814,12:0.4291660995317359,13:0.2608564312367051,14:-0.17308996368276533,15:0.5506648147974829,16:0.1020411637147802,17:0.36069864113455,18:0.2683878517602938,19:0.6357442462905069,20:0.6534911662284106,21:1.5045657049142511,22:1.257677376413893,23:0.19535071254617176,24:0.699437525383934,25:0.030572675059638982,26:1.169154649403698,27:0.08762721851019845,28:1.0370420036785093,29:1.4290450356671305,30:1.2695909690828953,31:0.7935309733832248,32:1.0502830832737242,33:0.564150356329378,34:1.7534209597575015,35:1.3789773840145618},\"threshold\":0.3520568584665965},{\"dendrites\":{1:0.6431094641581983,2:0.7132976155292926,3:0.5574653581312913,4:0.08009055827262929,5:0.5033512998442182,6:0.3439196003244908,7:0.849407408903155,8:0.4043649891470587,9:0.06300970684143943,10:0.742226515264529,11:0.6473441314251747,12:0.48111669410573477,13:0.23308882986536342,14:-0.05881965658626874,15:0.8485442180078595,16:0.16106796043360153,17:0.7438097050725485,18:0.7643717038003933,19:0.7997827518317202,20:0.8556130276777161,21:0.6289984466693352,22:0.052888433002990454,23:0.1040895310360726,24:0.13326238151841258,25:0.9554361430055195,26:0.9704021728665477,27:0.819826579785669,28:0.9052408610484842,29:0.7147762080597372,30:1.0881056779275557,31:0.8634717825480158,32:0.9514793541397598,33:1.165866305185544,34:0.7309549201052485,35:1.0683723438977628},\"threshold\":0.8674282088167221},{\"dendrites\":{1:0.6954574494738188,2:-0.0013018919795619616,3:0.12187599563653842,4:0.6045699086836567,5:0.8745017120485251,6:0.5120472511246185,7:1.096477153595774,8:0.19296180700147358,9:0.13676475388481937,10:0.6624240155161343,11:1.1271147641341777,12:0.4449964249544851,13:-0.02392444383765663,14:1.0099070047545435,15:0.6607699391141874,16:0.5782693540091328,17:0.4003717034522762,18:0.6879380200347469,19:0.9749346174272627,20:0.16218891420628453,21:-0.14405810075180445,22:-0.17432450687522522,23:0.21101122486195306,24:0.6333425677037118,25:0.885196266926744,26:0.9936435988764308,27:0.9229664208990858,28:-0.09784692395214109,29:0.4149795744020192,30:0.6729652605086447,31:1.034367200466997,32:0.1397083104893555,33:0.30439632820697293,34:0.591399518310888,35:0.13726004064813263},\"threshold\":0.0482671075394849},{\"dendrites\":{1:0.9043978696985354,2:0.5114944702041193,3:0.8547913769997153,4:0.656626722813553,5:0.5564805739304622,6:0.18658389314870538,7:0.90118419263876,8:0.25653320504917676,9:0.19374534806615876,10:0.5402916344625995,11:0.8959608625592672,12:0.7626539248327463,13:0.5345843876413,14:0.11705556370547755,15:0.7044204347330826,16:0.43917218634245747,17:0.8550515402786902,18:1.030591054081812,19:1.1139459689579814,20:0.03225224588882324,21:0.3285659259307474,22:0.04776274130394083,23:0.4237353793999157,24:0.9221396900271989,25:0.7299289154059098,26:0.6723838041267668,27:0.43685665726500283,28:0.19528635828370672,29:0.4082214523581449,30:0.30127953297603,31:0.6255510195646445,32:0.7725210248438826,33:0.4270044984322164,34:0.9077900467779042,35:0.054791336773918446},\"threshold\":0.7184258204881401},{\"dendrites\":{1:0.6318876239396358,2:0.17931613068357785,3:1.089750522519565,4:0.6789165107970391,5:1.035512208104859,6:0.9065246149052963,7:0.8502462973121925,8:-0.3357888143358637,9:0.7341258470708674,10:-0.09956658805542824,11:-0.21929023665178413,12:1.022250024353536,13:0.37160901863972234,14:0.08008376524591072,15:0.16257720927101083,16:0.43752235791988403,17:0.5948531662489178,18:0.3479971816646408,19:1.0647396833678673,20:0.39402103474011635,21:0.6858110100415199,22:0.5642181102352418,23:0.09701346370968034,24:0.530588823077516,25:0.29875677325790034,26:1.1561529178424494,27:0.5141757229881521,28:0.9046736141934985,29:0.9298278328107674,30:0.6548452798856871,31:1.2890683119407158,32:1.109890151344512,33:0.9997915381776958,34:1.3794631092351899,35:1.3036999307906136},\"threshold\":0.16134084793032513},{\"dendrites\":{1:0.17870374353217866,2:0.7114703956003448,3:0.7958322331898945,4:0.18169352069149877,5:0.8251160628880929,6:0.05173492934032594,7:0.2161486588024675,8:0.4275604110226431,9:0.11617943887170663,10:0.24062388036111637,11:0.6076824682725707,12:0.7137886405760635,13:-0.09925304227972864,14:0.4533613243400423,15:0.5914331162663737,16:0.4020385927508013,17:0.8227231219208598,18:0.975212398672925,19:1.3548187118396786,20:0.521794255874998,21:0.449922135453937,22:0.7813867808887636,23:0.517516467419692,24:0.6410415532971943,25:0.4385069224893672,26:0.5930629267950435,27:0.18856167141473507,28:0.02347812326854917,29:-0.0917954864977519,30:0.5873243866839859,31:0.8774746156090867,32:0.7199276037379724,33:0.8854582040553278,34:0.3553722071364917,35:0.3993911577875779},\"threshold\":0.16018703405052662},{\"dendrites\":{1:0.6604157179255382,2:0.7417588801083059,3:-0.07842746996704852,4:0.9147230054935125,5:0.08595583186957803,6:0.6342465427091476,7:0.49854581390233954,8:0.37525652400916515,9:0.103833859073775,10:0.5757325375139762,11:0.8375927340783086,12:0.5920033061346183,13:0.450917668868008,14:0.5474741999233096,15:0.9015392563250932,16:0.5393764005783392,17:0.89108742856504,18:0.16444212341910705,19:0.6403011005680834,20:1.0717662759546087,21:-0.304525593513622,22:0.5010307843240901,23:0.3807136735805639,24:0.9069963050200798,25:0.44816000873195416,26:0.5809243524742147,27:1.0738583153965418,28:-0.017258284718131508,29:0.08128990064476473,30:0.29515871434493657,31:0.5961533367085238,32:0.27744733306768654,33:0.18372651440691046,34:0.6726388715787553,35:0.6498352829672713},\"threshold\":0.6730579891999835}]],\"dnnAvg\":7.6125873238,\"dymNerveStudies\":[{\"list\":[0.11336361826267749,0.3152629374625133,0.9760194928696584,0.9891664347587575,0.2797335212804729,0.6006672881903405,0.7519342186503372,0.8018437014201365,0.9600873862726558],\"threshold\":0.1672704783804445},{\"list\":[0.38733049741087344,0.8737258913047904,0.0945098231378132,0.34933299351608016,0.7315921193491124,0.14526202526762055,0.46900481376922853,0.2909286605116036,0.32666625063110843],\"threshold\":0.0323618929774641},{\"list\":[0.4315782334051259,0.31423487520083304,0.05908076855945221,0.35744390656530967,0.17417003252672103,0.1191307189486468,0.0667239796932958,0.7947869399385024,0.564512886131763],\"threshold\":-0.807549953532866}],\"dymOutNerveStudy\":{\"list\":[0.461744792593901,0.886001843426975,0.09192891226500333,0.3164439082281295,0.5870274615392361,0.7850967668439511,0.6309425280509436,0.9203188541377715,0.2614358051696034],\"threshold\":-0.805223727846192},\"matrixK\":{},\"outNerves\":[{\"dendrites\":{1:-0.13833216272361046,2:0.6724283784761534,3:0.05901753325971701,4:0.3169774005624482,5:0.46637989292557513,6:-0.053779277805462884,7:0.01495089273402363,8:0.04565193250755854,9:0.7437691232986713},\"threshold\":0.52776953371034},{\"dendrites\":{1:0.7857343536605664,2:-0.15749831914179838,3:0.681096971348693,4:0.31746419564639194,5:0.5246561528223534,6:0.15248503714394618,7:0.4228718902600013,8:0.2271822243188965,9:0.20163511411877677},\"threshold\":0.3022664051180266}]}"; } From 06acc55456bc0107b434494623856b7e41fb94f9 Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Thu, 7 May 2020 17:13:21 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=88=86=E6=B0=B4=E5=B2=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/wlld/config/Kernel.java | 1 + .../wlld/imageRecognition/Convolution.java | 52 ++++++++------ .../org/wlld/imageRecognition/Operation.java | 72 ------------------- .../org/wlld/imageRecognition/Picture.java | 15 ++-- .../imageRecognition/ThreeChannelMatrix.java | 9 +++ .../org/wlld/imageRecognition/XYBody.java | 33 +++++++++ .../modelEntity/RegressionBody.java | 25 ++++--- .../segmentation/Watershed.java | 12 +++- src/test/java/coverTest/CoverTest.java | 31 ++++---- src/test/java/coverTest/FoodTest.java | 66 +++++++++-------- 10 files changed, 157 insertions(+), 159 deletions(-) create mode 100644 src/main/java/org/wlld/imageRecognition/XYBody.java diff --git a/src/main/java/org/wlld/config/Kernel.java b/src/main/java/org/wlld/config/Kernel.java index a7f3d44..4f5f149 100644 --- a/src/main/java/org/wlld/config/Kernel.java +++ b/src/main/java/org/wlld/config/Kernel.java @@ -10,6 +10,7 @@ public class Kernel { private static final String All_Number2 = "[-1,0,-1]#[0,4,0]#[-1,0,-1]#"; public static final int rainNub = 10;//分水岭初始降雨点的数量 public static final int th = 150;//分水岭灰度阈值 + public static final double rgbN = 441.6729559300637;//RGB范数归一化最大值 public static Matrix Vertical; public static Matrix Horizontal; public static Matrix All; diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index 13388c0..9be10a7 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -40,7 +40,7 @@ public class Convolution extends Frequency { return matrix; } - private List regionThreeChannelMatrix(ThreeChannelMatrix threeChannelMatrix, int size) { + private List regionThreeChannelMatrix(ThreeChannelMatrix threeChannelMatrix, int size) { List threeChannelMatrixList = new ArrayList<>(); Matrix matrixRAll = threeChannelMatrix.getMatrixR(); Matrix matrixGAll = threeChannelMatrix.getMatrixG(); @@ -63,17 +63,17 @@ public class Convolution extends Frequency { } // public static void main(String[] args) throws Exception { -// Picture picture = new Picture(); -// for (int i = 1; i < 10; i++) { -// ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai/a" + i + ".jpg"); -// ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai/b" + i + ".jpg"); -// kc(threeChannelMatrix1, 2, 3, 40); -// kc(threeChannelMatrix2, 2, 3, 40); -// System.out.println("============================================"); -// } +// Picture picture = new Picture();//imageTrance +// ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("D:\\share/a.png"); +// ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share/b.png"); +// XYBody xyBody = imageTrance(threeChannelMatrix.getMatrixRGB(), 40); +// XYBody xyBody2 = imageTrance(threeChannelMatrix2.getMatrixRGB(), 40); +// regression(xyBody); +// RegressionBody regressionBody = xyBody.getRegressionBody(); +// regressionBody.getMaxDis(xyBody2.getY(), xyBody2.getX());//av==0.8493586867 // } - public List> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub + public List> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub , int regionSize) throws Exception { RGBSort rgbSort = new RGBSort(); List> features = new ArrayList<>(); @@ -111,13 +111,13 @@ public class Convolution extends Frequency { for (int t = 0; t < dm.length; t++) { dm[t] = rgbNorms.get(t).getNorm(); } - System.out.println(Arrays.toString(dm)); + //System.out.println(Arrays.toString(dm)); features.add(feature); } return features; } - public List> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub + public List> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub , int regionSize) throws Exception { Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); @@ -214,36 +214,44 @@ public class Convolution extends Frequency { return list; } - public List> imageTrance(Matrix matrix, int size, int featureNub) throws Exception {//矩阵和卷积核大小 + private void regression(XYBody xyBody) { + //计算当前图形的线性回归 + RegressionBody regressionBody = new RegressionBody(); + regressionBody.lineRegression(xyBody.getY(), xyBody.getX(),this); + xyBody.setRegressionBody(regressionBody); + } + + public XYBody imageTrance(Matrix matrix, int size) throws Exception {//矩阵和卷积核大小 int xn = matrix.getX(); int yn = matrix.getY(); int xSize = xn / size;//求导后矩阵的行数 int ySize = yn / size;//求导后矩阵的列数 double[] Y = new double[xSize * ySize]; double[] X = new double[xSize * ySize]; + double rgbN = Kernel.rgbN; for (int i = 0; i < xn - size; i += size) { for (int j = 0; j < yn - size; j += size) { Matrix matrix1 = matrix.getSonOfMatrix(i, j, size, size); double[] nubs = new double[size * size];//平均值数组 for (int t = 0; t < size; t++) { for (int k = 0; k < size; k++) { - double nub = matrix1.getNumber(t, k) / 255; + double nub = matrix1.getNumber(t, k) / rgbN; nubs[t * size + k] = nub; } } double avg = average(nubs);//平均值 - double dc = dcByAvg(nubs, avg);//当前离散系数 - //double va = varianceByAve(nubs, avg);//方差 + //double dc = frequency.dcByAvg(nubs, avg);//当前离散系数 + double va = varianceByAve(nubs, avg);//方差 //离散系数作为X,AVG作为Y int t = i / size * ySize + j / size; Y[t] = avg; - X[t] = dc; + X[t] = va; } } - //计算当前图形的线性回归 - RegressionBody regressionBody = new RegressionBody(); - regressionBody.lineRegression(Y, X, this); - return regressionBody.mappingMatrix(featureNub); + XYBody xyBody = new XYBody(); + xyBody.setX(X); + xyBody.setY(Y); + return xyBody; } @@ -325,7 +333,7 @@ public class Convolution extends Frequency { return myMatrix; } - protected Matrix late(Matrix matrix, int size) throws Exception {//迟化处理 + protected Matrix late(Matrix matrix, int size) throws Exception {//迟化处理 int xn = matrix.getX(); int yn = matrix.getY(); int x = xn / size;//求导后矩阵的行数 diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 04a3429..4186de0 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -57,78 +57,6 @@ public class Operation {//进行计算 return sub(matrix1); } - public void coverStudyOne(Map matrixMap, int regionSize) throws Exception {//先学卷积核 - Frame frame = new Frame(); - frame.setHeight(regionSize); - frame.setWidth(regionSize); - frame.setLengthHeight(regionSize); - frame.setLengthWidth(regionSize); - List sensoryNerve = templeConfig.getConvolutionNerveManager().getSensoryNerves(); - for (Map.Entry entry : matrixMap.entrySet()) { - Matrix matrix = entry.getValue().getH(); - List frameBodies = convolution.getRegion(matrix, frame); - int key = entry.getKey(); - int size = frameBodies.size(); - for (int i = 0; i < size; i++) { - FrameBody frameBody = frameBodies.get(i); - intoConvolutionNetwork(1, frameBody.getMatrix(), sensoryNerve, true, key, null); - } - } - } - - public void coverStudyTwo(Map matrixMap, int poolSize, int sqNub, int regionSize, - int times) throws Exception { - int size = templeConfig.getSensoryNerves().size(); - List sensoryNerve = templeConfig.getConvolutionNerveManager().getSensoryNerves(); - Frame frame = new Frame(); - frame.setHeight(regionSize); - frame.setWidth(regionSize); - frame.setLengthHeight(regionSize); - frame.setLengthWidth(regionSize); - List coverBodies = new ArrayList<>(); - for (Map.Entry entry : matrixMap.entrySet()) { - List frameBodies = convolution.getRegion(entry.getValue().getH(), frame); - int key = entry.getKey(); - int sizeA = frameBodies.size(); - List> featureList = new ArrayList<>(); - for (int i = 0; i < sizeA; i++) { - FrameBody frameBody = frameBodies.get(i); - MatrixBack matrixBack = new MatrixBack(); - intoConvolutionNetwork(1, frameBody.getMatrix(), sensoryNerve, false, 0, matrixBack); - Matrix matrix1 = matrixBack.getMatrix(); - List feature = getFeatures(matrix1); - featureList.add(feature); - } - CoverBody coverBody = new CoverBody(); - Map tag = new HashMap<>(); - tag.put(entry.getKey(), 1.0); - //聚类RGB特征 - List> lists = convolution.kAvg(entry.getValue(), poolSize, sqNub, regionSize); - coverBody.setcFeature(featureList); - coverBody.setFeature(lists); - coverBody.setTag(tag); - coverBodies.add(coverBody); - } - for (int j = 0; j < times; j++) { - for (int i = 0; i < size; i++) { - List list; - for (CoverBody coverBody : coverBodies) { - List list1 = coverBody.getFeature().get(i); - List list2 = coverBody.getcFeature().get(i); - if (i < list1.size()) { - list = list1; - } else { - list = list2; - } - if (templeConfig.isShowLog()) { - System.out.println("feature:" + list); - } - intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null); - } - } - } - } - public void coverStudy(Map matrixMap, int poolSize, int sqNub, int regionSize, int times) throws Exception { if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { diff --git a/src/main/java/org/wlld/imageRecognition/Picture.java b/src/main/java/org/wlld/imageRecognition/Picture.java index c76c84b..b3cedeb 100644 --- a/src/main/java/org/wlld/imageRecognition/Picture.java +++ b/src/main/java/org/wlld/imageRecognition/Picture.java @@ -77,16 +77,23 @@ public class Picture { ThreeChannelMatrix threeChannelMatrix = new ThreeChannelMatrix(); Matrix matrixR = new Matrix(height, width);//行,列 Matrix matrixG = new Matrix(height, width);//行,列 - Matrix matrixB = new Matrix(height, width);//行,列 + Matrix matrixB = new Matrix(height, width);//行, + Matrix matrixRGB = new Matrix(height, width); threeChannelMatrix.setMatrixR(matrixR); threeChannelMatrix.setMatrixG(matrixG); threeChannelMatrix.setMatrixB(matrixB); + threeChannelMatrix.setMatrixRGB(matrixRGB); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int pixel = bi.getRGB(j, i);// 下面三行代码将一个数字转换为RGB数字 - matrixR.setNub(i, j, (pixel & 0xff0000) >> 16); - matrixG.setNub(i, j, (pixel & 0xff00) >> 8); - matrixB.setNub(i, j, (pixel & 0xff)); + int r = (pixel & 0xff0000) >> 16;//R + int g = (pixel & 0xff00) >> 8;//G + int b = (pixel & 0xff);//B + double rgb = Math.sqrt(Math.pow(r, 2) + Math.pow(g, 2) + Math.pow(b, 2)); + matrixRGB.setNub(i, j, rgb); + matrixR.setNub(i, j, r); + matrixG.setNub(i, j, g); + matrixB.setNub(i, j, b); } } return threeChannelMatrix; diff --git a/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java b/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java index 8711d9c..be7276d 100644 --- a/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java +++ b/src/main/java/org/wlld/imageRecognition/ThreeChannelMatrix.java @@ -7,6 +7,15 @@ public class ThreeChannelMatrix { Matrix matrixG; Matrix matrixB; Matrix H; + Matrix matrixRGB; + + public Matrix getMatrixRGB() { + return matrixRGB; + } + + public void setMatrixRGB(Matrix matrixRGB) { + this.matrixRGB = matrixRGB; + } public Matrix getH() { return H; diff --git a/src/main/java/org/wlld/imageRecognition/XYBody.java b/src/main/java/org/wlld/imageRecognition/XYBody.java new file mode 100644 index 0000000..b9df449 --- /dev/null +++ b/src/main/java/org/wlld/imageRecognition/XYBody.java @@ -0,0 +1,33 @@ +package org.wlld.imageRecognition; + +import org.wlld.imageRecognition.modelEntity.RegressionBody; + +public class XYBody { + private double[] X; + private double[] Y; + private RegressionBody regressionBody; + + public RegressionBody getRegressionBody() { + return regressionBody; + } + + public void setRegressionBody(RegressionBody regressionBody) { + this.regressionBody = regressionBody; + } + + public double[] getX() { + return X; + } + + public void setX(double[] x) { + X = x; + } + + public double[] getY() { + return Y; + } + + public void setY(double[] y) { + Y = y; + } +} diff --git a/src/main/java/org/wlld/imageRecognition/modelEntity/RegressionBody.java b/src/main/java/org/wlld/imageRecognition/modelEntity/RegressionBody.java index df6ca26..03ec02b 100644 --- a/src/main/java/org/wlld/imageRecognition/modelEntity/RegressionBody.java +++ b/src/main/java/org/wlld/imageRecognition/modelEntity/RegressionBody.java @@ -9,26 +9,26 @@ import java.util.List; public class RegressionBody { private double w; private double b; - private double[] X; + private double maxDis;//最大距离 - public List> mappingMatrix(int size) { - int len = X.length - size; - List> lists = new ArrayList<>(); - for (int i = 0; i < len; i += size) { - List list = new ArrayList<>(); - for (int t = i; t < i + size; t++) { - double nub = ArithUtil.add(ArithUtil.mul(w, X[t]), b); - list.add(nub); + public void getMaxDis(double[] Y, double[] X) {//获取当前的最大距离 + double allNub = 0; + for (int i = 0; i < X.length; i++) { + double y = ArithUtil.add(ArithUtil.mul(X[i], w), b); + double dis = Math.abs(ArithUtil.sub(Y[i], y)); + allNub = ArithUtil.add(allNub, dis); + System.out.println("dis======" + dis); + if (dis > maxDis) { + maxDis = dis; } - lists.add(list); } - return lists; + allNub = ArithUtil.div(allNub, X.length);//当前最大值:0.1955576793420405,allNub==0.035958733 + System.out.println("当前最大值:" + maxDis + ",allNub==" + allNub); } public void lineRegression(double[] Y, double[] X, Frequency frequency) {//进行二元线性回归 double avX = frequency.average(X);//平均值 int len = Y.length; - this.X = X; double wFenZi = 0; double wFenMu; double xSigma = 0;//X求和 @@ -49,6 +49,5 @@ public class RegressionBody { bSigma = ArithUtil.add(ArithUtil.sub(y, ArithUtil.mul(w, x)), bSigma); } b = ArithUtil.div(bSigma, len); - } } diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index 647fc8c..0f038b9 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -2,7 +2,6 @@ package org.wlld.imageRecognition.segmentation; import org.wlld.MatrixTools.Matrix; import org.wlld.config.Kernel; -import org.wlld.imageRecognition.border.FrameBody; import java.util.*; @@ -201,6 +200,9 @@ public class Watershed { int x = matrix.getX(); int y = matrix.getY(); int size = xSize * ySize; + double minPoint = 1; + int xr = 0; + int yr = 0; for (int i = 0; i <= x - xSize; i += xSize) { for (int j = 0; j <= y - ySize; j += ySize) { Matrix myMatrix = rainfallMap.getSonOfMatrix(i, j, xSize, ySize); @@ -213,9 +215,15 @@ public class Watershed { } } double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标 - System.out.println("cover==" + cover + ",x==" + i + ",y==" + j); + if (cover < minPoint) { + xr = i; + yr = j; + //System.out.println("cover==" + cover + ",x==" + i + ",y==" + j); + minPoint = cover; + } } } + System.out.println("min==" + minPoint + ",x==" + xr + ",y==" + yr); } private int getMinIndex(double[] array, double mySelf) {//获取最小值 diff --git a/src/test/java/coverTest/CoverTest.java b/src/test/java/coverTest/CoverTest.java index 4026955..c006d93 100644 --- a/src/test/java/coverTest/CoverTest.java +++ b/src/test/java/coverTest/CoverTest.java @@ -34,7 +34,7 @@ public class CoverTest { // for (int i = 1; i < 100; i++) { // cover2(operation, "D:\\pic\\6\\a/a" + i + ".jpg"); // } - //test(null, 2, 3, 40, "c", 3); + //test(null, 2, 3, 40, "c", 3); cover(); } @@ -71,7 +71,7 @@ public class CoverTest { operation = getModel(); } for (int i = 1; i < 100; i++) { - String na = "D:\\share\\cai/" + name + i + ".jpg"; + String na = "D:\\pic\\test/" + name + i + ".jpg"; //System.out.println("name======================" + na); ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na); Map map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); @@ -80,7 +80,7 @@ public class CoverTest { for (Map.Entry entry : map1.entrySet()) { int key = entry.getKey(); double value = entry.getValue(); - // System.out.println("key==" + key + ",value==" + value); + // System.out.println("key==" + key + ",value==" + value); if (value > point) { point = value; id = key; @@ -108,31 +108,26 @@ public class CoverTest { //初始化模板 注意 width height参数是你训练图片的实际尺寸需要改,其他不用动 //创建运算类进行标注 templeConfig.isShowLog(true); - templeConfig.setStudyPoint(0.005);//不动 + templeConfig.setStudyPoint(0.01);//不动 templeConfig.setSoftMax(true); //templeConfig.setDeep(2); //templeConfig.setHiddenNerveNub(9); - templeConfig.setSensoryNerveNub(4); + templeConfig.setSensoryNerveNub(3);//多出来的 templeConfig.setRzType(RZ.L1);//不动//3 18 - templeConfig.setlParam(0.01);//不动 - templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4); + templeConfig.setlParam(0.015);//不动 + templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 2); Operation operation = new Operation(templeConfig); for (int i = 1; i < 100; i++) { Map matrixMap = new HashMap<>(); - ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai/a" + i + ".jpg"); - ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai/b" + i + ".jpg"); - ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\cai/c" + i + ".jpg"); - ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai/d" + i + ".jpg"); - - matrixMap.put(1, threeChannelMatrix1); - matrixMap.put(2, threeChannelMatrix2); - matrixMap.put(3, threeChannelMatrix3); - matrixMap.put(4, threeChannelMatrix4); - operation.coverStudy(matrixMap, 5, 4, 10, 2); + ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic\\test/b" + i + ".jpg"); + ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\pic\\test/d" + i + ".jpg"); + matrixMap.put(1, threeChannelMatrix1);//桔梗覆盖 + matrixMap.put(2, threeChannelMatrix2);//土地 + operation.coverStudy(matrixMap, 2, 3, 18, 2); } ModelParameter modelParameter = templeConfig.getModel(); String model = JSON.toJSONString(modelParameter); System.out.println(model); - // test(operation, 2, 3, 40, "d", 4); + test(operation, 2, 3, 18, "d", 2); } } diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index ee7c340..17df9c3 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -5,6 +5,8 @@ import org.wlld.MatrixTools.Matrix; import org.wlld.config.Classifier; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; +import org.wlld.function.Sigmod; +import org.wlld.function.Tanh; import org.wlld.imageRecognition.*; import org.wlld.imageRecognition.segmentation.Watershed; import org.wlld.nerveEntity.ModelParameter; @@ -19,59 +21,69 @@ public class FoodTest { public static void rain() throws Exception {//降雨 Picture picture = new Picture(); - Matrix matrix = picture.getImageMatrixByLocal("D:\\share\\cai/i1.jpg"); + Matrix matrix = picture.getImageMatrixByLocal("D:\\share\\cai/d1.jpg"); Watershed watershed = new Watershed(matrix); watershed.rainfall(); } public static void food() throws Exception { - Picture picture = new Picture(); - TempleConfig templeConfig = new TempleConfig(); - templeConfig.setClassifier(Classifier.DNN); - templeConfig.isShowLog(true); - templeConfig.setSoftMax(true); - templeConfig.setTh(0); - //templeConfig.setMatrixWidth(5); - templeConfig.setStudyPoint(0.02); - templeConfig.setRzType(RZ.L1); - templeConfig.setlParam(0.016);//0.015 + Picture picture = new Picture();//创建图片解析类 + TempleConfig templeConfig = new TempleConfig();//创建配置模板类 + templeConfig.setClassifier(Classifier.DNN);//使用DNN 分类器 + //templeConfig.setActiveFunction(new Sigmod());//设置激活函数 + templeConfig.setDeep(2);//设置深度 深度神经网络 深度越深速度越慢 + //数量越大越准 但是影响量比较小 不绝对 盲试 + templeConfig.setHiddenNerveNub(9);//设置隐层神经元数量 + templeConfig.isShowLog(true);//输出打印数据 + // + //templeConfig.setSoftMax(true);//启用最后一层的SOFTMAX + //templeConfig.setTh(-1);//设置阈值 + templeConfig.setStudyPoint(0.012);//设置学习率 0-1 + templeConfig.setRzType(RZ.L1);//设置正则函数 + templeConfig.setlParam(0.015);//设置正则参数 + templeConfig.init(StudyPattern.Accuracy_Pattern, true, 640, 480, 2); - Operation operation = new Operation(templeConfig); + Operation operation = new Operation(templeConfig);//计算类 // 一阶段 for (int j = 0; j < 2; j++) { - for (int i = 1; i < 233; i++) {//一阶段 + for (int i = 1; i < 101; i++) {//一阶段 System.out.println("study1===================" + i); //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\pic\\6\\b/b" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\1/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\pic\\2/b" + i + ".jpg"); operation.learning(a, 1, false); operation.learning(b, 2, false); } } - // 二阶段 - for (int i = 1; i < 233; i++) { + // 二阶段 归一化 + for (int i = 1; i < 101; i++) { System.out.println("avg==" + i); - Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\pic\\6\\b/b" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\1/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\pic\\2/b" + i + ".jpg"); operation.normalization(a, templeConfig.getConvolutionNerveManager()); operation.normalization(b, templeConfig.getConvolutionNerveManager()); } templeConfig.getNormalization().avg(); - for (int j = 0; j < 5; j++) { - for (int i = 1; i < 233; i++) { + + for (int j = 0; j < 3; j++) { + for (int i = 1; i < 101; i++) { System.out.println("j==" + j + ",study2==================" + i); - Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); - Matrix b = picture.getImageMatrixByLocal("D:\\pic\\6\\b/b" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\1/a" + i + ".jpg"); + Matrix b = picture.getImageMatrixByLocal("D:\\pic\\2/b" + i + ".jpg"); operation.learning(a, 1, true); operation.learning(b, 2, true); } } templeConfig.finishStudy();//结束学习 + ModelParameter modelParameter = templeConfig.getModel(); + String model = JSON.toJSONString(modelParameter); + System.out.println(model); + int wrong = 0; int allNub = 0; - for (int i = 1; i <= 232; i++) { + for (int i = 1; i <= 100; i++) { //读取本地URL地址图片,并转化成矩阵 - Matrix a = picture.getImageMatrixByLocal("D:\\pic\\6\\a/a" + i + ".jpg"); + Matrix a = picture.getImageMatrixByLocal("D:\\pic\\1/a" + i + ".jpg"); allNub++; int an = operation.toSee(a); if (an != 1) { @@ -80,9 +92,7 @@ public class FoodTest { } double wrongPoint = ArithUtil.div(wrong, allNub); System.out.println("错误率:" + (wrongPoint * 100) + "%"); - ModelParameter modelParameter = templeConfig.getModel(); - String model = JSON.toJSONString(modelParameter); - System.out.println(model); + } } From e5a72ce3bbc1519a8444dec05ece78548b4b5add Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Fri, 8 May 2020 17:30:27 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=88=86=E6=B0=B4=E5=B2=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/wlld/config/Kernel.java | 2 +- .../segmentation/RegionBody.java | 36 +++++++++++- .../segmentation/Watershed.java | 57 +++++++++---------- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/wlld/config/Kernel.java b/src/main/java/org/wlld/config/Kernel.java index 4f5f149..0052c9b 100644 --- a/src/main/java/org/wlld/config/Kernel.java +++ b/src/main/java/org/wlld/config/Kernel.java @@ -9,7 +9,7 @@ public class Kernel { private static final String All_Number = "[1,-2,1]#[-2,4,-2]#[1,-2,1]#";//角卷积 private static final String All_Number2 = "[-1,0,-1]#[0,4,0]#[-1,0,-1]#"; public static final int rainNub = 10;//分水岭初始降雨点的数量 - public static final int th = 150;//分水岭灰度阈值 + public static final double th = 0.7;//分水岭灰度阈值 public static final double rgbN = 441.6729559300637;//RGB范数归一化最大值 public static Matrix Vertical; public static Matrix Horizontal; diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java index 1d14e2f..e40c9f2 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java @@ -1,8 +1,5 @@ package org.wlld.imageRecognition.segmentation; -import org.wlld.MatrixTools.Matrix; - -import java.util.ArrayList; import java.util.List; /** @@ -10,5 +7,38 @@ import java.util.List; * @description 分区实体 */ public class RegionBody { + private int minX = -1; + private int minY = -1; + private int maxX; + private int maxY; + public void setPoint(int x, int y) { + if (x < minX || minX == -1) { + minX = x; + } + if (y < minY || minY == -1) { + minY = y; + } + if (x > maxX) { + maxX = x; + } + if (y > maxY) { + maxY = y; + } + } + + public int getMinX() { + return minX; + } + + public int getMinY() { + return minY; + } + + public int getMaxX() { + return maxX; + } + public int getMaxY() { + return maxY; + } } diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index 0f038b9..72c8cfb 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -11,25 +11,22 @@ import java.util.*; * @date 10:25 上午 2020/1/13 */ public class Watershed { - private Matrix matrix;//灰度图像 + private Matrix matrix;//RGB范数图像 private Matrix rainfallMap;//降雨图 - private int rainNub = Kernel.rainNub;//默认降雨点的数量 - private int th = Kernel.th;//灰度阈值 - private List pointList = new ArrayList<>(); + private Matrix rainDensityMap;//降雨密度图 + private Matrix regionMap;//分区图 + private int xSize;//单元高度 + private int ySize;//单元宽度 + private double th = Kernel.th;//灰度阈值 + private List regionList = new ArrayList<>(); private int xMax; private int yMax; - class Point { - private int x; - private int y; - private boolean isLow;//已经到最低处了 - private boolean isFull;//已经满了 - } - public Watershed(Matrix matrix) throws Exception { if (matrix != null) { this.matrix = matrix; rainfallMap = new Matrix(matrix.getX(), matrix.getY()); + rainDensityMap = new Matrix(matrix.getX() / 30, matrix.getY() / 30); xMax = rainfallMap.getX() - 1; yMax = rainfallMap.getY() - 1; } else { @@ -94,7 +91,7 @@ public class Watershed { return new double[]{top, left, bottom, right, leftTop, leftBottom, rightBottom, rightTop}; } - private int[] rain(int x, int y, boolean isFirst) throws Exception {//先往下降,直到不能再降了为止 + private int[] rain(int x, int y) throws Exception {//先往下降,直到不能再降了为止 //有两种情况停止:1,最小值是自身。2,周围已经灌满水了,包括自身 double[] pixels = getPixels(x, y); int[] point = new int[8]; @@ -147,8 +144,6 @@ public class Watershed { rainfallMap.setNub(row, column, 1); } } - } else {//我自己就是最小了 - } return point; } @@ -164,14 +159,12 @@ public class Watershed { private void fall(int i, int j) throws Exception { List list = new ArrayList<>(); list.add((i << 12) | j); - boolean isFirst = true; do { List list2 = new ArrayList<>(); for (int pixel : list) { int x = pixel >> 12; int y = pixel & 0xfff; - int[] nodes = rain(x, y, isFirst); - isFirst = false; + int[] nodes = rain(x, y); pull(list2, nodes); } list = list2; @@ -190,19 +183,27 @@ public class Watershed { } } //进行区域提取 - int xSize = x / 30; - int ySize = y / 30; + xSize = x / 30; + ySize = y / 30; System.out.println("xSize==" + xSize + ",ySize==" + ySize); - sigmaPixel(xSize, ySize); + sigmaPixel(); + } + + + private void getPosition() throws Exception { + int x = rainDensityMap.getX(); + int y = rainDensityMap.getY(); + for (int i = 0; i < x; i++) { + for (int j = 0; j < y; j++) { + double nub = rainDensityMap.getNumber(i, j); + } + } } - private void sigmaPixel(int xSize, int ySize) throws Exception { + private void sigmaPixel() throws Exception {//生成降雨密度图 int x = matrix.getX(); int y = matrix.getY(); int size = xSize * ySize; - double minPoint = 1; - int xr = 0; - int yr = 0; for (int i = 0; i <= x - xSize; i += xSize) { for (int j = 0; j <= y - ySize; j += ySize) { Matrix myMatrix = rainfallMap.getSonOfMatrix(i, j, xSize, ySize); @@ -215,15 +216,11 @@ public class Watershed { } } double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标 - if (cover < minPoint) { - xr = i; - yr = j; - //System.out.println("cover==" + cover + ",x==" + i + ",y==" + j); - minPoint = cover; + if (cover > th) {//降雨密度图 + rainDensityMap.setNub(i / 30, j / 30, 1); } } } - System.out.println("min==" + minPoint + ",x==" + xr + ",y==" + yr); } private int getMinIndex(double[] array, double mySelf) {//获取最小值 From a738814f23c45987116fd4f50c3b2be510d0224f Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Sat, 9 May 2020 13:06:44 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=88=86=E6=B0=B4=E5=B2=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/wlld/config/Kernel.java | 2 +- .../segmentation/RegionBody.java | 28 +++++++- .../segmentation/Watershed.java | 68 +++++++++++++++++-- 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/wlld/config/Kernel.java b/src/main/java/org/wlld/config/Kernel.java index 0052c9b..782bba4 100644 --- a/src/main/java/org/wlld/config/Kernel.java +++ b/src/main/java/org/wlld/config/Kernel.java @@ -8,7 +8,7 @@ public class Kernel { private static final String Horizontal_Number = "[-1,-2,-1]#[0,0,0]#[1,2,1]#";//横卷积核 private static final String All_Number = "[1,-2,1]#[-2,4,-2]#[1,-2,1]#";//角卷积 private static final String All_Number2 = "[-1,0,-1]#[0,4,0]#[-1,0,-1]#"; - public static final int rainNub = 10;//分水岭初始降雨点的数量 + public static final int Region_Nub = 30;//一张图分为多少份 public static final double th = 0.7;//分水岭灰度阈值 public static final double rgbN = 441.6729559300637;//RGB范数归一化最大值 public static Matrix Vertical; diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java index e40c9f2..038f395 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java @@ -1,5 +1,8 @@ package org.wlld.imageRecognition.segmentation; +import org.wlld.MatrixTools.Matrix; + +import java.util.ArrayList; import java.util.List; /** @@ -11,7 +14,27 @@ public class RegionBody { private int minY = -1; private int maxX; private int maxY; - public void setPoint(int x, int y) { + private List pointList = new ArrayList<>(); + private Matrix regionMap;//分区图 + + public List getPointList() { + return pointList; + } + + public RegionBody(Matrix regionMap) { + this.regionMap = regionMap; + } + + public void merge(int type, RegionBody regionBody) throws Exception {//区域合并 + List points = regionBody.getPointList(); + for (int pixel : points) { + int x = pixel >> 12; + int y = pixel & 0xfff; + setPoint(x, y, type); + } + } + + public void setPoint(int x, int y, int type) throws Exception { if (x < minX || minX == -1) { minX = x; } @@ -24,6 +47,9 @@ public class RegionBody { if (y > maxY) { maxY = y; } + int pixel = x << 12 | y; + pointList.add(pixel); + regionMap.setNub(x, y, type); } public int getMinX() { diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index 72c8cfb..558893b 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -18,17 +18,24 @@ public class Watershed { private int xSize;//单元高度 private int ySize;//单元宽度 private double th = Kernel.th;//灰度阈值 - private List regionList = new ArrayList<>(); + private Map regionBodyMap = new HashMap<>(); + private int regionNub = Kernel.Region_Nub;//一张图分多少份 private int xMax; private int yMax; + private int rxMax; + private int ryMax; + private int id = 0; public Watershed(Matrix matrix) throws Exception { if (matrix != null) { this.matrix = matrix; rainfallMap = new Matrix(matrix.getX(), matrix.getY()); - rainDensityMap = new Matrix(matrix.getX() / 30, matrix.getY() / 30); + rainDensityMap = new Matrix(matrix.getX() / regionNub, matrix.getY() / regionNub); + regionMap = new Matrix(matrix.getX() / regionNub, matrix.getY() / regionNub); xMax = rainfallMap.getX() - 1; yMax = rainfallMap.getY() - 1; + rxMax = regionMap.getX() - 1; + ryMax = regionMap.getY() - 1; } else { throw new Exception("matrix is null"); } @@ -183,12 +190,55 @@ public class Watershed { } } //进行区域提取 - xSize = x / 30; - ySize = y / 30; + xSize = x / regionNub; + ySize = y / regionNub; System.out.println("xSize==" + xSize + ",ySize==" + ySize); sigmaPixel(); } + private void setRegion(int x, int y, int type) throws Exception { + int i = 0; + int j = 0; + for (int t = 0; t < 8; t++) { + switch (t) { + case 0: + i = x - 1; + j = y; + break; + case 1: + i = x - 1; + j = y - 1; + break; + case 2: + i = x - 1; + j = y + 1; + break; + case 3: + i = x; + j = y - 1; + break; + case 4: + i = x; + j = y + 1; + break; + case 5: + i = x + 1; + j = y - 1; + break; + case 6: + i = x + 1; + j = y; + break; + case 7: + i = x + 1; + j = y + 1; + break; + } + if (i > -1 && j > -1 && i <= rxMax && j <= ryMax && regionMap.getNumber(i, j) == 1) { + regionBodyMap.get(type).setPoint(i, j, type); + } + } + } private void getPosition() throws Exception { int x = rainDensityMap.getX(); @@ -196,6 +246,13 @@ public class Watershed { for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { double nub = rainDensityMap.getNumber(i, j); + if (nub == 1) { + id++; + RegionBody regionBody = new RegionBody(regionMap); + regionBody.setPoint(x, y, id); + regionBodyMap.put(id, regionBody); + setRegion(i, j, id); + } } } } @@ -217,10 +274,11 @@ public class Watershed { } double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标 if (cover > th) {//降雨密度图 - rainDensityMap.setNub(i / 30, j / 30, 1); + rainDensityMap.setNub(i / regionNub, j / regionNub, 1); } } } + getPosition(); } private int getMinIndex(double[] array, double mySelf) {//获取最小值 From e0c541467dfcf4f6a2e23479d53814dd58e156a5 Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Mon, 11 May 2020 17:47:33 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=86=E6=B0=B4=E5=B2=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/wlld/config/Kernel.java | 4 +- .../segmentation/RegionBody.java | 33 +---- .../segmentation/Watershed.java | 131 ++++++++++-------- src/test/java/coverTest/FoodTest.java | 2 +- 4 files changed, 88 insertions(+), 82 deletions(-) diff --git a/src/main/java/org/wlld/config/Kernel.java b/src/main/java/org/wlld/config/Kernel.java index 782bba4..f0c9302 100644 --- a/src/main/java/org/wlld/config/Kernel.java +++ b/src/main/java/org/wlld/config/Kernel.java @@ -9,7 +9,9 @@ public class Kernel { private static final String All_Number = "[1,-2,1]#[-2,4,-2]#[1,-2,1]#";//角卷积 private static final String All_Number2 = "[-1,0,-1]#[0,4,0]#[-1,0,-1]#"; public static final int Region_Nub = 30;//一张图分为多少份 - public static final double th = 0.7;//分水岭灰度阈值 + public static final int Region_Dif = 3;//区域内的最大间隔 + public static final double Region_Th = 0.2;//区域分割阈值 + public static final double th = 0.5;//分水岭灰度阈值 public static final double rgbN = 441.6729559300637;//RGB范数归一化最大值 public static Matrix Vertical; public static Matrix Horizontal; diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java index 038f395..3268ebd 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java @@ -14,42 +14,23 @@ public class RegionBody { private int minY = -1; private int maxX; private int maxY; - private List pointList = new ArrayList<>(); - private Matrix regionMap;//分区图 - public List getPointList() { - return pointList; - } - - public RegionBody(Matrix regionMap) { - this.regionMap = regionMap; - } - - public void merge(int type, RegionBody regionBody) throws Exception {//区域合并 - List points = regionBody.getPointList(); - for (int pixel : points) { - int x = pixel >> 12; - int y = pixel & 0xfff; - setPoint(x, y, type); - } - } - - public void setPoint(int x, int y, int type) throws Exception { + public void setX(int x) { if (x < minX || minX == -1) { minX = x; } - if (y < minY || minY == -1) { - minY = y; - } if (x > maxX) { maxX = x; } + } + + public void setY(int y) { + if (y < minY || minY == -1) { + minY = y; + } if (y > maxY) { maxY = y; } - int pixel = x << 12 | y; - pointList.add(pixel); - regionMap.setNub(x, y, type); } public int getMinX() { diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index 558893b..ae479c3 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -2,6 +2,7 @@ package org.wlld.imageRecognition.segmentation; import org.wlld.MatrixTools.Matrix; import org.wlld.config.Kernel; +import org.wlld.tools.ArithUtil; import java.util.*; @@ -13,24 +14,24 @@ import java.util.*; public class Watershed { private Matrix matrix;//RGB范数图像 private Matrix rainfallMap;//降雨图 - private Matrix rainDensityMap;//降雨密度图 private Matrix regionMap;//分区图 private int xSize;//单元高度 private int ySize;//单元宽度 private double th = Kernel.th;//灰度阈值 + private double regionTh = Kernel.Region_Th; + private int regionSize = Kernel.Region_Dif; private Map regionBodyMap = new HashMap<>(); private int regionNub = Kernel.Region_Nub;//一张图分多少份 private int xMax; private int yMax; + private int id = 1; private int rxMax; private int ryMax; - private int id = 0; public Watershed(Matrix matrix) throws Exception { if (matrix != null) { this.matrix = matrix; rainfallMap = new Matrix(matrix.getX(), matrix.getY()); - rainDensityMap = new Matrix(matrix.getX() / regionNub, matrix.getY() / regionNub); regionMap = new Matrix(matrix.getX() / regionNub, matrix.getY() / regionNub); xMax = rainfallMap.getX() - 1; yMax = rainfallMap.getY() - 1; @@ -194,69 +195,90 @@ public class Watershed { ySize = y / regionNub; System.out.println("xSize==" + xSize + ",ySize==" + ySize); sigmaPixel(); +// int nub = 0; +// System.out.println("region size==" + regionBodyMap.size()); +// for (Map.Entry entry : regionBodyMap.entrySet()) { +// RegionBody regionBody = entry.getValue(); +// int maxX = regionBody.getMaxX(); +// int maxY = regionBody.getMaxY(); +// int minX = regionBody.getMinX(); +// int minY = regionBody.getMinY(); +// System.out.println("minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY); +// } +// System.out.println("nub===" + nub); } - private void setRegion(int x, int y, int type) throws Exception { - int i = 0; - int j = 0; - for (int t = 0; t < 8; t++) { - switch (t) { - case 0: - i = x - 1; - j = y; - break; - case 1: - i = x - 1; - j = y - 1; - break; - case 2: - i = x - 1; - j = y + 1; - break; - case 3: - i = x; - j = y - 1; - break; - case 4: - i = x; - j = y + 1; - break; - case 5: - i = x + 1; - j = y - 1; - break; - case 6: - i = x + 1; - j = y; - break; - case 7: - i = x + 1; - j = y + 1; - break; - } - if (i > -1 && j > -1 && i <= rxMax && j <= ryMax && regionMap.getNumber(i, j) == 1) { - regionBodyMap.get(type).setPoint(i, j, type); + private void setType(int type, int x, int y) throws Exception { + for (int i = x; i < x + 3; i++) { + for (int j = y; j < y + 3; j++) { + if (regionMap.getNumber(i, j) != 0) { + regionMap.setNub(i, j, type); + } } } } - private void getPosition() throws Exception { - int x = rainDensityMap.getX(); - int y = rainDensityMap.getY(); + private void mergeRegion() throws Exception {//区域合并 + int x = regionMap.getX() - 2; + int y = regionMap.getY() - 2; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { - double nub = rainDensityMap.getNumber(i, j); - if (nub == 1) { + Matrix matrix = regionMap.getSonOfMatrix(i, j, regionSize, regionSize); + int type = 0; + int state = 0; + for (int k = 0; k < matrix.getX(); k++) { + for (int l = 0; l < matrix.getY(); l++) { + int nub = (int) matrix.getNumber(k, l); + if (nub > 1 && type == 0) {//存在大于1的数 + type = nub; + state = state | (1 << 1); + } else if (nub == 1) { + state = state | 1; + } + } + } + if ((state & 2) != 0) {//存在大于1的数 + setType(type, i, j); + } else if ((state & 1) != 0) {//不存在大于1的数,但是存在1,生成新的ID id++; - RegionBody regionBody = new RegionBody(regionMap); - regionBody.setPoint(x, y, id); - regionBodyMap.put(id, regionBody); - setRegion(i, j, id); + regionBodyMap.put(id, new RegionBody()); + setType(id, i, j); } } } } + private void createRegion() throws Exception { + int x = regionMap.getX(); + int y = regionMap.getY(); + for (int i = 0; i < x; i++) { + Map map = new HashMap<>(); + for (int j = 0; j < y; j++) { + int type = (int) regionMap.getNumber(i, j); + if (type > 1) { + if (map.containsKey(type)) { + map.put(type, map.get(type) + 1); + } else { + map.put(type, 1); + } + } + } + /// + for (Map.Entry entry : regionBodyMap.entrySet()) { + int type = entry.getKey(); + RegionBody regionBody = entry.getValue(); + if (map.containsKey(type)) {//如果这个类型存在 + int nub = map.get(type); + double point = ArithUtil.div(nub, ryMax); + if (point > regionTh) { + //regionBody.setX(); + } + } + } + } + + } + private void sigmaPixel() throws Exception {//生成降雨密度图 int x = matrix.getX(); int y = matrix.getY(); @@ -274,11 +296,12 @@ public class Watershed { } double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标 if (cover > th) {//降雨密度图 - rainDensityMap.setNub(i / regionNub, j / regionNub, 1); + regionMap.setNub(i / regionNub, j / regionNub, 1); } } } - getPosition(); + mergeRegion(); + // System.out.println(regionMap.getString()); } private int getMinIndex(double[] array, double mySelf) {//获取最小值 diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index 17df9c3..82769af 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -21,7 +21,7 @@ public class FoodTest { public static void rain() throws Exception {//降雨 Picture picture = new Picture(); - Matrix matrix = picture.getImageMatrixByLocal("D:\\share\\cai/d1.jpg"); + Matrix matrix = picture.getImageMatrixByLocal("D:\\share/c.png"); Watershed watershed = new Watershed(matrix); watershed.rainfall(); } From 196c37b67fa8adc93cf3ece255e515abe74ed47a Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Tue, 12 May 2020 15:26:38 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=88=86=E6=B0=B4=E5=B2=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/wlld/config/Kernel.java | 2 +- .../wlld/imageRecognition/Convolution.java | 95 ++----------------- .../segmentation/RegionBody.java | 5 - .../segmentation/Specifications.java | 22 +++++ .../segmentation/Watershed.java | 83 +++++++++++----- src/test/java/coverTest/CoverTest.java | 2 +- src/test/java/coverTest/FoodTest.java | 27 +++++- 7 files changed, 111 insertions(+), 125 deletions(-) create mode 100644 src/main/java/org/wlld/imageRecognition/segmentation/Specifications.java diff --git a/src/main/java/org/wlld/config/Kernel.java b/src/main/java/org/wlld/config/Kernel.java index f0c9302..2fe5dc4 100644 --- a/src/main/java/org/wlld/config/Kernel.java +++ b/src/main/java/org/wlld/config/Kernel.java @@ -8,7 +8,7 @@ public class Kernel { private static final String Horizontal_Number = "[-1,-2,-1]#[0,0,0]#[1,2,1]#";//横卷积核 private static final String All_Number = "[1,-2,1]#[-2,4,-2]#[1,-2,1]#";//角卷积 private static final String All_Number2 = "[-1,0,-1]#[0,4,0]#[-1,0,-1]#"; - public static final int Region_Nub = 30;//一张图分为多少份 + public static final int Region_Nub = 30;//一张图有多少份 public static final int Region_Dif = 3;//区域内的最大间隔 public static final double Region_Th = 0.2;//区域分割阈值 public static final double th = 0.5;//分水岭灰度阈值 diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index 9be10a7..c7a4fea 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -62,17 +62,6 @@ public class Convolution extends Frequency { return threeChannelMatrixList; } -// public static void main(String[] args) throws Exception { -// Picture picture = new Picture();//imageTrance -// ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("D:\\share/a.png"); -// ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share/b.png"); -// XYBody xyBody = imageTrance(threeChannelMatrix.getMatrixRGB(), 40); -// XYBody xyBody2 = imageTrance(threeChannelMatrix2.getMatrixRGB(), 40); -// regression(xyBody); -// RegressionBody regressionBody = xyBody.getRegressionBody(); -// regressionBody.getMaxDis(xyBody2.getY(), xyBody2.getX());//av==0.8493586867 -// } - public List> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub , int regionSize) throws Exception { RGBSort rgbSort = new RGBSort(); @@ -117,8 +106,7 @@ public class Convolution extends Frequency { return features; } - public List> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub - , int regionSize) throws Exception { + public List getCenterColor(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub) throws Exception { Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixB = threeChannelMatrix.getMatrixB(); @@ -137,91 +125,22 @@ public class Convolution extends Frequency { } meanClustering.start(); List rgbNorms = meanClustering.getMatrices(); - double minNorm = 0; - int normSize = rgbNorms.size(); - for (int i = 0; i < normSize; i++) { - RGBNorm rgbNorm = rgbNorms.get(i); - double[] rgb = rgbNorm.getRgb(); - for (int j = 0; j < normSize; j++) { - if (j != i) { - double normSub = getEDist(rgb, rgbNorms.get(j).getRgb()); - if (minNorm == 0 || normSub < minNorm) { - minNorm = normSub; - } - } - } - } Collections.sort(rgbNorms, rgbSort); - double[] features = new double[sqNub]; + List feature = new ArrayList<>(); for (int i = 0; i < sqNub; i++) { - features[i] = rgbNorms.get(i).getNorm(); - } - System.out.println(Arrays.toString(features)); - minNorm = ArithUtil.div(minNorm, 2); - return null;//checkImage(matrixR, matrixG, matrixB, minNorm, regionSize, features); - } - - private List> checkImage(Matrix matrixR, Matrix matrixG, Matrix matrixB, double minNorm, int size - , double[] features) throws Exception { - List> lists = new ArrayList<>(); - int x = matrixR.getX() - size;//求导后矩阵的行数 - int y = matrixR.getY() - size;//求导后矩阵的列数 - for (int i = 0; i < x; i += size) {//遍历行 - for (int j = 0; j < y; j += size) {//遍历每行的列 - Matrix myMatrixR = matrixR.getSonOfMatrix(i, j, size, size); - Matrix myMatrixG = matrixG.getSonOfMatrix(i, j, size, size); - Matrix myMatrixB = matrixB.getSonOfMatrix(i, j, size, size); - List list = getListFeature(myMatrixR, myMatrixG, myMatrixB, minNorm, features); - // System.out.println("feature====" + list); - lists.add(list); - } - } - return lists; - } - - private List getListFeature(Matrix matrixR, Matrix matrixG, Matrix matrixB, double minNorm - , double[] features) throws Exception { - int x = matrixR.getX(); - int y = matrixR.getY(); - List list = new ArrayList<>(); - double[] feat = new double[features.length]; - List rgbNormList = meanClustering.getMatrices(); - for (int i = 0; i < x; i++) { - for (int j = 0; j < y; j++) { - double[] color = new double[]{matrixR.getNumber(i, j) / 255, matrixG.getNumber(i, j) / 255, matrixB.getNumber(i, j) / 255}; - int id = -1; - double minDist = 0; - for (int t = 0; t < rgbNormList.size(); t++) { - RGBNorm rgbNorm = rgbNormList.get(t); - double dist = getEDist(color, rgbNorm.getRgb()); - if (minDist == 0 || dist < minDist) { - minDist = dist; - id = t; - } - } - if (minDist >= minNorm) { - id = -1; - } - if (id > -1) { - feat[id] = rgbNormList.get(id).getNorm(); - } - } - } - // - for (int i = 0; i < feat.length; i++) { - list.add(feat[i]); + feature.add(rgbNorms.get(i).getNorm()); } - return list; + return feature; } - private void regression(XYBody xyBody) { + private void regression(XYBody xyBody) { //计算当前图形的线性回归 RegressionBody regressionBody = new RegressionBody(); - regressionBody.lineRegression(xyBody.getY(), xyBody.getX(),this); + regressionBody.lineRegression(xyBody.getY(), xyBody.getX(), this); xyBody.setRegressionBody(regressionBody); } - public XYBody imageTrance(Matrix matrix, int size) throws Exception {//矩阵和卷积核大小 + public XYBody imageTrance(Matrix matrix, int size) throws Exception {//矩阵和卷积核大小 int xn = matrix.getX(); int yn = matrix.getY(); int xSize = xn / size;//求导后矩阵的行数 diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java index 3268ebd..8a2e754 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/RegionBody.java @@ -1,10 +1,5 @@ package org.wlld.imageRecognition.segmentation; -import org.wlld.MatrixTools.Matrix; - -import java.util.ArrayList; -import java.util.List; - /** * @author lidapeng * @description 分区实体 diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Specifications.java b/src/main/java/org/wlld/imageRecognition/segmentation/Specifications.java new file mode 100644 index 0000000..95ec274 --- /dev/null +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Specifications.java @@ -0,0 +1,22 @@ +package org.wlld.imageRecognition.segmentation; + +public class Specifications { + private double width; + private double height; + + public double getWidth() { + return width; + } + + public void setWidth(double width) { + this.width = width; + } + + public double getHeight() { + return height; + } + + public void setHeight(double height) { + this.height = height; + } +} diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index ae479c3..b93d0ef 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -25,18 +25,18 @@ public class Watershed { private int xMax; private int yMax; private int id = 1; - private int rxMax; - private int ryMax; + private List specifications; - public Watershed(Matrix matrix) throws Exception { - if (matrix != null) { + public Watershed(Matrix matrix, List specifications) throws Exception { + if (matrix != null && specifications != null && specifications.size() > 0) { this.matrix = matrix; + this.specifications = specifications; + xSize = matrix.getX() / regionNub; + ySize = matrix.getY() / regionNub; rainfallMap = new Matrix(matrix.getX(), matrix.getY()); - regionMap = new Matrix(matrix.getX() / regionNub, matrix.getY() / regionNub); + regionMap = new Matrix(regionNub, regionNub); xMax = rainfallMap.getX() - 1; yMax = rainfallMap.getY() - 1; - rxMax = regionMap.getX() - 1; - ryMax = regionMap.getY() - 1; } else { throw new Exception("matrix is null"); } @@ -180,7 +180,7 @@ public class Watershed { } - public void rainfall() throws Exception {//开始降雨 + public List rainfall() throws Exception {//开始降雨 int x = matrix.getX(); int y = matrix.getY(); for (int i = 0; i < x; i++) { @@ -191,21 +191,28 @@ public class Watershed { } } //进行区域提取 - xSize = x / regionNub; - ySize = y / regionNub; - System.out.println("xSize==" + xSize + ",ySize==" + ySize); sigmaPixel(); -// int nub = 0; -// System.out.println("region size==" + regionBodyMap.size()); -// for (Map.Entry entry : regionBodyMap.entrySet()) { -// RegionBody regionBody = entry.getValue(); -// int maxX = regionBody.getMaxX(); -// int maxY = regionBody.getMaxY(); -// int minX = regionBody.getMinX(); -// int minY = regionBody.getMinY(); -// System.out.println("minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY); -// } -// System.out.println("nub===" + nub); + List regionBodies = new ArrayList<>(); + for (Map.Entry entry : regionBodyMap.entrySet()) { + RegionBody regionBody = entry.getValue(); + if (check(regionBody.getMinX(), regionBody.getMinY(), regionBody.getMaxX(), regionBody.getMaxY())) { + regionBodies.add(regionBody); + } + } + return regionBodies; + } + + private boolean check(int minX, int minY, int maxX, int maxY) { + boolean isRight = false; + for (Specifications specification : specifications) { + int width = maxY - minY; + int height = maxX - minX; + if (width >= specification.getWidth() && height >= specification.getHeight()) { + isRight = true; + break; + } + } + return isRight; } private void setType(int type, int x, int y) throws Exception { @@ -263,20 +270,43 @@ public class Watershed { } } } - /// for (Map.Entry entry : regionBodyMap.entrySet()) { int type = entry.getKey(); RegionBody regionBody = entry.getValue(); if (map.containsKey(type)) {//如果这个类型存在 int nub = map.get(type); - double point = ArithUtil.div(nub, ryMax); + double point = ArithUtil.div(nub, regionNub); if (point > regionTh) { - //regionBody.setX(); + regionBody.setX(i * xSize); } } } } + for (int j = 0; j < y; j++) { + Map map = new HashMap<>(); + for (int i = 0; i < x; i++) { + int type = (int) regionMap.getNumber(i, j); + if (type > 1) { + if (map.containsKey(type)) { + map.put(type, map.get(type) + 1); + } else { + map.put(type, 1); + } + } + } + for (Map.Entry entry : regionBodyMap.entrySet()) { + int type = entry.getKey(); + RegionBody regionBody = entry.getValue(); + if (map.containsKey(type)) {//如果这个类型存在 + int nub = map.get(type); + double point = ArithUtil.div(nub, regionNub); + if (point > regionTh) { + regionBody.setY(j * ySize); + } + } + } + } } private void sigmaPixel() throws Exception {//生成降雨密度图 @@ -296,12 +326,13 @@ public class Watershed { } double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标 if (cover > th) {//降雨密度图 - regionMap.setNub(i / regionNub, j / regionNub, 1); + regionMap.setNub(i / xSize, j / ySize, 1); } } } mergeRegion(); // System.out.println(regionMap.getString()); + createRegion(); } private int getMinIndex(double[] array, double mySelf) {//获取最小值 diff --git a/src/test/java/coverTest/CoverTest.java b/src/test/java/coverTest/CoverTest.java index c006d93..b281c59 100644 --- a/src/test/java/coverTest/CoverTest.java +++ b/src/test/java/coverTest/CoverTest.java @@ -128,6 +128,6 @@ public class CoverTest { ModelParameter modelParameter = templeConfig.getModel(); String model = JSON.toJSONString(modelParameter); System.out.println(model); - test(operation, 2, 3, 18, "d", 2); + test(operation, 2, 3, 18, "d", 2); } } diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index 82769af..9f04356 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -5,13 +5,17 @@ import org.wlld.MatrixTools.Matrix; import org.wlld.config.Classifier; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; -import org.wlld.function.Sigmod; -import org.wlld.function.Tanh; import org.wlld.imageRecognition.*; +import org.wlld.imageRecognition.segmentation.RegionBody; +import org.wlld.imageRecognition.segmentation.Specifications; import org.wlld.imageRecognition.segmentation.Watershed; +import org.wlld.nerveCenter.NerveManager; import org.wlld.nerveEntity.ModelParameter; import org.wlld.tools.ArithUtil; +import java.util.ArrayList; +import java.util.List; + public class FoodTest { public static void main(String[] args) throws Exception { @@ -20,10 +24,25 @@ public class FoodTest { } public static void rain() throws Exception {//降雨 + Convolution convolution = new Convolution(); Picture picture = new Picture(); Matrix matrix = picture.getImageMatrixByLocal("D:\\share/c.png"); - Watershed watershed = new Watershed(matrix); - watershed.rainfall(); + List specificationsList = new ArrayList<>(); + Specifications specifications = new Specifications(); + specifications.setWidth(400); + specifications.setHeight(400); + specificationsList.add(specifications); + Watershed watershed = new Watershed(matrix, specificationsList); + List regionList = watershed.rainfall(); + + } + + public static void study() throws Exception { + Picture picture = new Picture(); + Convolution convolution = new Convolution(); + ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(""); + List feature = convolution.getCenterColor(threeChannelMatrix, 2, 4); + } public static void food() throws Exception {