增加深层映射

pull/59/head
lidapeng 4 years ago
parent f18b825d79
commit 2a4dd3c46b

@ -135,7 +135,7 @@ public class Convolution extends Frequency {
} }
public List<Double> getCenterTexture(ThreeChannelMatrix threeChannelMatrix, int size, TempleConfig templeConfig public List<Double> getCenterTexture(ThreeChannelMatrix threeChannelMatrix, int size, TempleConfig templeConfig
, int sqNub) throws Exception { , int sqNub, boolean isStudy) throws Exception {
MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig, true); MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig, true);
Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixG = threeChannelMatrix.getMatrixG();
@ -184,6 +184,9 @@ public class Convolution extends Frequency {
List<Double> features = new ArrayList<>(); List<Double> features = new ArrayList<>();
for (int i = 0; i < sqNub; i++) { for (int i = 0; i < sqNub; i++) {
double[] rgb = rgbNorms.get(i).getRgb(); double[] rgb = rgbNorms.get(i).getRgb();
if (!isStudy) {
rgb = rgbMapping(rgb, i, templeConfig);
}
for (int j = 0; j < rgb.length; j++) { for (int j = 0; j < rgb.length; j++) {
features.add(rgb[j]); features.add(rgb[j]);
} }
@ -193,6 +196,18 @@ public class Convolution extends Frequency {
return features; return features;
} }
private double[] rgbMapping(double[] rgb, int index, TempleConfig templeConfig) {//进行映射
double[] mapping = templeConfig.getFood().getMappingParameter();
int size = rgb.length;
int allSize = mapping.length / 2;
double[] mappingFeature = new double[size];
for (int i = 0; i < size; i++) {
int myIndex = size * index + i;
mappingFeature[i] = rgb[i] * mapping[myIndex] + mapping[allSize + myIndex];
}
return mappingFeature;
}
private void normalization(Matrix matrix) throws Exception { private void normalization(Matrix matrix) throws Exception {
for (int i = 0; i < matrix.getX(); i++) { for (int i = 0; i < matrix.getX(); i++) {
for (int j = 0; j < matrix.getY(); j++) { for (int j = 0; j < matrix.getY(); j++) {

@ -7,7 +7,10 @@ import org.wlld.config.Classifier;
import org.wlld.config.StudyPattern; import org.wlld.config.StudyPattern;
import org.wlld.i.OutBack; import org.wlld.i.OutBack;
import org.wlld.imageRecognition.border.*; import org.wlld.imageRecognition.border.*;
import org.wlld.imageRecognition.segmentation.*; import org.wlld.imageRecognition.segmentation.RegionBody;
import org.wlld.imageRecognition.segmentation.RgbRegression;
import org.wlld.imageRecognition.segmentation.Specifications;
import org.wlld.imageRecognition.segmentation.Watershed;
import org.wlld.nerveCenter.NerveManager; import org.wlld.nerveCenter.NerveManager;
import org.wlld.nerveCenter.Normalization; import org.wlld.nerveCenter.Normalization;
import org.wlld.nerveEntity.SensoryNerve; import org.wlld.nerveEntity.SensoryNerve;
@ -88,13 +91,40 @@ public class Operation {//进行计算
int maxY = regionBody.getMaxY() - dif; int maxY = regionBody.getMaxY() - dif;
int xSize = maxX - minX; int xSize = maxX - minX;
int ySize = maxY - minY; int ySize = maxY - minY;
//convolution.imgNormalization(threeChannelMatrix);
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub()); // List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig, templeConfig.getFeatureNub());
Knn knn = templeConfig.getFood().getDimensionMappingStudy().getKnn(); List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub(), true);
knn.insertMatrix(MatrixOperation.listToRowVector(feature), tag); if (templeConfig.isShowLog()) {
System.out.println(tag + ":" + feature);
}
int classifier = templeConfig.getClassifier();
switch (classifier) {
case Classifier.DNN:
Map<Integer, Double> map = new HashMap<>();
map.put(tag, 1.0);
if (templeConfig.getSensoryNerves().size() == templeConfig.getFeatureNub() * 3) {
intoDnnNetwork(1, feature, templeConfig.getSensoryNerves(), true, map, null);
} else {
throw new Exception("nerves number is not equal featureNub");
}
break;
case Classifier.LVQ:
Matrix vector = MatrixOperation.listToRowVector(feature);
lvqStudy(tag, vector);
break;
case Classifier.VAvg:
Matrix vec = MatrixOperation.listToRowVector(feature);
avgStudy(tag, vec);
break;
case Classifier.KNN:
Matrix veck = MatrixOperation.listToRowVector(feature);
knnStudy(tag, veck);
break;
}
return regionBody; return regionBody;
} else { } else {
System.out.println("error=============================================error");
for (RegionBody regionBody : regionBodies) { for (RegionBody regionBody : regionBodies) {
int minX = regionBody.getMinX(); int minX = regionBody.getMinX();
int minY = regionBody.getMinY(); int minY = regionBody.getMinY();
@ -103,7 +133,6 @@ public class Operation {//进行计算
System.out.println("异常minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY + ",tag==" + tag System.out.println("异常minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY + ",tag==" + tag
+ "url==" + url); + "url==" + url);
} }
System.out.println("error=============================================error");
throw new Exception("Parameter exception region size==" + regionBodies.size()); throw new Exception("Parameter exception region size==" + regionBodies.size());
} }
} }
@ -130,6 +159,7 @@ public class Operation {//进行计算
Watershed watershed = new Watershed(threeChannelMatrix, specificationsList, templeConfig); Watershed watershed = new Watershed(threeChannelMatrix, specificationsList, templeConfig);
List<RegionBody> regionList = watershed.rainfall(); List<RegionBody> regionList = watershed.rainfall();
for (RegionBody regionBody : regionList) { for (RegionBody regionBody : regionList) {
MaxPoint maxPoint = new MaxPoint();
int minX = regionBody.getMinX() + dif; int minX = regionBody.getMinX() + dif;
int minY = regionBody.getMinY() + dif; int minY = regionBody.getMinY() + dif;
int maxX = regionBody.getMaxX() - dif; int maxX = regionBody.getMaxX() - dif;
@ -137,10 +167,37 @@ public class Operation {//进行计算
int xSize = maxX - minX; int xSize = maxX - minX;
int ySize = maxY - minY; int ySize = maxY - minY;
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub()); //List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig, templeConfig.getFeatureNub());
Matrix myMatrix2 = MatrixOperation.listToRowVector(feature); List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub(), false);
DimensionMappingStudy dimensionMappingStudy = templeConfig.getFood().getDimensionMappingStudy();
int id = dimensionMappingStudy.toClassification(myMatrix2); if (templeConfig.isShowLog()) {
System.out.println(feature);
}
int classifier = templeConfig.getClassifier();
int id = 0;
switch (classifier) {
case Classifier.LVQ:
Matrix myMatrix = MatrixOperation.listToRowVector(feature);
id = getIdByLVQ(myMatrix);
break;
case Classifier.DNN:
if (templeConfig.getSensoryNerves().size() == templeConfig.getFeatureNub() * 3) {
intoDnnNetwork(IdCreator.get().nextId(), feature, templeConfig.getSensoryNerves(), false, null, maxPoint);
id = maxPoint.getId();
} else {
throw new Exception("nerves number is not equal featureNub");
}
break;
case Classifier.VAvg:
Matrix myMatrix1 = MatrixOperation.listToRowVector(feature);
id = getIdByVag(myMatrix1);
break;
case Classifier.KNN:
Matrix myMatrix2 = MatrixOperation.listToRowVector(feature);
Knn knn = templeConfig.getKnn();
id = knn.getType(myMatrix2);
break;
}
regionBody.setType(id); regionBody.setType(id);
System.out.println("类别" + id); System.out.println("类别" + id);
} }

@ -0,0 +1,26 @@
package org.wlld.imageRecognition.modelEntity;
import org.wlld.imageRecognition.TempleConfig;
import org.wlld.imageRecognition.border.Knn;
import org.wlld.imageRecognition.segmentation.DimensionMappingStudy;
import java.util.HashMap;
import java.util.Map;
/**
* @param
* @DATA
* @Author LiDaPeng
* @Description
*/
public class DeepMappingBody {
private DimensionMappingStudy dimensionAll;
private TempleConfig templeConfig;
private Map<Integer, DimensionMappingStudy> mappingMap = new HashMap<>();
public DeepMappingBody(TempleConfig templeConfig) throws Exception {
this.templeConfig = templeConfig;
dimensionAll = new DimensionMappingStudy(templeConfig);
dimensionAll.start();
}
}

@ -123,10 +123,10 @@ public class FeatureMapping extends Frequency implements PsoFunction {
featureDifferent.addAll(entry2.getValue()); featureDifferent.addAll(entry2.getValue());
} }
} }
double sameMax = compareSame(myFeature);//同类最大值 // double sameMax = compareSame(myFeature);//同类最大值
double differentMin = compareDifferent(myFeature, featureDifferent);//异类最小值 // double differentMin = compareDifferent(myFeature, featureDifferent);//异类最小值
double sub = differentMin - sameMax; // double sub = differentMin - sameMax;
//double sub = getSub(myFeature, featureDifferent); double sub = getSub(myFeature, featureDifferent);
sigma = sigma + sub; sigma = sigma + sub;
} }
return sigma; return sigma;

