parent
824874c078
commit
f399fac619
@ -0,0 +1,35 @@
|
|||||||
|
package org.wlld.imageRecognition.modelEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param
|
||||||
|
* @DATA
|
||||||
|
* @Author LiDaPeng
|
||||||
|
* @Description 映射体
|
||||||
|
*/
|
||||||
|
public class MappingBody {
|
||||||
|
private double[] feature;//特征
|
||||||
|
private double mappingNub;//映射好的值
|
||||||
|
|
||||||
|
public MappingBody(double[] mapping, double[] feature) {
|
||||||
|
this.feature = feature;
|
||||||
|
double sigma = 0;
|
||||||
|
for (int i = 0; i < mapping.length; i++) {
|
||||||
|
sigma = sigma + Math.pow(mapping[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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getFeature() {
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMappingNub() {
|
||||||
|
return mappingNub;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package org.wlld.imageRecognition.segmentation;
|
||||||
|
|
||||||
|
import org.wlld.MatrixTools.Matrix;
|
||||||
|
import org.wlld.i.PsoFunction;
|
||||||
|
import org.wlld.imageRecognition.ThreeChannelMatrix;
|
||||||
|
import org.wlld.tools.Frequency;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param
|
||||||
|
* @DATA
|
||||||
|
* @Author LiDaPeng
|
||||||
|
* @Description
|
||||||
|
*/
|
||||||
|
public class ColorFunction extends Frequency implements PsoFunction {
|
||||||
|
private Matrix matrixR;
|
||||||
|
private Matrix matrixG;
|
||||||
|
private Matrix matrixB;
|
||||||
|
private Map<Integer, double[]> pixels = new HashMap<>();
|
||||||
|
|
||||||
|
public ColorFunction(ThreeChannelMatrix threeChannelMatrix) {
|
||||||
|
matrixR = threeChannelMatrix.getMatrixR();
|
||||||
|
matrixG = threeChannelMatrix.getMatrixG();
|
||||||
|
matrixB = threeChannelMatrix.getMatrixB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getResult(double[] parameter, int id) throws Exception {
|
||||||
|
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};
|
||||||
|
pixels.put(id, rgb);
|
||||||
|
//计算当前方差
|
||||||
|
return getDist();
|
||||||
|
//return getRegression();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getRegression() throws Exception {
|
||||||
|
RgbRegression rgbRegression = new RgbRegression(pixels.size());
|
||||||
|
for (Map.Entry<Integer, double[]> entry : pixels.entrySet()) {
|
||||||
|
double[] rgb = entry.getValue();
|
||||||
|
rgbRegression.insertRGB(rgb);
|
||||||
|
}
|
||||||
|
double sigma = 0;
|
||||||
|
if (rgbRegression.regression()) {
|
||||||
|
for (Map.Entry<Integer, double[]> entry : pixels.entrySet()) {
|
||||||
|
double[] rgb = entry.getValue();
|
||||||
|
sigma = sigma + rgbRegression.getDisError(rgb);
|
||||||
|
}
|
||||||
|
sigma = sigma / pixels.size();
|
||||||
|
}
|
||||||
|
return sigma;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getDist() {//计算当前均方误差
|
||||||
|
double[] r = new double[pixels.size()];
|
||||||
|
double[] g = new double[pixels.size()];
|
||||||
|
double[] b = new double[pixels.size()];
|
||||||
|
for (Map.Entry<Integer, double[]> entry : pixels.entrySet()) {
|
||||||
|
double[] rgb = entry.getValue();
|
||||||
|
int key = entry.getKey();
|
||||||
|
r[key] = rgb[0];
|
||||||
|
g[key] = rgb[1];
|
||||||
|
b[key] = rgb[2];
|
||||||
|
}
|
||||||
|
return dc(r) + dc(g) + dc(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue