!25 增加分水岭切图

Merge pull request !25 from 逐光/test
pull/25/MERGE
逐光 5 years ago committed by Gitee
commit c14fd239ee

@ -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");
}
}

@ -8,6 +8,11 @@ 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_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;
public static Matrix All;

@ -106,8 +106,7 @@ public class Convolution extends Frequency {
return features;
}
public List<List<Double>> kc(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub
, int regionSize) throws Exception {
public List<Double> getCenterColor(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub) throws Exception {
Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG();
Matrix matrixB = threeChannelMatrix.getMatrixB();
@ -117,7 +116,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};
@ -126,113 +125,52 @@ public class Convolution extends Frequency {
}
meanClustering.start();
List<RGBNorm> 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<Double> feature = new ArrayList<>();
for (int i = 0; i < sqNub; i++) {
features[i] = rgbNorms.get(i).getNorm();
feature.add(rgbNorms.get(i).getNorm());
}
// System.out.println(Arrays.toString(features));
minNorm = ArithUtil.div(minNorm, 2);
return checkImage(matrixR, matrixG, matrixB, minNorm, regionSize, features);
return feature;
}
private List<List<Double>> checkImage(Matrix matrixR, Matrix matrixG, Matrix matrixB, double minNorm, int size
, double[] features) throws Exception {
List<List<Double>> 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<Double> list = getListFeature(myMatrixR, myMatrixG, myMatrixB, minNorm, features);
// System.out.println("feature====" + list);
lists.add(list);
}
}
return lists;
}
private List<Double> getListFeature(Matrix matrixR, Matrix matrixG, Matrix matrixB, double minNorm
, double[] features) throws Exception {
int x = matrixR.getX();
int y = matrixR.getY();
List<Double> list = new ArrayList<>();
double[] feat = new double[features.length];
List<RGBNorm> 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]);
}
return list;
private void regression(XYBody xyBody) {
//计算当前图形的线性回归
RegressionBody regressionBody = new RegressionBody();
regressionBody.lineRegression(xyBody.getY(), xyBody.getX(), this);
xyBody.setRegressionBody(regressionBody);
}
public List<List<Double>> imageTrance(Matrix matrix, int size, int featureNub) throws Exception {//矩阵和卷积核大小
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);//方差
//离散系数作为XAVG作为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;
}

@ -6,12 +6,21 @@ import java.util.Map;
public class CoverBody {
private List<List<Double>> feature;//特征
private Map<Integer, Double> tag;//标注
private List<List<Double>> cFeature;//卷积特征
private int type;
public int getType() {
return type;
}
public List<List<Double>> getcFeature() {
return cFeature;
}
public void setcFeature(List<List<Double>> cFeature) {
this.cFeature = cFeature;
}
public void setType(int type) {
this.type = type;
}

@ -6,6 +6,20 @@ 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;
}
public int getId() {
return id;
@ -13,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;

@ -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;
@ -285,6 +286,17 @@ public class Operation {//进行计算
lvq.insertMatrixBody(matrixBody);
}
private List<Double> getFeatures(Matrix matrix) throws Exception {
List<Double> 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<Double> getFeature(Matrix matrix) throws Exception {//将特征矩阵转化为集合并除10
List<Double> list = new ArrayList<>();
Normalization normalization = templeConfig.getNormalization();
@ -298,7 +310,6 @@ public class Operation {//进行计算
} else {
list.add(0.0);
}
}
}
return list;
@ -560,6 +571,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<Double> 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) {
@ -588,6 +610,7 @@ public class Operation {//进行计算
private int getClassificationIdByDnn(Matrix myMatrix) throws Exception {
List<Double> 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();
@ -601,6 +624,7 @@ public class Operation {//进行计算
for (Map.Entry<Integer, Matrix> 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();

@ -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;

@ -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<Integer, Matrix> 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) {

@ -6,6 +6,24 @@ public class ThreeChannelMatrix {
Matrix matrixR;
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;
}
public void setH(Matrix h) {
H = h;
}
public Matrix getMatrixR() {
return matrixR;

@ -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;
}
}

@ -16,7 +16,7 @@ public class LVQ {
private int typeNub;//原型聚类个数,即分类个数(需要模型返回)
private MatrixBody[] model;//原型向量(需要模型返回)
private List<MatrixBody> matrixList = new ArrayList<>();
private double studyPoint = 0.1;//量化学习率
private double studyPoint = 0.01;//量化学习率
private int length;//向量长度(需要返回)
private boolean isReady = false;
private int lvqNub;

@ -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<List<Double>> mappingMatrix(int size) {
int len = X.length - size;
List<List<Double>> lists = new ArrayList<>();
for (int i = 0; i < len; i += size) {
List<Double> 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);
}
}

@ -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<Integer, RegionBody> 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;
}
}

@ -1,14 +1,46 @@
package org.wlld.imageRecognition.segmentation;
import org.wlld.MatrixTools.Matrix;
import java.util.ArrayList;
import java.util.List;
/**
* @author lidapeng
* @description
*/
public class RegionBody {
private int minX = -1;
private int minY = -1;
private int maxX;
private int maxY;
public void setX(int x) {
if (x < minX || minX == -1) {
minX = x;
}
if (x > maxX) {
maxX = x;
}
}
public void setY(int y) {
if (y < minY || minY == -1) {
minY = y;
}
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;
}
}

@ -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;
}
}

