public void setGreenBinCount(int greenBinCount) {
this.greenBins = greenBinCount;
}
public void setBlueBinCount(int blueBinCount) {
this.blueBins = blueBinCount;
}
public float[] filter(BufferedImage src, BufferedImage dest) {
int width = src.getWidth();
int height = src.getHeight();
int[] inPixels = new int[width*height];
float[] histogramData = new float[redBins * greenBins * blueBins];
getRGB( src, 0, 0, width, height, inPixels );
int index = 0;
int redIdx = 0, greenIdx = 0, blueIdx = 0;
int singleIndex = 0;
float total = 0;
for(int row=0; row<height; row++) {
int ta = 0, tr = 0, tg = 0, tb = 0;
for(int col=0; col<width; col++) {
index = row * width + col;
ta = (inPixels[index] >> 24) & 0xff;
tr = (inPixels[index] >> 16) & 0xff;
tg = (inPixels[index] >> 8) & 0xff;
tb = inPixels[index] & 0xff;
redIdx = (int)getBinIndex(redBins, tr, 255);
greenIdx = (int)getBinIndex(greenBins, tg, 255);
blueIdx = (int)getBinIndex(blueBins, tb, 255);
singleIndex = redIdx + greenIdx * redBins + blueIdx * redBins * greenBins;
histogramData[singleIndex] += 1;
total += 1;
}
}
// start to normalize the histogram data
for (int i = 0; i < histogramData.length; i++)
{
histogramData[i] = histogramData[i] / total;
}
return histogramData;
}
/**
* Bhattacharyya Coefficient
* http://www.cse.yorku.ca/~kosta/CompVis_Notes/bhattacharyya.pdf
*
* @return
*/
public double modelMatch() {
HistogramFilter hfilter = new HistogramFilter();
float[] sourceData = hfilter.filter(sourceImage, null);
float[] candidateData = hfilter.filter(candidateImage, null);
double[] mixedData = new double[sourceData.length];
for(int i=0; i<sourceData.length; i++ ) {
mixedData[i] = Math.sqrt(sourceData[i] * candidateData[i]);
}
// The values of Bhattacharyya Coefficient ranges from 0 to 1,
double similarity = 0;
for(int i=0; i<mixedData.length; i++ ) {
similarity += mixedData[i];
}
// The degree of similarity
return similarity;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有