添加多种类干食切图

pull/59/head
lidapeng 4 years ago
parent 7e1a01e650
commit 36a63eb512

@ -102,7 +102,6 @@ public class Convolution extends Frequency {
if (foodTypes == null) { if (foodTypes == null) {
foods = new int[]{type}; foods = new int[]{type};
} else { } else {
foods = new int[foodTypes.length + 1];
boolean isLife = false; boolean isLife = false;
for (int myType : foodTypes) { for (int myType : foodTypes) {
if (type == myType) { if (type == myType) {
@ -111,9 +110,14 @@ public class Convolution extends Frequency {
} }
} }
if (!isLife) { if (!isLife) {
for (int i = 0; i < foodTypes.length; i++) { foods = new int[foodTypes.length + 1];
foods[i] = foodTypes[i]; } else {
} foods = new int[foodTypes.length];
}
for (int i = 0; i < foodTypes.length; i++) {
foods[i] = foodTypes[i];
}
if (!isLife) {
foods[foodTypes.length] = type; foods[foodTypes.length] = type;
} }
} }

@ -56,7 +56,7 @@ public class CutFood {
return sigma / (x * y); return sigma / (x * y);
} }
private boolean getAvgPro(ThreeChannelMatrix threeChannelMatrix, GMClustering gm) throws Exception { private void getAvgPro(ThreeChannelMatrix threeChannelMatrix) throws Exception {
int size = templeConfig.getFood().getRegionSize(); int size = templeConfig.getFood().getRegionSize();
Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixG = threeChannelMatrix.getMatrixG();
@ -64,35 +64,25 @@ public class CutFood {
int x = matrixR.getX(); int x = matrixR.getX();
int y = matrixR.getY(); int y = matrixR.getY();
regionMap = new Matrix(x / size, y / size); regionMap = new Matrix(x / size, y / size);
double sigmaPro = 0;
double sigmaOther = 0;
for (int i = 0; i <= x - size; i += size) { for (int i = 0; i <= x - size; i += size) {
for (int j = 0; j <= y - size; j += size) { for (int j = 0; j <= y - size; j += size) {
double r = getAvg(matrixR.getSonOfMatrix(i, j, size, size)); double r = getAvg(matrixR.getSonOfMatrix(i, j, size, size));
double g = getAvg(matrixG.getSonOfMatrix(i, j, size, size)); double g = getAvg(matrixG.getSonOfMatrix(i, j, size, size));
double b = getAvg(matrixB.getSonOfMatrix(i, j, size, size)); double b = getAvg(matrixB.getSonOfMatrix(i, j, size, size));
double[] rgb = new double[]{r / 255, g / 255, b / 255}; double[] rgb = new double[]{r / 255, g / 255, b / 255};
TypePro typePro = getType(rgb); int index = getType(rgb);
int index = typePro.index;//该区域所属类别
sigmaPro = sigmaPro + typePro.pro;
if (gm != null) {
sigmaOther = sigmaOther + gm.getProbabilityDensity(rgb);//概率密度
}
regionMap.setNub(i / size, j / size, index); regionMap.setNub(i / size, j / size, index);
} }
} }
return sigmaPro > sigmaOther;
} }
public Map<Integer, Integer> getTypeNub(ThreeChannelMatrix threeChannelMatrix, public Map<Integer, Integer> getTypeNub(ThreeChannelMatrix threeChannelMatrix
GMClustering gm) throws Exception { , int myType) throws Exception {
if (getAvgPro(threeChannelMatrix, gm)) {//进行二次判定 getAvgPro(threeChannelMatrix);
return getTypeNub(); return getTypeNub(myType);
}
return null;
} }
private Map<Integer, Integer> getTypeNub() throws Exception { private Map<Integer, Integer> getTypeNub(int myType) throws Exception {
int size = templeConfig.getFood().getRegionSize(); int size = templeConfig.getFood().getRegionSize();
double s = Math.pow(size, 2); double s = Math.pow(size, 2);
int xr = regionMap.getX(); int xr = regionMap.getX();
@ -113,7 +103,7 @@ public class CutFood {
int type = gmBody.getType(); int type = gmBody.getType();
if (type != 1) {//背景直接过滤 if (type != 1) {//背景直接过滤
double oneSize = meanMap.get(type).getRegionSize(); double oneSize = meanMap.get(type).getRegionSize();
int nub = (int) (regionSize / oneSize); int nub = (int) (regionSize / oneSize);//数量
if (nub > 0) { if (nub > 0) {
if (gmTypeNub.containsKey(type)) { if (gmTypeNub.containsKey(type)) {
int myNub = gmTypeNub.get(type); int myNub = gmTypeNub.get(type);
@ -126,6 +116,9 @@ public class CutFood {
} }
} }
} }
if (gmTypeNub.size() == 0) {
gmTypeNub.put(myType, 1);
}
return gmTypeNub; return gmTypeNub;
} }
@ -140,17 +133,7 @@ public class CutFood {
return isInsert; return isInsert;
} }
class TypePro { private int getType(double[] rgb) throws Exception {
private int index;
private double pro;//概率密度
TypePro(int index, double pro) {
this.index = index;
this.pro = pro;
}
}
private TypePro getType(double[] rgb) throws Exception {
int index = 0; int index = 0;
double max = 0; double max = 0;
for (Map.Entry<Integer, GMClustering> entry : meanMap.entrySet()) { for (Map.Entry<Integer, GMClustering> entry : meanMap.entrySet()) {
@ -163,10 +146,8 @@ public class CutFood {
} }
if (max < 2) { if (max < 2) {
index = 1; index = 1;
max = 0;
} }
return index;
return new TypePro(index, max);
} }
public void study(int type, ThreeChannelMatrix threeChannelMatrix) throws Exception { public void study(int type, ThreeChannelMatrix threeChannelMatrix) throws Exception {

@ -167,11 +167,13 @@ public class Operation {//进行计算
} }
} }
} }
CutFood cutFood = new CutFood(templeConfig, food.getFoodMeanMap()); if (isFood) {//判断类别,获取积分
if (isFood) {//一次判定就属于干食,则无需进行二次判定 Map<Integer, GMClustering> foods = food.getFoodMeanMap();
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, null)); Map<Integer, GMClustering> test = new HashMap<>();
} else {//一次判定属于非干食,则进行二次判定 test.put(1, foods.get(1));
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, food.getNotFoodMeanMap().get(id))); test.put(id, foods.get(id));
CutFood cutFood = new CutFood(templeConfig, test);
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, id));
} }
regionBody.setType(id); regionBody.setType(id);
System.out.println("类别" + id); System.out.println("类别" + id);

