添加多种类干食切图

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

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

@ -56,7 +56,7 @@ public class CutFood {
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();
Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG();
@ -64,35 +64,25 @@ public class CutFood {
int x = matrixR.getX();
int y = matrixR.getY();
regionMap = new Matrix(x / size, y / size);
double sigmaPro = 0;
double sigmaOther = 0;
for (int i = 0; i <= x - size; i += size) {
for (int j = 0; j <= y - size; j += size) {
double r = getAvg(matrixR.getSonOfMatrix(i, j, size, size));
double g = getAvg(matrixG.getSonOfMatrix(i, j, size, size));
double b = getAvg(matrixB.getSonOfMatrix(i, j, size, size));
double[] rgb = new double[]{r / 255, g / 255, b / 255};
TypePro typePro = getType(rgb);
int index = typePro.index;//该区域所属类别
sigmaPro = sigmaPro + typePro.pro;
if (gm != null) {
sigmaOther = sigmaOther + gm.getProbabilityDensity(rgb);//概率密度
}
int index = getType(rgb);
regionMap.setNub(i / size, j / size, index);
}
}
return sigmaPro > sigmaOther;
}
public Map<Integer, Integer> getTypeNub(ThreeChannelMatrix threeChannelMatrix,
GMClustering gm) throws Exception {
if (getAvgPro(threeChannelMatrix, gm)) {//进行二次判定
return getTypeNub();
}
return null;
public Map<Integer, Integer> getTypeNub(ThreeChannelMatrix threeChannelMatrix
, int myType) throws Exception {
getAvgPro(threeChannelMatrix);
return getTypeNub(myType);
}
private Map<Integer, Integer> getTypeNub() throws Exception {
private Map<Integer, Integer> getTypeNub(int myType) throws Exception {
int size = templeConfig.getFood().getRegionSize();
double s = Math.pow(size, 2);
int xr = regionMap.getX();
@ -113,7 +103,7 @@ public class CutFood {
int type = gmBody.getType();
if (type != 1) {//背景直接过滤
double oneSize = meanMap.get(type).getRegionSize();
int nub = (int) (regionSize / oneSize);
int nub = (int) (regionSize / oneSize);//数量
if (nub > 0) {
if (gmTypeNub.containsKey(type)) {
int myNub = gmTypeNub.get(type);
@ -126,6 +116,9 @@ public class CutFood {
}
}
}
if (gmTypeNub.size() == 0) {
gmTypeNub.put(myType, 1);
}
return gmTypeNub;
}
@ -140,17 +133,7 @@ public class CutFood {
return isInsert;
}
class TypePro {
private int index;
private double pro;//概率密度
TypePro(int index, double pro) {
this.index = index;
this.pro = pro;
}
}
private TypePro getType(double[] rgb) throws Exception {
private int getType(double[] rgb) throws Exception {
int index = 0;
double max = 0;
for (Map.Entry<Integer, GMClustering> entry : meanMap.entrySet()) {
@ -163,10 +146,8 @@ public class CutFood {
}
if (max < 2) {
index = 1;
max = 0;
}
return new TypePro(index, max);
return index;
}
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) {//一次判定就属于干食,则无需进行二次判定
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, null));
} else {//一次判定属于非干食,则进行二次判定
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, food.getNotFoodMeanMap().get(id)));
if (isFood) {//判断类别,获取积分
Map<Integer, GMClustering> foods = food.getFoodMeanMap();
Map<Integer, GMClustering> test = new HashMap<>();
test.put(1, foods.get(1));
test.put(id, foods.get(id));
CutFood cutFood = new CutFood(templeConfig, test);
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, id));
}
regionBody.setType(id);
System.out.println("类别" + id);

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

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

@ -53,7 +53,7 @@ public class GMClustering extends MeanClustering {
RGBNorm rgbNorm = new RGBNorm();
matrices.add(rgbNorm);
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);
}

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

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

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

Loading…
Cancel
Save