修改覆盖率计算

This commit is contained in:
thenk008 2020-04-18 15:19:27 +08:00
parent aeb106f7ef
commit 37f45a81dc
6 changed files with 157 additions and 31 deletions

View File

@ -40,6 +40,72 @@ public class Convolution extends Frequency {
return matrix;
}
private List<ThreeChannelMatrix> regionThreeChannelMatrix(ThreeChannelMatrix threeChannelMatrix, int size) {
List<ThreeChannelMatrix> threeChannelMatrixList = new ArrayList<>();
Matrix matrixRAll = threeChannelMatrix.getMatrixR();
Matrix matrixGAll = threeChannelMatrix.getMatrixG();
Matrix matrixBAll = threeChannelMatrix.getMatrixB();
int x = matrixRAll.getX();
int y = matrixRAll.getY();
for (int i = 0; i <= x - size; i += size) {
for (int j = 0; j <= y - size; j += size) {
ThreeChannelMatrix threeMatrix = new ThreeChannelMatrix();
Matrix matrixR = matrixRAll.getSonOfMatrix(i, j, size, size);
Matrix matrixG = matrixGAll.getSonOfMatrix(i, j, size, size);
Matrix matrixB = matrixBAll.getSonOfMatrix(i, j, size, size);
threeMatrix.setMatrixR(matrixR);
threeMatrix.setMatrixG(matrixG);
threeMatrix.setMatrixB(matrixB);
threeChannelMatrixList.add(threeMatrix);
}
}
return threeChannelMatrixList;
}
public List<List<Double>> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub
, int regionSize) throws Exception {
RGBSort rgbSort = new RGBSort();
List<List<Double>> features = new ArrayList<>();
Matrix matrixR = threeMatrix.getMatrixR();
Matrix matrixG = threeMatrix.getMatrixG();
Matrix matrixB = threeMatrix.getMatrixB();
matrixR = late(matrixR, poolSize);
matrixG = late(matrixG, poolSize);
matrixB = late(matrixB, poolSize);
threeMatrix.setMatrixR(matrixR);
threeMatrix.setMatrixG(matrixG);
threeMatrix.setMatrixB(matrixB);
List<ThreeChannelMatrix> threeChannelMatrixList = regionThreeChannelMatrix(threeMatrix, regionSize);
for (ThreeChannelMatrix threeChannelMatrix : threeChannelMatrixList) {
List<Double> feature = new ArrayList<>();
MeanClustering meanClustering = new MeanClustering(sqNub);
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[] color = new double[]{matrixR.getNumber(i, j) / 255, matrixG.getNumber(i, j) / 255, matrixB.getNumber(i, j) / 255};
meanClustering.setColor(color);
}
}
meanClustering.start();
List<RGBNorm> rgbNorms = meanClustering.getMatrices();
Collections.sort(rgbNorms, rgbSort);
double[] dm = new double[sqNub];
for (RGBNorm rgbNorm : rgbNorms) {
feature.add(rgbNorm.getNorm());
}
for (int t = 0; t < dm.length; t++) {
dm[t] = rgbNorms.get(t).getNorm();
}
//System.out.println(Arrays.toString(dm));
features.add(feature);
}
return features;
}
public List<List<Double>> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub
, int regionSize) throws Exception {
Matrix matrixR = threeChannelMatrix.getMatrixR();
@ -79,8 +145,8 @@ public class Convolution extends Frequency {
for (int i = 0; i < sqNub; i++) {
features[i] = rgbNorms.get(i).getNorm();
}
//System.out.println(Arrays.toString(features));
minNorm = ArithUtil.div(minNorm, 1);
// System.out.println(Arrays.toString(features));
minNorm = ArithUtil.div(minNorm, 2);
return checkImage(matrixR, matrixG, matrixB, minNorm, regionSize, features);
}

View File

@ -5,7 +5,7 @@ import org.wlld.i.OutBack;
public class MaxPoint implements OutBack {
private int id;
private double point = 0;
private double point = -1;
public int getId() {
return id;

View File

@ -81,14 +81,24 @@ public class MeanClustering {
}
//进行两者的比较
boolean isNext;
do {
for (int i = 0; i < 40; i++) {
averageMatrix();
isNext = isNext();
if (isNext) {
clear();
} else {
break;
}
}
while (isNext);
// boolean isNext;
// do {
// averageMatrix();
// isNext = isNext();
// if (isNext) {
// clear();
// }
// }
// while (isNext);
} else {
throw new Exception("matrixList number less than 2");

View File

@ -65,7 +65,7 @@ public class Operation {//进行计算
CoverBody coverBody = new CoverBody();
Map<Integer, Double> tag = new HashMap<>();
tag.put(entry.getKey(), 1.0);
List<List<Double>> lists = convolution.kc(entry.getValue(), poolSize, sqNub, regionSize);
List<List<Double>> lists = convolution.kAvg(entry.getValue(), poolSize, sqNub, regionSize);
size = lists.size();
coverBody.setFeature(lists);
coverBody.setTag(tag);
@ -82,7 +82,6 @@ public class Operation {//进行计算
intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null);
}
}
}
}
}
@ -91,7 +90,7 @@ public class Operation {//进行计算
if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) {
Map<Integer, Double> coverMap = new HashMap<>();
Map<Integer, Integer> typeNub = new HashMap<>();
List<List<Double>> lists = convolution.kc(matrix, poolSize, sqNub, regionSize);
List<List<Double>> lists = convolution.kAvg(matrix, poolSize, sqNub, regionSize);
//特征塞入容器完毕
int size = lists.size();
int all = 0;

View File

@ -23,6 +23,16 @@ public class Picture {
return getImage(bi);
}
public ThreeChannelMatrix getThreeMatrix(InputStream file) throws Exception {
BufferedImage bi = null;
try {
bi = ImageIO.read(file);
} catch (Exception e) {
e.printStackTrace();
}
return this.getThreeChannel(bi);
}
public ThreeChannelMatrix getThreeMatrix(String fileURL) throws Exception {
File file = new File(fileURL);
BufferedImage bi = null;

View File

@ -48,51 +48,92 @@ public class CoverTest {
public static void test(Operation operation, int poolSize, int sqlNub, int regionSize) throws Exception {
Picture picture = new Picture();
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("D:\\db/a.jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\db/b.jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\db/c.jpg");
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<Integer, Double> map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize);
Map<Integer, Double> map2 = operation.coverPoint(threeChannelMatrix2, poolSize, sqlNub, regionSize);
Map<Integer, Double> map3 = operation.coverPoint(threeChannelMatrix3, poolSize, sqlNub, regionSize);
Map<Integer, Double> map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize);
Map<Integer, Double> map2 = operation.coverPoint(threeChannelMatrix2, poolSize, sqlNub, regionSize);
// Map<Integer, Double> map3 = operation.coverPoint (threeChannelMatrix3, poolSize, sqlNub, regionSize);
//Map<Integer, Double> map4 = operation.coverPoint(threeChannelMatrix4, poolSize, sqlNub, regionSize);
// Map<Integer, Double> map5 = operation.coverPoint(threeChannelMatrix5, poolSize, sqlNub, regionSize);
// Map<Integer, Double> map6 = operation.coverPoint(threeChannelMatrix6, poolSize, sqlNub, regionSize);
// Map<Integer, Double> map7 = operation.coverPoint(threeChannelMatrix7, poolSize, sqlNub, regionSize);
// Map<Integer, Double> map8 = operation.coverPoint(threeChannelMatrix8, poolSize, sqlNub, regionSize);
for (Map.Entry<Integer, Double> entry : map1.entrySet()) {
int key = entry.getKey();
double value = entry.getValue();
System.out.println("1key===" + key + ",value==" + value);
}
System.out.println("=============================");
for (Map.Entry<Integer, Double> entry : map2.entrySet()) {
int key = entry.getKey();
double value = entry.getValue();
System.out.println("2key===" + key + ",value==" + value);
}
System.out.println("=============================");
// for (Map.Entry<Integer, Double> entry : map3.entrySet()) {
// int key = entry.getKey();
// double value = entry.getValue();
// System.out.println("3key===" + key + ",value==" + value);
// }
// System.out.println("=============================");
for (Map.Entry<Integer, Double> entry : map1.entrySet()) {
System.out.println("1type==" + entry.getKey() + ",1value==" + entry.getValue());
}
System.out.println("=============================");
for (Map.Entry<Integer, Double> entry : map2.entrySet()) {
System.out.println("2type==" + entry.getKey() + ",2value==" + entry.getValue());
}
System.out.println("=============================");
for (Map.Entry<Integer, Double> entry : map3.entrySet()) {
System.out.println("2type==" + entry.getKey() + ",2value==" + entry.getValue());
}
}
public static void cover() throws Exception {
//创建图片解析类 桔梗覆盖桔梗焚烧土壤扰动
Picture picture = new Picture();
//创建模版类参数选false就可以
TempleConfig templeConfig = new TempleConfig();
//初始化模板 注意 width height参数是你训练图片的实际尺寸需要改其他不用动
//创建运算类进行标注
//templeConfig.setActiveFunction(new Sigmod());
templeConfig.isShowLog(true);
templeConfig.setStudyPoint(0.01);//不动
templeConfig.setSoftMax(true);
//templeConfig.setDeep(2);
templeConfig.setSensoryNerveNub(2);
templeConfig.setRzType(RZ.L1);//不动
templeConfig.setlParam(0.015);//不动
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 2);
Operation operation = new Operation(templeConfig);
for (int i = 1; i < 2; i++) {
Map<Integer, ThreeChannelMatrix> matrixMap = new HashMap<>();
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\db/a.jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\db/b.jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\db/c.jpg");
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);
operation.coverStudy(matrixMap, 4, 2, 10, 10);
// 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);
}
ModelParameter modelParameter = templeConfig.getModel();
String model = JSON.toJSONString(modelParameter);
System.out.println(model);
test(operation, 4, 2, 10);
test(operation, 2, 2, 40);
}
}