覆盖模式 使用rgb

pull/44/head
lidapeng 5 years ago
parent da8f35277b
commit 0b93a3bf9d

@ -58,6 +58,17 @@ public class Operation {//进行计算
return sub(matrix1);
}
private void cutPic(ThreeChannelMatrix threeChannelMatrix, int x, int y, int xSize, int ySize) {
Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG();
Matrix matrixB = threeChannelMatrix.getMatrixB();
Matrix matrixRGB = threeChannelMatrix.getMatrixRGB();
threeChannelMatrix.setMatrixR(matrixR.getSonOfMatrix(x, y, xSize, ySize));
threeChannelMatrix.setMatrixG(matrixG.getSonOfMatrix(x, y, xSize, ySize));
threeChannelMatrix.setMatrixB(matrixB.getSonOfMatrix(x, y, xSize, ySize));
threeChannelMatrix.setMatrixRGB(matrixRGB.getSonOfMatrix(x, y, xSize, ySize));
}
public void colorStudy(ThreeChannelMatrix threeChannelMatrix, int tag, List<Specifications> specificationsList) throws Exception {
Watershed watershed = new Watershed(threeChannelMatrix.getMatrixRGB(), specificationsList, templeConfig);
List<RegionBody> regionBodies = watershed.rainfall();
@ -232,7 +243,6 @@ public class Operation {//进行计算
List<CoverBody> coverBodies = new ArrayList<>();
for (Map.Entry<Integer, ThreeChannelMatrix> entry : matrixMap.entrySet()) {
//先进行切图
CoverBody coverBody = new CoverBody();
Map<Integer, Double> tag = new HashMap<>();
tag.put(entry.getKey(), 1.0);

@ -25,6 +25,8 @@ public class Watershed {
private int xMax;
private int yMax;
private double maxRain;
private double width;
private double height;
private List<Specifications> specifications;
public Watershed(Matrix matrix, List<Specifications> specifications, TempleConfig templeConfig) throws Exception {
@ -35,6 +37,8 @@ public class Watershed {
maxRain = cutting.getMaxRain();
this.matrix = matrix;
this.specifications = specifications;
width = matrix.getY();
height = matrix.getX();
xSize = matrix.getX() / regionNub;
ySize = matrix.getY() / regionNub;
// System.out.println("xSize===" + xSize + ",ysize===" + ySize);
@ -212,8 +216,12 @@ public class Watershed {
for (Specifications specification : specifications) {
int width = maxY - minY;
int height = maxX - minX;
double h = this.height / 8;
double w = this.width / 8;
boolean isCenter = true;// minX > h && minY > w && minX < (h * 4.5) && minY < (w * 4.5);
if (width >= specification.getMinWidth() && height >= specification.getMinHeight()
&& width <= specification.getMaxWidth() && height <= specification.getMaxHeight()) {
&& width <= specification.getMaxWidth() && height <= specification.getMaxHeight()
&& isCenter) {
isRight = true;
break;
}
@ -301,7 +309,7 @@ public class Watershed {
}
createMerge();
merge();
// System.out.println(regionMap.getString());
// System.out.println(regionMap.getString());
}
private int getMinIndex(double[] array, double mySelf) {//获取最小值

@ -52,15 +52,15 @@ public class CoverTest {
return new Operation(templeConfig);//初始化运算类
}
public static void test(Operation operation, int poolSize, int sqlNub, int regionSize,
public static void test(Operation operation, int sqlNub, int regionSize,
String name, int t) throws Exception {
Picture picture = new Picture();
int wrong = 0;
if (operation == null) {
operation = getModel();
}
for (int i = 1; i < 100; i++) {
String na = "D:\\share\\cai/" + name + i + ".jpg";
for (int i = 1; i < 20; i++) {
String na = "/Users/lidapeng/Desktop/myDocument/food/" + name + i + ".jpg";
//System.out.println("name======================" + na);
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na);
Map<Integer, Double> map1 = operation.coverPoint(threeChannelMatrix, sqlNub, regionSize);
@ -90,6 +90,8 @@ public class CoverTest {
}
public static void cover() throws Exception {
int sqNub = 1;
int regionSize = 20;
//创建图片解析类 桔梗覆盖,桔梗焚烧,土壤扰动
Picture picture = new Picture();
//创建模版类参数选false就可以
@ -97,35 +99,36 @@ public class CoverTest {
//初始化模板 注意 width height参数是你训练图片的实际尺寸需要改其他不用动
//创建运算类进行标注
templeConfig.isShowLog(true);
templeConfig.setStudyPoint(0.01);//不动
templeConfig.setSoftMax(true);
//templeConfig.setDeep(2);
//templeConfig.setHiddenNerveNub(9);
templeConfig.setSensoryNerveNub(3);//多出来的
templeConfig.setStudyPoint(0.005);//不动
//templeConfig.setSoftMax(true);
templeConfig.setDeep(2);
templeConfig.setHiddenNerveNub(9);
templeConfig.setSensoryNerveNub(sqNub);//多出来的
templeConfig.setRzType(RZ.L1);//不动//3 18
templeConfig.setlParam(0.015);//不动
templeConfig.setClassifier(Classifier.DNN);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4);
Operation operation = new Operation(templeConfig);
for (int i = 1; i < 100; i++) {
for (int i = 1; i < 20; i++) {
System.out.println("i====================================" + i);
Map<Integer, ThreeChannelMatrix> 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");
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/food/d" + i + ".jpg");
matrixMap.put(1, threeChannelMatrix1);//桔梗覆盖
matrixMap.put(2, threeChannelMatrix2);//土地
matrixMap.put(3, threeChannelMatrix3);//桔梗覆盖
matrixMap.put(4, threeChannelMatrix4);//土地
operation.coverStudy(matrixMap, 2, 18);
operation.coverStudy(matrixMap, sqNub, regionSize);
}
ModelParameter modelParameter = templeConfig.getModel();
String model = JSON.toJSONString(modelParameter);
System.out.println(model);
test(operation, 2, 3, 18, "a", 1);
test(operation, 2, 3, 18, "b", 2);
test(operation, 2, 3, 18, "c", 3);
test(operation, 2, 3, 18, "d", 4);
// ModelParameter modelParameter = templeConfig.getModel();
// String model = JSON.toJSONString(modelParameter);
// System.out.println(model);
test(operation, sqNub, regionSize, "a", 1);
test(operation, sqNub, regionSize, "b", 2);
test(operation, sqNub, regionSize, "c", 3);
test(operation, sqNub, regionSize, "d", 4);
}
}

@ -45,14 +45,14 @@ public class FoodTest {
Picture picture = new Picture();
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
specifications.setMinWidth(250);
specifications.setMinHeight(250);
specifications.setMaxWidth(750);
specifications.setMaxHeight(750);
specifications.setMinWidth(400);
specifications.setMinHeight(400);
specifications.setMaxWidth(950);
specifications.setMaxHeight(950);
specificationsList.add(specifications);
Operation operation = new Operation(templeConfig);
for (int i = 1; i <= 28; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\g/g" + i + ".jpg");
for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/c" + i + ".jpg");
List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList);
for (int j = 0; j < regionBody.size(); j++) {
RegionBody regionBody1 = regionBody.get(j);
@ -70,17 +70,17 @@ public class FoodTest {
Cutting cutting = templeConfig.getCutting();
Food food = templeConfig.getFood();
//切割
cutting.setMaxRain(320);//切割阈值
cutting.setTh(0.88);
cutting.setMaxRain(310);//切割阈值
cutting.setTh(0.8);
cutting.setRegionNub(200);
//knn参数
templeConfig.setKnnNub(3);
templeConfig.setKnnNub(1);
//池化比例
templeConfig.setPoolSize(2);//缩小比例
//聚类
templeConfig.setFeatureNub(3);//聚类特征数量
//菜品识别实体类
food.setShrink(60);//缩紧像素
food.setShrink(5);//缩紧像素
food.setTimes(2);//聚类数据增强
templeConfig.setClassifier(Classifier.KNN);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
@ -96,32 +96,17 @@ public class FoodTest {
Operation operation = new Operation(templeConfig);
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
specifications.setMinWidth(250);
specifications.setMinHeight(250);
specifications.setMaxWidth(750);
specifications.setMaxHeight(750);
specifications.setMinWidth(400);
specifications.setMinHeight(400);
specifications.setMaxWidth(950);
specifications.setMaxHeight(950);
specificationsList.add(specifications);
for (int i = 1; i <= 10; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\a/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\share\\cai\\b/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\share\\cai\\c/c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\share\\cai\\d/d" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix("D:\\share\\cai\\e/e" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix("D:\\share\\cai\\f/f" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix("D:\\share\\cai\\h/h" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix("D:\\share\\cai\\i/i" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix9 = picture.getThreeMatrix("D:\\share\\cai\\j/j" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix10 = picture.getThreeMatrix("D:\\share\\cai\\k/k" + i + ".jpg");
for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/b" + i + ".jpg");
operation.colorStudy(threeChannelMatrix1, 1, specificationsList);
System.out.println("=======================================");
operation.colorStudy(threeChannelMatrix2, 2, specificationsList);
operation.colorStudy(threeChannelMatrix3, 3, specificationsList);
operation.colorStudy(threeChannelMatrix4, 4, specificationsList);
operation.colorStudy(threeChannelMatrix5, 5, specificationsList);
operation.colorStudy(threeChannelMatrix6, 6, specificationsList);
operation.colorStudy(threeChannelMatrix7, 7, specificationsList);
operation.colorStudy(threeChannelMatrix8, 8, specificationsList);
operation.colorStudy(threeChannelMatrix9, 9, specificationsList);
operation.colorStudy(threeChannelMatrix10, 10, specificationsList);
System.out.println("=======================================" + i);
}
test2(templeConfig);

Loading…
Cancel
Save