@ -1,6 +1,5 @@
package org.wlld.param; package org.wlld.param;
import org.wlld.imageRecognition.segmentation.DimensionMappingStudy;
import org.wlld.imageRecognition.segmentation.KNerveManger; import org.wlld.imageRecognition.segmentation.KNerveManger;
import org.wlld.imageRecognition.segmentation.RgbRegression; import org.wlld.imageRecognition.segmentation.RgbRegression;
@ -25,10 +24,14 @@ public class Food {
private int step = 1;//特征取样步长 private int step = 1;//特征取样步长
private int speciesNub = 24;//种类数 private int speciesNub = 24;//种类数
private KNerveManger kNerveManger; private KNerveManger kNerveManger;
private DimensionMappingStudy dimensionMappingStudy = new DimensionMappingStudy(); private double[] mappingParameter;//特征映射
public DimensionMappingStudy getDimensionMappingStudy() { public double[] getMappingParameter() {
return dimensionMappingStudy; return mappingParameter;
}
public void setMappingParameter(double[] mappingParameter) {
this.mappingParameter = mappingParameter;
} }
public KNerveManger getkNerveManger() { public KNerveManger getkNerveManger() {

@ -14,14 +14,96 @@ import org.wlld.param.Cutting;
import org.wlld.param.Food; import org.wlld.param.Food;
import org.wlld.tools.ArithUtil; import org.wlld.tools.ArithUtil;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
public class FoodTest { public class FoodTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
test(); //test();
int[] a = new int[]{1, 4, 5, 7, 31};
int[] b = new int[]{4, 6, 7, 8, 21,};
int[] c = new int[]{12, 42, 54, 9};
int[] d = new int[]{63, 54, 99};
int[] e = new int[]{991, 123, 456};
List<int[]> t = new ArrayList<>();
t.add(a);
t.add(b);
t.add(c);
t.add(d);
t.add(e);
ab(t);
}
public static void ab(List<int[]> t) {
//最终输入结果
List<Set<Integer>> t1 = new ArrayList<>();
//储存临时值
Set<Integer> s = new HashSet<>();
//用来校验重复游标组
List<List<Integer>> k = new ArrayList<>();
Boolean x = true;//对循环进行判断
int num = 0;//循环游标初始值
while (x) {
//校验重复游标
List<Integer> l = new ArrayList<>();
//清楚临时存储值
s.clear();
//单个最终值
Set<Integer> s1 = new HashSet<>();
for (int i = num; i < t.size(); i++) {
Boolean check = false;
//如果存在已经验证的数组,则跳过
for (int j = num; j < k.size(); j++) {
if (k.get(j).contains(i)) {
check = true;
break;
}
}
if (check) {
continue;
}
//循环判断数组是否存在重复当i=num时给初始的s赋值
//当S中包含重复值的时候插入
for (int info : t.get(i)) {
if (i == num) {
for (int info1 : t.get(i)) {
l.add(i);
k.add(l);
s.add(info1);
}
} else if (s.contains(info)) {
for (int info1 : t.get(i)) {
l.add(i);
k.add(l);
s.add(info1);
}
break;
}
}
}
//如果临时s不为空给s1赋值并存入到最后输出的t1中
if (!s.isEmpty()) {
for (Integer info : s) {
s1.add(info);
}
t1.add(s1);
}
num++;
//跳出循环
if (num >= t.size()) {
x = false;
}
}
System.out.println(t1);
} }
public static void test2(TempleConfig templeConfig) throws Exception { public static void test2(TempleConfig templeConfig) throws Exception {
@ -153,8 +235,9 @@ public class FoodTest {
operation.colorStudy(threeChannelMatrix23, 23, specificationsList, name); operation.colorStudy(threeChannelMatrix23, 23, specificationsList, name);
operation.colorStudy(threeChannelMatrix24, 24, specificationsList, name); operation.colorStudy(threeChannelMatrix24, 24, specificationsList, name);
} }
DimensionMappingStudy dimensionMappingStudy = templeConfig.getFood().getDimensionMappingStudy(); DimensionMappingStudy dimensionMappingStudy = new DimensionMappingStudy(templeConfig);
dimensionMappingStudy.start(templeConfig);//完成映射 dimensionMappingStudy.start();//完成映射
//dimensionMappingStudy.selfTest(6);//检查
//System.out.println("========================"); //System.out.println("========================");
// kNerveManger.startStudy(); // kNerveManger.startStudy();
int i = 4; int i = 4;

Loading…
Cancel
Save