package com.github.axet.lookup.proc;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
import com.github.axet.lookup.Lookup.NotFound;
import com.github.axet.lookup.common.FeatureK;
import com.github.axet.lookup.common.GFirst;
import com.github.axet.lookup.common.GPoint;
import com.github.axet.lookup.common.ImageBinary;
import com.github.axet.lookup.common.ImageBinaryChannel;
import com.github.axet.lookup.common.ImageBinaryChannelFeature;
import com.github.axet.lookup.common.ImageBinaryFeature;
import com.github.axet.lookup.common.ImageBinaryGrey;
import com.github.axet.lookup.common.ImageBinaryRGB;
import com.github.axet.lookup.common.ImageBinaryRGBFeature;
import com.github.axet.lookup.common.RectK;
* http://isas.uka.de/Material/AltePublikationen/briechle_spie2001.pdf
* NOT WORKING (check NCC.java)
* Fast Normalized cross correlation algorithm
static public List<GPoint> lookupAll(BufferedImage i, BufferedImage t, double threshold, float m) {
ImageBinaryRGB imageBinary = new ImageBinaryRGB(i);
ImageBinaryRGBFeature templateBinary = new ImageBinaryRGBFeature(t, threshold);
return lookupAll(imageBinary, templateBinary, m);
static public GPoint lookup(ImageBinary image, ImageBinaryFeature template, float m) {
List<GPoint> list = lookupAll(image, template, m);
Collections.sort(list, new GFirst());
static public List<GPoint> lookupAll(ImageBinary image, ImageBinaryFeature template, float m) {
return lookupAll(image, 0, 0, image.getWidth() - 1, image.getHeight() - 1, template, m);
static public List<GPoint> lookupAll(ImageBinary image, int x1, int y1, int x2, int y2,
ImageBinaryFeature template, float m) {
List<GPoint> list = new ArrayList<GPoint>();
for (int x = x1; x <= x2 - template.getWidth() + 1; x++) {
for (int y = y1; y <= y2 - template.getHeight() + 1; y++) {
List<ImageBinaryChannel> ci = image.getChannels();
List<ImageBinaryChannelFeature> ct = template.getFeatureChannels();
int ii = Math.min(ci.size(), ct.size());
double gg = Double.MAX_VALUE;
for (int i = 0; i < ii; i++) {
double g = gamma(ci.get(i), ct.get(i), x, y);
list.add(new GPoint(x, y, gg));
static double denominator(ImageBinaryChannel image, ImageBinaryChannel template, int xx, int yy) {
double di = image.dev2n(xx, yy, xx + template.getWidth() - 1, yy + template.getHeight() - 1);
double dt = template.dev2n();
return Math.sqrt(di * dt);
static double numerator(ImageBinaryChannel image, ImageBinaryChannelFeature template, int xx, int yy) {
for (FeatureK f : template.k) {
double ii = image.integral.sigma(xx + k.x1, yy + k.y1, xx + k.x2, yy + k.y2);
static public double gamma(ImageBinaryChannel image, ImageBinaryChannelFeature template, int xx, int yy) {
double d = denominator(image, template, xx, yy);
double n = numerator(image, template, xx, yy);