@ -22,6 +22,18 @@ public class RGBNorm {
private double gmParameter;//gm混合系数 private double gmParameter;//gm混合系数
private double probabilitySigma = 0;//后验概率求和 private double probabilitySigma = 0;//后验概率求和
public double getVarAll() {
return varAll;
}
public Matrix getAvgMatrix() {
return avgMatrix;
}
public Matrix getVarMatrix() {
return varMatrix;
}
public List<double[]> getRgbs() { public List<double[]> getRgbs() {
return rgbs; return rgbs;
} }

@ -707,7 +707,6 @@ public class TempleConfig {
food.getNotFoodMeanMap().put(key, gmClustering); food.getNotFoodMeanMap().put(key, gmClustering);
} }
} }
//
DimensionMappingStudy dimensionAll = new DimensionMappingStudy(this); DimensionMappingStudy dimensionAll = new DimensionMappingStudy(this);
dimensionAll.start();//生成映射层并将已经保存的knn特征进行映射 dimensionAll.start();//生成映射层并将已经保存的knn特征进行映射
food.setDimensionMappingStudy(dimensionAll); food.setDimensionMappingStudy(dimensionAll);

@ -53,7 +53,7 @@ public class GMClustering extends MeanClustering {
RGBNorm rgbNorm = new RGBNorm(); RGBNorm rgbNorm = new RGBNorm();
matrices.add(rgbNorm); matrices.add(rgbNorm);
for (int j = i; j < i + size; j++) { for (int j = i; j < i + size; j++) {
feature[j - i] = matrix.getNumber(0, i); feature[j - i] = matrix.getNumber(0, j);
} }
rgbNorm.insertFeature(feature); rgbNorm.insertFeature(feature);
} }

@ -48,7 +48,7 @@ public class FeatureMapping extends Frequency implements PsoFunction {
@Override @Override
public double getResult(double[] parameter, int id) throws Exception { public double getResult(double[] parameter, int id) throws Exception {
return featuresMapping2(parameter); return featuresMapping(parameter);
} }
private double[] mapping(Matrix matrix, double[] parameter) throws Exception { private double[] mapping(Matrix matrix, double[] parameter) throws Exception {

@ -1,6 +1,5 @@
package org.wlld.param; package org.wlld.param;
import org.wlld.imageRecognition.CutFood;
import org.wlld.imageRecognition.border.GMClustering; import org.wlld.imageRecognition.border.GMClustering;
import org.wlld.imageRecognition.segmentation.DimensionMappingStudy; import org.wlld.imageRecognition.segmentation.DimensionMappingStudy;
import org.wlld.imageRecognition.segmentation.RgbRegression; import org.wlld.imageRecognition.segmentation.RgbRegression;

@ -80,7 +80,6 @@ public class FoodTest {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(a); ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(a);
Watershed watershed = new Watershed(threeChannelMatrix1, specificationsList, templeConfig); Watershed watershed = new Watershed(threeChannelMatrix1, specificationsList, templeConfig);
List<RegionBody> regionList = watershed.rainfall(); List<RegionBody> regionList = watershed.rainfall();
System.out.println("==");
} }
private static void look(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List<Specifications> specifications, private static void look(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List<Specifications> specifications,
@ -95,9 +94,6 @@ public class FoodTest {
int maxY = regionBody.getMaxY(); int maxY = regionBody.getMaxY();
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);
cutFood.getTypeNub(threeChannelMatrix1, null);
System.out.println("结束===================");
} }
} }

Loading…
Cancel
Save