@ -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];

@ -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,6 +23,18 @@ import java.util.Map;
*/
public class CoverTest {
public static void main(String[] args) throws Exception {
// 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();
}
@ -40,58 +53,51 @@ 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.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) 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;
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");
if (operation == null) {
operation = getModel();
}
for (int i = 1; i < 100; i++) {
String na = "D:\\pic\\test/" + name + i + ".jpg";
//System.out.println("name======================" + na);
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na);
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);
int id = 0;
double point = 0;
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("key==" + key + ",value==" + value);
if (value > point) {
point = value;
id = key;
}
}
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);
if (id != t) {
wrong++;
}
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("=============================");
}
System.out.println("错误率:" + wrong + "%");
}
public static void cover2(Operation operation, String url) throws Exception {
Picture picture = new Picture();
Matrix matrix = picture.getImageMatrixByLocal(url);
double type = operation.toSeeById(matrix, 1);
System.out.println("type==" + type);
}
public static void cover() throws Exception {
@ -101,39 +107,27 @@ public class CoverTest {
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.setHiddenNerveNub(9);
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 < 100; i++) {
Map<Integer, ThreeChannelMatrix> 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/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, 2, 40);
test(operation, 2, 3, 18, "d", 2);
}
}

@ -2,119 +2,116 @@ 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.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.*;
import java.util.ArrayList;
import java.util.List;
public class FoodTest {
public static void main(String[] args) throws Exception {
//food();
rain();
}
public static void rain() throws Exception {//降雨
Convolution convolution = new Convolution();
Picture picture = new Picture();
Matrix matrix = picture.getImageMatrixByLocal("D:\\share/c.png");
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
specifications.setWidth(400);
specifications.setHeight(400);
specificationsList.add(specifications);
Watershed watershed = new Watershed(matrix, specificationsList);
List<RegionBody> regionList = watershed.rainfall();
food();
}
public static void food() throws Exception {
public static void study() throws Exception {
Picture picture = new Picture();
TempleConfig templeConfig = new TempleConfig();
Convolution convolution = new Convolution();
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("");
List<Double> feature = convolution.getCenterColor(threeChannelMatrix, 2, 4);
}
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);
Operation operation = new Operation(templeConfig);
public static void food() throws Exception {
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);//计算类
// 一阶段
for (int j = 0; j < 2; j++) {
for (int i = 1; i < 101; 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:\\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);
operation.learning(c, 3, false);
//operation.learning(d, 4, false);
}
}
//二阶段
// 二阶段 归一化
for (int i = 1; i < 101; 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:\\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());
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 j = 0; j < 3; j++) {
for (int i = 1; i < 101; 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:\\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);
operation.learning(c, 3, true);
//operation.learning(d, 4, 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 = 10; i <= 20; i++) {
for (int i = 1; i <= 100; 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:\\pic\\1/a" + i + ".jpg");
allNub++;
int an = operation.toSee(a);
if (an != 1) {
wrong++;
}
int bn = operation.toSee(b);
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) + "%");
ModelParameter modelParameter = templeConfig.getModel();
String model = JSON.toJSONString(modelParameter);
System.out.println(model);
}
}

@ -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);

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save