增加聚类后的映射层

pull/59/head
lidapeng 4 years ago
parent f399fac619
commit 4c01112ba0

@ -93,7 +93,7 @@ public class MatrixOperation {
}
}
public static double errorNub(Matrix matrix, Matrix avgMatrix, int excNub) throws Exception {//求均方误差
public static double errorNub(Matrix matrix, Matrix avgMatrix) throws Exception {//求均方误差
int y = matrix.getY();
if (matrix.isRowVector() && avgMatrix.isRowVector() && y == avgMatrix.getY()) {
double[] subAll = new double[y];
@ -103,12 +103,11 @@ public class MatrixOperation {
double sub = Math.pow(avg - mySelf, 2);
subAll[j] = sub;
}
Arrays.sort(subAll);
double sigma = 0;
for (int i = 0; i < y - excNub; i++) {
for (int i = 0; i < y; i++) {
sigma = sigma + subAll[i];
}
return sigma / (y - excNub);
return sigma / y;
} else {
throw new Exception("this matrix is not rowVector or length different");
}

@ -7,8 +7,6 @@ import org.wlld.imageRecognition.border.Border;
import org.wlld.imageRecognition.border.Frame;
import org.wlld.imageRecognition.border.FrameBody;
import org.wlld.imageRecognition.segmentation.ColorFunction;
import org.wlld.imageRecognition.segmentation.DimensionMapping;
import org.wlld.param.Food;
import org.wlld.pso.PSO;
import org.wlld.tools.ArithUtil;
import org.wlld.tools.Frequency;
@ -100,62 +98,44 @@ public class Convolution extends Frequency {
public List<Double> getCenterColor(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig,
boolean isStudy, int tag) throws Exception {
int sqNub) throws Exception {
Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG();
Matrix matrixB = threeChannelMatrix.getMatrixB();
MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig, true);
int maxX = matrixR.getX();
int maxY = matrixR.getY();
ColorFunction colorFunction = new ColorFunction(threeChannelMatrix);
int[] minBorder = new int[]{0, 0};
int[] maxBorder = new int[]{maxX, maxY};
int[] maxBorder = new int[]{maxX - 1, maxY - 1};
//创建粒子群
PSO pso = new PSO(2, minBorder, maxBorder, 100, 100,
PSO pso = new PSO(2, minBorder, maxBorder, 200, 200,
colorFunction, 0.2, 1, 0.5, true, 10, 1);
List<double[]> positions = pso.start(0, 0);
List<double[]> feature = new ArrayList<>();//像素特征
List<double[]> positions = pso.start();
for (int i = 0; i < positions.size(); i++) {
double[] parameter = positions.get(i);
//获取取样坐标
int x = (int) parameter[0];
int y = (int) parameter[1];
double[] rgb = new double[]{matrixR.getNumber(x, y) / 255, matrixG.getNumber(x, y) / 255,
matrixB.getNumber(x, y) / 255};
feature.add(rgb);
double[] rgb = new double[]{matrixR.getNumber(x, y), matrixG.getNumber(x, y),
matrixB.getNumber(x, y)};
meanClustering.setColor(rgb);
}
if (isStudy) {//进行新维度映射排序
pso = new PSO(3, null, null, 200, 50,
new DimensionMapping(feature), 0.5, 2, 2, true, 0.5, 0.001);
List<double[]> mappings = pso.start(0, 0);//最小映射集合
double[] sigmaMapping = new double[3];//最小映射
for (int i = 0; i < mappings.size(); i++) {
double[] mapping = mappings.get(i);
for (int j = 0; j < sigmaMapping.length; j++) {
sigmaMapping[j] = sigmaMapping[j] + mapping[j];
}
}
for (int j = 0; j < sigmaMapping.length; j++) {
sigmaMapping[j] = sigmaMapping[j] / mappings.size();
}
//保存类别及映射
Food food = templeConfig.getFood();
Map<Integer, double[]> allMappings = food.getMappings();
if (allMappings == null) {
allMappings = new HashMap<>();
food.setMappings(allMappings);
meanClustering.start(true);
List<RGBNorm> rgbNorms = meanClustering.getMatrices();
List<Double> features = new ArrayList<>();
for (int i = 0; i < sqNub; i++) {
double[] rgb = rgbNorms.get(i).getRgb();
for (int j = 0; j < rgb.length; j++) {
features.add(rgb[j]);
}
allMappings.put(tag, sigmaMapping);
//根据映射值进行排序
} else {
}
return null;
return features;
}
public List<Double> getCenterTexture(ThreeChannelMatrix threeChannelMatrix, int size, int poolSize, TempleConfig templeConfig
, int sqNub, int tag) throws Exception {
public List<Double> getCenterTexture(ThreeChannelMatrix threeChannelMatrix, int size, TempleConfig templeConfig
, int sqNub, boolean isStudy) throws Exception {
MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig, true);
Matrix matrixR = threeChannelMatrix.getMatrixR();
Matrix matrixG = threeChannelMatrix.getMatrixG();
@ -166,8 +146,8 @@ public class Convolution extends Frequency {
//局部特征选区筛选
int nub = size * size;
int twoNub = nub * 2;
for (int i = 0; i <= xn - size; i++) {
for (int j = 0; j <= yn - size; j++) {
for (int i = 0; i <= xn - size; i += 3) {
for (int j = 0; j <= yn - size; j += 3) {
Matrix sonR = matrixR.getSonOfMatrix(i, j, size, size);
Matrix sonG = matrixG.getSonOfMatrix(i, j, size, size);
Matrix sonB = matrixB.getSonOfMatrix(i, j, size, size);
@ -204,14 +184,29 @@ public class Convolution extends Frequency {
List<Double> features = new ArrayList<>();
for (int i = 0; i < sqNub; i++) {
double[] rgb = rgbNorms.get(i).getRgb();
if (!isStudy) {
rgb = rgbMapping(rgb, i, templeConfig);
}
for (int j = 0; j < rgb.length; j++) {
features.add(rgb[j]);
}
}
// System.out.println(features);
return features;
}
private double[] rgbMapping(double[] rgb, int index, TempleConfig templeConfig) {//进行映射
double[] mapping = templeConfig.getFood().getMappingParameter();
int size = rgb.length;
int allSize = mapping.length / 2;
double[] mappingFeature = new double[size];
for (int i = 0; i < size; i++) {
int myIndex = size * index + i;
mappingFeature[i] = rgb[i] * mapping[myIndex] + mapping[allSize + myIndex];
}
return mappingFeature;
}
private void normalization(Matrix matrix) throws Exception {
for (int i = 0; i < matrix.getX(); i++) {

@ -0,0 +1,23 @@
package org.wlld.imageRecognition;
import org.wlld.imageRecognition.modelEntity.MappingBody;
import java.util.Comparator;
/**
* @param
* @DATA
* @Author LiDaPeng
* @Description
*/
public class MappingSort implements Comparator<MappingBody> {
@Override
public int compare(MappingBody o1, MappingBody o2) {
if (o1.getMappingNub() > o2.getMappingNub()) {
return -1;
} else if (o1.getMappingNub() < o2.getMappingNub()) {
return 1;
}
return 0;
}
}

@ -93,10 +93,8 @@ public class Operation {//进行计算
int ySize = maxY - minY;
//convolution.imgNormalization(threeChannelMatrix);
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
// List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(),
// templeConfig.getFeatureNub(), templeConfig);
List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(),
templeConfig.getPoolSize(), templeConfig, templeConfig.getFeatureNub(), tag);
// List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig, templeConfig.getFeatureNub());
List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub(), true);
if (templeConfig.isShowLog()) {
System.out.println(tag + ":" + feature);
}
@ -169,10 +167,9 @@ public class Operation {//进行计算
int xSize = maxX - minX;
int ySize = maxY - minY;
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
// List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(),
// templeConfig.getFeatureNub(), templeConfig);
List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(),
templeConfig.getPoolSize(), templeConfig, templeConfig.getFeatureNub(), 0);
//List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig, templeConfig.getFeatureNub());
List<Double> feature = convolution.getCenterTexture(threeChannelMatrix1, templeConfig.getFood().getRegionSize(), templeConfig, templeConfig.getFeatureNub(), false);
if (templeConfig.isShowLog()) {
System.out.println(feature);
}
@ -202,7 +199,7 @@ public class Operation {//进行计算
break;
}
regionBody.setType(id);
//System.out.println("类别" + id);
System.out.println("类别" + id);
}
return regionList;
}

@ -14,6 +14,10 @@ public class Knn {//KNN分类器
this.nub = nub;
}
public void setFeatureMap(Map<Integer, List<Matrix>> featureMap) {
this.featureMap = featureMap;
}
public Map<Integer, List<Matrix>> getFeatureMap() {
return featureMap;
}
@ -96,8 +100,8 @@ public class Knn {//KNN分类器
int type = entry.getKey();
List<Matrix> matrices = entry.getValue();
for (Matrix matrix : matrices) {
double dist = MatrixOperation.errorNub(vector, matrix, 0);
// double dist = MatrixOperation.getEDist(matrix, vector);
//double dist = MatrixOperation.errorNub(vector, matrix);
double dist = MatrixOperation.getEDist(matrix, vector);
compare(dists, types, dist, type);
}
}

@ -10,19 +10,13 @@ public class MappingBody {
private double[] feature;//特征
private double mappingNub;//映射好的值
public MappingBody(double[] mapping, double[] feature) {
public MappingBody(double[] feature) {
this.feature = feature;
double sigma = 0;
for (int i = 0; i < mapping.length; i++) {
sigma = sigma + Math.pow(mapping[i], 2);
for (int i = 0; i < feature.length; i++) {
sigma = sigma + Math.pow(feature[i], 2);
}
sigma = Math.sqrt(sigma);//映射维度的莫
double s = 0;
for (int j = 0; j < feature.length; j++) {
s = s + feature[j] * mapping[j];
}
mappingNub = s / sigma;
mappingNub = Math.sqrt(sigma);
}
public double[] getFeature() {

@ -1,41 +0,0 @@
package org.wlld.imageRecognition.segmentation;
import org.wlld.i.PsoFunction;
import org.wlld.tools.Frequency;
import java.util.List;
/**
* @param
* @DATA
* @Author LiDaPeng
* @Description
*/
public class DimensionMapping extends Frequency implements PsoFunction {
private List<double[]> features;
private int size;
public DimensionMapping(List<double[]> features) {
this.features = features;
size = features.size();
}
@Override
public double getResult(double[] parameter, int id) throws Exception {
double sigma = 0;
for (int i = 0; i < parameter.length; i++) {
sigma = sigma + Math.pow(parameter[i], 2);
}
sigma = Math.sqrt(sigma);
double[] mapping = new double[size];//在新维度的映射集合
for (int i = 0; i < size; i++) {
double[] feature = features.get(i);
double s = 0;
for (int j = 0; j < feature.length; j++) {
s = s + feature[j] * parameter[j];
}
mapping[i] = s / sigma;
}
return variance(mapping);
}
}

@ -0,0 +1,153 @@
package org.wlld.imageRecognition.segmentation;
import org.wlld.MatrixTools.Matrix;
import org.wlld.i.PsoFunction;
import org.wlld.imageRecognition.RGBNorm;
import org.wlld.imageRecognition.TempleConfig;
import org.wlld.pso.PSO;
import java.util.*;
/**
* @param
* @DATA
* @Author LiDaPeng
* @Description
*/
public class DimensionMappingStudy {
private double getDist(Matrix data1, Matrix data2) throws Exception {
int size = data1.getY();
double sigma = 0;
for (int i = 0; i < size; i++) {
sigma = sigma + Math.pow(data1.getNumber(0, i) - data2.getNumber(0, i), 2);
}
return Math.sqrt(sigma);
}
private double compareSame(List<Matrix> testFeatures) throws Exception {//比较同类找最小值
int size = testFeatures.size();
double max = 0;
for (int i = 0; i < size; i++) {
Matrix feature = testFeatures.get(i);
double min = -1;
for (int j = 0; j < size; j++) {
if (i != j) {
double dist = getDist(feature, testFeatures.get(j));
if (min == -1 || dist < min) {
min = dist;
}
}
}
if (min > max) {
max = min;
}
}
return max;
}
private double compareDifferent(List<Matrix> featureSame, List<Matrix> featureDifferent) throws Exception {
double min = -1;//比较异类取最小值
for (Matrix myFeature : featureSame) {
for (Matrix feature : featureDifferent) {
double dist = getDist(myFeature, feature);
if (min < 0 || dist < min) {
min = dist;
}
}
}
return min;
}
class MinType {
private double minDist;
private int type;
}
public void selfTest(TempleConfig templeConfig) throws Exception {//对模型数据进行自检测
Map<Integer, List<Matrix>> featureMap = templeConfig.getKnn().getFeatureMap();
Map<Integer, Double> maxMap = new HashMap<>();//保存与该类别最大间距
Map<Integer, List<MinType>> minMap = new HashMap<>();//保存与该类别最相似的类别,及距离值
for (Map.Entry<Integer, List<Matrix>> entry : featureMap.entrySet()) {
int key = entry.getKey();
List<MinType> minTypes = new ArrayList<>();
List<Matrix> myFeatures = entry.getValue();
double sameMax = compareSame(myFeatures);//同类之间的最大值
maxMap.put(key, sameMax);
for (Map.Entry<Integer, List<Matrix>> entry2 : featureMap.entrySet()) {
int testKey = entry2.getKey();
if (testKey != key) {//找出最小距离
List<Matrix> features = entry2.getValue();
MinType minType = new MinType();
double minDist = compareDifferent(myFeatures, features);//该类别的最小值
if (minDist < sameMax) {
minType.minDist = minDist;
minType.type = testKey;
minTypes.add(minType);
}
}
}
minMap.put(key, minTypes);
}
for (Map.Entry<Integer, Double> entry : maxMap.entrySet()) {
int key = entry.getKey();
double maxValue = entry.getValue();
System.out.println("=============================================");
System.out.println("类别:" + key + ",最大类间距为:" + maxValue);
List<MinType> minTypes = minMap.get(key);
for (int i = 0; i < minTypes.size(); i++) {
MinType minType = minTypes.get(i);
System.out.println("相近类:" + minType.type + ",最小类间距为:" + minType.minDist);
}
}
}
public void start(TempleConfig templeConfig) throws Exception {
Map<Integer, List<Matrix>> featureMap = templeConfig.getKnn().getFeatureMap();
FeatureMapping featureMapping = new FeatureMapping(featureMap);
int dimensionNub = templeConfig.getFeatureNub() * 3 * 2;//PSO维度
//创建粒子群
PSO pso = new PSO(dimensionNub, null, null, 200, 100,
featureMapping, 0.4, 2, 2, true, 0.2, 0.01);
List<double[]> mappings = pso.start();
int size = mappings.size();
double[] mappingSigma = new double[dimensionNub];
for (int i = 0; i < size; i++) {
double[] mapping = mappings.get(i);
for (int j = 0; j < mapping.length; j++) {
mappingSigma[j] = mappingSigma[j] + mapping[j];
}
}
for (int i = 0; i < mappingSigma.length; i++) {
mappingSigma[i] = mappingSigma[i] / size;
}
templeConfig.getFood().setMappingParameter(mappingSigma);
//还要把所有已存在的knn特征完成映射
featureMapping(featureMap, mappingSigma, templeConfig);
}
private void featureMapping(Map<Integer, List<Matrix>> featureMap, double[] mapping
, TempleConfig templeConfig) throws Exception {
Map<Integer, List<Matrix>> featureMap2 = new HashMap<>();
for (Map.Entry<Integer, List<Matrix>> entry : featureMap.entrySet()) {
int key = entry.getKey();
List<Matrix> features = entry.getValue();
List<Matrix> mappingFeatures = new ArrayList<>();
for (Matrix matrix : features) {
mappingFeatures.add(mapping(matrix, mapping));
}
featureMap2.put(key, mappingFeatures);
}
templeConfig.getKnn().setFeatureMap(featureMap2);
}
private Matrix mapping(Matrix feature, double[] mapping) throws Exception {
int size = feature.getY();
Matrix matrix = new Matrix(1, size);
for (int i = 0; i < size; i++) {
double nub = feature.getNumber(0, i) * mapping[i] + mapping[size + i];
matrix.setNub(0, i, nub);
}
return matrix;
}
}

@ -0,0 +1,115 @@
package org.wlld.imageRecognition.segmentation;
import org.wlld.MatrixTools.Matrix;
import org.wlld.i.PsoFunction;
import org.wlld.tools.Frequency;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @param
* @DATA
* @Author LiDaPeng
* @Description
*/
public class FeatureMapping extends Frequency implements PsoFunction {
private Map<Integer, List<Matrix>> featureMap;//特征
public FeatureMapping(Map<Integer, List<Matrix>> featureMap) {
this.featureMap = featureMap;
}
@Override
public double getResult(double[] parameter, int id) throws Exception {
return featuresMapping(parameter);
}
private double[] mapping(Matrix matrix, double[] parameter) throws Exception {
int size = matrix.getY();
double[] mapping = new double[size];
for (int i = 0; i < size; i++) {
mapping[i] = matrix.getNumber(0, i) * parameter[i] + parameter[size + i];
}
return mapping;
}
private double getDist(double[] data1, double[] data2) {
int size = data1.length;
double sigma = 0;
for (int i = 0; i < size; i++) {
sigma = sigma + Math.pow(data1[i] - data2[i], 2);
}
return Math.sqrt(sigma);
}
private double compareSame(List<double[]> testFeatures) {//比较同类找最大值
int size = testFeatures.size();
double max = 0;
for (int i = 0; i < size; i++) {
double min = -1;
double[] feature = testFeatures.get(i);
for (int j = 0; j < size; j++) {
if (i != j) {
double dist = getDist(feature, testFeatures.get(j));
if (min < 0 || dist < min) {
min = dist;
}
}
}
if (min > max) {
max = min;
}
}
return max;
}
private double compareDifferent(List<double[]> featureSame, List<double[]> featureDifferent) {
double min = -1;//比较异类取最小值
for (double[] myFeature : featureSame) {
for (double[] feature : featureDifferent) {
double dist = getDist(myFeature, feature);
if (min < 0 || dist < min) {
min = dist;
}
}
}
return min;
}
private double compareDist(Map<Integer, List<double[]>> mapping) {//比较距离
double sigma = 0;
for (Map.Entry<Integer, List<double[]>> entry : mapping.entrySet()) {
int key = entry.getKey();
List<double[]> myFeature = entry.getValue();
List<double[]> featureDifferent = new ArrayList<>();
for (Map.Entry<Integer, List<double[]>> entry2 : mapping.entrySet()) {
if (entry2.getKey() != key) {
featureDifferent.addAll(entry2.getValue());
}
}
double sameMax = compareSame(myFeature);//同类最大值
double differentMin = compareDifferent(myFeature, featureDifferent);//异类最小值
double sub = differentMin - sameMax;
sigma = sigma + sub;
}
return sigma;
}
private double featuresMapping(double[] parameter) throws Exception {//对当前所有数据进行映射
Map<Integer, List<double[]>> mapping = new HashMap<>();
for (Map.Entry<Integer, List<Matrix>> entry : featureMap.entrySet()) {
int key = entry.getKey();
List<Matrix> features = entry.getValue();//当前类别的所有特征
List<double[]> featureList = new ArrayList<>();
for (Matrix matrix : features) {
featureList.add(mapping(matrix, parameter));
}
mapping.put(key, featureList);
}
return compareDist(mapping);
}
}

@ -24,14 +24,14 @@ public class Food {
private int step = 1;//特征取样步长
private int speciesNub = 24;//种类数
private KNerveManger kNerveManger;
private Map<Integer, double[]> mappings;//类别映射集合
private double[] mappingParameter;//特征映射
public Map<Integer, double[]> getMappings() {
return mappings;
public double[] getMappingParameter() {
return mappingParameter;
}
public void setMappings(Map<Integer, double[]> mappings) {
this.mappings = mappings;
public void setMappingParameter(double[] mappingParameter) {
this.mappingParameter = mappingParameter;
}
public KNerveManger getkNerveManger() {

@ -66,7 +66,7 @@ public class PSO {
this.allPar = allPar;
}
public List<double[]> start(int fatherX, int fatherY) throws Exception {//开始进行迭代
public List<double[]> start() throws Exception {//开始进行迭代
int size = allPar.size();
for (int i = 0; i < times; i++) {
for (int j = 0; j < size; j++) {

@ -8,10 +8,7 @@ import org.wlld.config.Classifier;
import org.wlld.config.RZ;
import org.wlld.config.StudyPattern;
import org.wlld.imageRecognition.*;
import org.wlld.imageRecognition.segmentation.KNerveManger;
import org.wlld.imageRecognition.segmentation.RegionBody;
import org.wlld.imageRecognition.segmentation.RegionMapping;
import org.wlld.imageRecognition.segmentation.Specifications;
import org.wlld.imageRecognition.segmentation.*;
import org.wlld.nerveEntity.ModelParameter;
import org.wlld.param.Cutting;
import org.wlld.param.Food;
@ -68,14 +65,14 @@ public class FoodTest {
cutting.setRegionNub(100);
cutting.setMaxIou(2);
//knn参数
templeConfig.setKnnNub(15);
templeConfig.setKnnNub(1);
//池化比例
templeConfig.setPoolSize(2);//缩小比例
//聚类
templeConfig.setFeatureNub(5);//聚类特征数量
//菜品识别实体类
food.setShrink(5);//缩紧像素
food.setRegionSize(5);
food.setRegionSize(6);
KNerveManger kNerveManger = new KNerveManger(12, 24, 6000);
food.setkNerveManger(kNerveManger);
food.setRowMark(0.15);//0.12
@ -156,59 +153,65 @@ public class FoodTest {
operation.colorStudy(threeChannelMatrix23, 23, specificationsList, name);
operation.colorStudy(threeChannelMatrix24, 24, specificationsList, name);
}
System.out.println("========================");
kNerveManger.startStudy();
int i = 3;
// ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(name + "a" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix(name + "b" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix(name + "c" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix(name + "d" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix(name + "e" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix(name + "f" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix(name + "g" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix(name + "h" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix9 = picture.getThreeMatrix(name + "i" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix10 = picture.getThreeMatrix(name + "j" + i + ".jpg");
DimensionMappingStudy dimensionMappingStudy = new DimensionMappingStudy();
//System.out.println("映射前检查========================");
dimensionMappingStudy.selfTest(templeConfig);//检查
dimensionMappingStudy.start(templeConfig);//完成映射
System.out.println("映射后检查========================");
dimensionMappingStudy.selfTest(templeConfig);//检查
//System.out.println("========================");
// kNerveManger.startStudy();
int i = 4;
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(name + "a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix(name + "b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix(name + "c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix(name + "d" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix(name + "e" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix(name + "f" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix7 = picture.getThreeMatrix(name + "g" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix8 = picture.getThreeMatrix(name + "h" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix9 = picture.getThreeMatrix(name + "i" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix10 = picture.getThreeMatrix(name + "j" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix11 = picture.getThreeMatrix(name + "k" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix12 = picture.getThreeMatrix(name + "l" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix12 = picture.getThreeMatrix(name + "l" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix13 = picture.getThreeMatrix(name + "m" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix14 = picture.getThreeMatrix(name + "n" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix14 = picture.getThreeMatrix(name + "n" + i + ".jpg");
//
// ThreeChannelMatrix threeChannelMatrix15 = picture.getThreeMatrix(name + "o" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix16 = picture.getThreeMatrix(name + "p" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix17 = picture.getThreeMatrix(name + "q" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix18 = picture.getThreeMatrix(name + "r" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix19 = picture.getThreeMatrix(name + "s" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix20 = picture.getThreeMatrix(name + "t" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix21 = picture.getThreeMatrix(name + "u" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix22 = picture.getThreeMatrix(name + "v" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix23 = picture.getThreeMatrix(name + "w" + i + ".jpg");
// ThreeChannelMatrix threeChannelMatrix24 = picture.getThreeMatrix(name + "x" + i + ".jpg");
// operation.colorLook(threeChannelMatrix1, specificationsList);
// operation.colorLook(threeChannelMatrix2, specificationsList);
// operation.colorLook(threeChannelMatrix3, specificationsList);
// operation.colorLook(threeChannelMatrix4, specificationsList);
// operation.colorLook(threeChannelMatrix5, specificationsList);
// operation.colorLook(threeChannelMatrix6, specificationsList);
// operation.colorLook(threeChannelMatrix7, specificationsList);
// operation.colorLook(threeChannelMatrix8, specificationsList);
// operation.colorLook(threeChannelMatrix9, specificationsList);
// operation.colorLook(threeChannelMatrix10, specificationsList);
ThreeChannelMatrix threeChannelMatrix15 = picture.getThreeMatrix(name + "o" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix16 = picture.getThreeMatrix(name + "p" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix17 = picture.getThreeMatrix(name + "q" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix18 = picture.getThreeMatrix(name + "r" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix19 = picture.getThreeMatrix(name + "s" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix20 = picture.getThreeMatrix(name + "t" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix21 = picture.getThreeMatrix(name + "u" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix22 = picture.getThreeMatrix(name + "v" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix23 = picture.getThreeMatrix(name + "w" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix24 = picture.getThreeMatrix(name + "x" + i + ".jpg");
operation.colorLook(threeChannelMatrix1, specificationsList);
operation.colorLook(threeChannelMatrix2, specificationsList);
operation.colorLook(threeChannelMatrix3, specificationsList);
operation.colorLook(threeChannelMatrix4, specificationsList);
operation.colorLook(threeChannelMatrix5, specificationsList);
operation.colorLook(threeChannelMatrix6, specificationsList);
operation.colorLook(threeChannelMatrix7, specificationsList);
operation.colorLook(threeChannelMatrix8, specificationsList);
operation.colorLook(threeChannelMatrix9, specificationsList);
operation.colorLook(threeChannelMatrix10, specificationsList);
operation.colorLook(threeChannelMatrix11, specificationsList);
// operation.colorLook(threeChannelMatrix12, specificationsList);
operation.colorLook(threeChannelMatrix12, specificationsList);
operation.colorLook(threeChannelMatrix13, specificationsList);
// operation.colorLook(threeChannelMatrix14, specificationsList);
// operation.colorLook(threeChannelMatrix15, specificationsList);
// operation.colorLook(threeChannelMatrix16, specificationsList);
// operation.colorLook(threeChannelMatrix17, specificationsList);
// operation.colorLook(threeChannelMatrix18, specificationsList);
// operation.colorLook(threeChannelMatrix19, specificationsList);
// operation.colorLook(threeChannelMatrix20, specificationsList);
// operation.colorLook(threeChannelMatrix21, specificationsList);
// operation.colorLook(threeChannelMatrix22, specificationsList);
// operation.colorLook(threeChannelMatrix23, specificationsList);
// operation.colorLook(threeChannelMatrix24, specificationsList);
//
operation.colorLook(threeChannelMatrix14, specificationsList);
operation.colorLook(threeChannelMatrix15, specificationsList);
operation.colorLook(threeChannelMatrix16, specificationsList);
operation.colorLook(threeChannelMatrix17, specificationsList);
operation.colorLook(threeChannelMatrix18, specificationsList);
operation.colorLook(threeChannelMatrix19, specificationsList);
operation.colorLook(threeChannelMatrix20, specificationsList);
operation.colorLook(threeChannelMatrix21, specificationsList);
operation.colorLook(threeChannelMatrix22, specificationsList);
operation.colorLook(threeChannelMatrix23, specificationsList);
operation.colorLook(threeChannelMatrix24, specificationsList);
// test3(threeChannelMatrix1, operation, specificationsList, 1);
// test3(threeChannelMatrix2, operation, specificationsList, 2);
// test3(threeChannelMatrix3, operation, specificationsList, 3);
@ -232,7 +235,7 @@ public class FoodTest {
// test3(threeChannelMatrix21, operation, specificationsList, 21);
// test3(threeChannelMatrix22, operation, specificationsList, 22);
// test3(threeChannelMatrix23, operation, specificationsList, 23);
//test3(threeChannelMatrix24, operation, specificationsList, 24);
// test3(threeChannelMatrix24, operation, specificationsList, 24);
}

@ -84,7 +84,6 @@ public class ForestTest {
templeConfig.setFeatureNub(3);//聚类特征数量
//菜品识别实体类
food.setShrink(5);//缩紧像素
food.setTimes(1);//聚类数据增强
food.setRowMark(0.15);//0.12
food.setColumnMark(0.15);//0.25
food.setRegressionNub(20000);

@ -36,7 +36,7 @@ public class RegionCut {
long a = System.currentTimeMillis();
PSO pso = new PSO(2, minBorder, maxBorder, 100, 100,
colorFunction, 0.2, 1, 0.5, true, 10, 1);
pso.start(fatherX, fatherY);
pso.start();
long b = System.currentTimeMillis() - a;
System.out.println("时间:" + b);
// Matrix matrixR = threeChannelMatrix.getMatrixR();

Loading…
Cancel
Save