修改分水岭

pull/27/head
thenk008 5 years ago
parent 76faaabbe3
commit fc25269620

@ -8,10 +8,9 @@ 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 = 80;//一张图有多少份
public static final double Rain_Th = 336.41016151377545;//一概不落雨水
public static final int Region_Nub = 60;//一张图有多少份
public static final int Region_Dif = 2;//区域内的最大间隔
public static final double Region_Th = 0.3;//区域分割阈值
public static final double Region_Th = 0.05;//区域分割阈值
public static final double th = 0.88;//分水岭灰度阈值
public static final double rgbN = 441.6729559300637;//RGB范数归一化最大值
public static Matrix Vertical;

@ -130,7 +130,7 @@ public class Convolution extends Frequency {
for (int i = 0; i < sqNub; i++) {
feature.add(rgbNorms.get(i).getNorm());
}
System.out.println("feature==" + feature);
//System.out.println("feature==" + feature);
return feature;
}
@ -189,13 +189,17 @@ public class Convolution extends Frequency {
return border;
}
public void getRegionMatrix(ThreeChannelMatrix threeChannelMatrix, int x, int y, int xSize, int ySize) {
public ThreeChannelMatrix getRegionMatrix(ThreeChannelMatrix threeChannelMatrix, int x, int y, int xSize, int ySize) {
ThreeChannelMatrix threeChannelMatrix1 = new ThreeChannelMatrix();
Matrix matrixR = threeChannelMatrix.getMatrixR().getSonOfMatrix(x, y, xSize, ySize);
Matrix matrixG = threeChannelMatrix.getMatrixG().getSonOfMatrix(x, y, xSize, ySize);
Matrix matrixB = threeChannelMatrix.getMatrixB().getSonOfMatrix(x, y, xSize, ySize);
threeChannelMatrix.setMatrixR(matrixR);
threeChannelMatrix.setMatrixG(matrixG);
threeChannelMatrix.setMatrixB(matrixB);
threeChannelMatrix1.setMatrixR(matrixR);
threeChannelMatrix1.setMatrixG(matrixG);
threeChannelMatrix1.setMatrixB(matrixB);
threeChannelMatrix1.setH(threeChannelMatrix.getH());
threeChannelMatrix1.setMatrixRGB(threeChannelMatrix.getMatrixRGB());
return threeChannelMatrix1;
}
public List<FrameBody> getRegion(Matrix matrix, Frame frame) {

@ -81,7 +81,7 @@ public class MeanClustering {
}
//进行两者的比较
boolean isNext;
for (int i = 0; i < 40; i++) {
for (int i = 0; i < 50; i++) {
averageMatrix();
isNext = isNext();
if (isNext) {

@ -65,11 +65,12 @@ public class Operation {//进行计算
map.put(tag, 1.0);
List<Double> feature = convolution.getCenterColor(threeChannelMatrix, templeConfig.getPoolSize(),
templeConfig.getSensoryNerves().size());
System.out.println(feature);
intoDnnNetwork(1, feature, templeConfig.getSensoryNerves(), true, map, null);
}
public List<RegionBody> colorLook(ThreeChannelMatrix threeChannelMatrix, List<Specifications> specificationsList) throws Exception {
Watershed watershed = new Watershed(threeChannelMatrix.getH(), specificationsList);
Watershed watershed = new Watershed(threeChannelMatrix.getH(), specificationsList, templeConfig);
List<RegionBody> regionList = watershed.rainfall();
for (RegionBody regionBody : regionList) {
MaxPoint maxPoint = new MaxPoint();
@ -79,9 +80,10 @@ public class Operation {//进行计算
int maxY = regionBody.getMaxY();
int xSize = maxX - minX;
int ySize = maxY - minY;
convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
List<Double> feature = convolution.getCenterColor(threeChannelMatrix, templeConfig.getPoolSize(),
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(),
templeConfig.getSensoryNerves().size());
System.out.println(feature);
intoDnnNetwork(IdCreator.get().nextId(), feature, templeConfig.getSensoryNerves(), false, null, maxPoint);
regionBody.setType(maxPoint.getId());
}

@ -3,6 +3,7 @@ package org.wlld.imageRecognition;
import org.wlld.MatrixTools.Matrix;
import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.config.Classifier;
import org.wlld.config.Kernel;
import org.wlld.config.RZ;
import org.wlld.config.StudyPattern;
import org.wlld.function.ReLu;
@ -59,6 +60,33 @@ public class TempleConfig {
private int hiddenNerveNub = 9;//隐层神经元个数
private boolean isSoftMax = false;//是否启用softMax层
private int poolSize = 2;//池化尺寸
private double regionTh = 0.05;//绝对行数或者列数是否录入的阈值
private int regionNub = 60;//一张图行或列分多少个区块
private double hTh = 0.88;//灰度阈值
public double getRegionTh() {
return regionTh;
}
public void setRegionTh(double regionTh) {
this.regionTh = regionTh;
}
public int getRegionNub() {
return regionNub;
}
public void setRegionNub(int regionNub) {
this.regionNub = regionNub;
}
public double gethTh() {
return hTh;
}
public void sethTh(double hTh) {
this.hTh = hTh;
}
public int getPoolSize() {
return poolSize;

@ -17,6 +17,15 @@ public class RegionBody {
private int type;
private List<Integer> pointList = new ArrayList<>();
private Matrix regionMap;//分区图
private boolean isDestroy = false;
public boolean isDestroy() {
return isDestroy;
}
public void setDestroy(boolean destroy) {
isDestroy = destroy;
}
RegionBody(Matrix regionMap, int type) {
//System.out.println("type===" + type);

@ -2,6 +2,7 @@ package org.wlld.imageRecognition.segmentation;
import org.wlld.MatrixTools.Matrix;
import org.wlld.config.Kernel;
import org.wlld.imageRecognition.TempleConfig;
import org.wlld.tools.ArithUtil;
import java.util.*;
@ -18,18 +19,20 @@ public class Watershed {
private int xSize;//单元高度
private int ySize;//单元宽度
private double th = Kernel.th;//灰度阈值
private double regionTh = Kernel.Region_Th;
private double regionTh = Kernel.Region_Th;//绝对行数或者列数是否录入的阈值
private int regionSize = Kernel.Region_Dif;
private Map<Integer, RegionBody> regionBodyMap = new HashMap<>();
private int regionNub = Kernel.Region_Nub;//一张图分多少份
private double rainTh = Kernel.Rain_Th;
private Map<Integer, RegionBody> regionBodyMap = new HashMap<>();
private int xMax;
private int yMax;
private int id = 1;
private List<Specifications> specifications;
public Watershed(Matrix matrix, List<Specifications> specifications) throws Exception {
public Watershed(Matrix matrix, List<Specifications> specifications, TempleConfig templeConfig) throws Exception {
if (matrix != null && specifications != null && specifications.size() > 0) {
th = templeConfig.gethTh();
regionTh = templeConfig.getRegionTh();
regionNub = templeConfig.getRegionNub();
this.matrix = matrix;
this.specifications = specifications;
xSize = matrix.getX() / regionNub;
@ -365,6 +368,37 @@ public class Watershed {
regionBodyMap.put(id, new RegionBody(regionMap, id));
setType(id, i, j);
}
}
}
}
private void mergeRegions() {
for (Map.Entry<Integer, RegionBody> entry : regionBodyMap.entrySet()) {
RegionBody regionBody = entry.getValue();
if (!regionBody.isDestroy()) {
int minX = regionBody.getMinX();
int maxX = regionBody.getMaxX();
int minY = regionBody.getMinY();
int maxY = regionBody.getMaxY();
int key = entry.getKey();
for (Map.Entry<Integer, RegionBody> entry2 : regionBodyMap.entrySet()) {
RegionBody regionBody1 = entry2.getValue();
int testKey = entry2.getKey();
if (testKey != key && !regionBody1.isDestroy()) {
int otherMinX = regionBody1.getMinX();
int otherMaxX = regionBody1.getMaxX();
int otherMinY = regionBody1.getMinY();
int otherMaxY = regionBody1.getMaxY();
boolean one = (otherMaxY >= maxY && maxY > otherMinY) || (otherMaxY < maxY && otherMaxY > minY);
boolean two = maxX + xSize == otherMinX || otherMaxX + xSize == minX;
if (one && two) {//这个两个区域进行合并
regionBody1.setDestroy(true);//这个区域被合并了
regionBody.setX(otherMinX);
regionBody.setX(otherMaxX);
}
}
}
}
}
}
@ -439,18 +473,16 @@ public class Watershed {
}
}
double cover = (double) sigma / (double) size;//降雨率产生剧烈波动时则出现坐标
// System.out.println("x==" + i + ",y==" + j + ",cover==" + cover);
//System.out.println("x==" + i + ",y==" + j + ",cover==" + cover);
if (cover > th) {//降雨密度图
regionMap.setNub(i / xSize, j / ySize, 1);
}
}
}
getRegion();
lineRegion();
mergeRegion();
System.out.println(regionMap.getString());
System.out.println("========================");
//mergeRegion();
//createRegion();
createRegion();
mergeRegions();
}
private int getMinIndex(double[] array, double mySelf) {//获取最小值

@ -25,10 +25,14 @@ public class FoodTest {
}
public static void test2() throws Exception {
//test();
TempleConfig templeConfig = new TempleConfig();
Picture picture = new Picture();
templeConfig.setSensoryNerveNub(5);
templeConfig.setSensoryNerveNub(4);
templeConfig.setStudyPoint(0.01);
templeConfig.setRegionTh(0.05);
templeConfig.sethTh(0.88);
templeConfig.setRegionNub(80);
templeConfig.setSoftMax(true);
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
@ -37,19 +41,19 @@ public class FoodTest {
specificationsList.add(specifications);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
Operation operation = new Operation(templeConfig);
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("D:\\cai\\e/e3.jpg");
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("D:\\cai\\e/e2.jpg");
operation.colorLook(threeChannelMatrix, specificationsList);
}
public static void test() throws Exception {
TempleConfig templeConfig = new TempleConfig();
Picture picture = new Picture();
templeConfig.setSensoryNerveNub(5);
templeConfig.setSensoryNerveNub(4);
templeConfig.setStudyPoint(0.01);
templeConfig.setSoftMax(true);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
Operation operation = new Operation(templeConfig);
for (int j = 0; j < 2; j++) {
for (int j = 0; j < 1; j++) {
for (int i = 1; i <= 10; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\cai/a/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\cai/b/b" + i + ".jpg");
@ -62,20 +66,6 @@ public class FoodTest {
}
}
public static void rain() throws Exception {//降雨
Convolution convolution = new Convolution();
Picture picture = new Picture();
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("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(threeChannelMatrix.getH(), specificationsList);
List<RegionBody> regionList = watershed.rainfall();
}
public static void study() throws Exception {
TempleConfig templeConfig = new TempleConfig();
templeConfig.setSoftMax(true);

Loading…
Cancel
Save