/** * same as {@link #patchMean(float[][], int, int, int, int)} but the width and height are taken from data[0].length and data.length * @param data * @return the patch mean */ public static final float patchMean(final float[][] data){ return patchMean(data, 0, 0, data.length > 0 && data[0]!=null ? data[0].length : 0, data.length); } /**
@Override public Float prepareWorkingSpace(FImage template) { return MeanCenter.patchMean(template.pixels); } },
/** * same as {@link #patchMean(float[][], int, int, int, int)} but the width and height are taken from data[0].length and data.length * @param data * @return the patch mean */ public static final float patchMean(final float[][] data){ return patchMean(data, 0, 0, data.length > 0 && data[0]!=null ? data[0].length : 0, data.length); } /**
@Override public Float prepareWorkingSpace(FImage template) { return MeanCenter.patchMean(template.pixels); } },
@Override public final float computeMatchScore(final float[][] img, final int x, final int y, final float[][] template, final int templateX, final int templateY, final int templateWidth, final int templateHeight) { float imgMean = MeanCenter.patchMean(img, x, y, templateWidth, templateHeight); float templateMean = MeanCenter.patchMean(template, templateX, templateY, templateWidth, templateHeight); return computeMatchScore(img, x, y, imgMean, template, templateX, templateY, templateWidth, templateHeight, templateMean); }
@Override public final float computeMatchScore(final float[][] img, final int x, final int y, final float[][] template, final int templateX, final int templateY, final int templateWidth, final int templateHeight) { float imgMean = MeanCenter.patchMean(img, x,y,templateWidth, templateHeight); float templateMean = MeanCenter.patchMean(template, templateX, templateY, templateWidth, templateHeight); final int stopX1 = templateWidth + x; final int stopY1 = templateHeight + y; final int stopX2 = templateWidth + templateX; final int stopY2 = templateHeight + templateY; float score = 0; float s1 = 0; float s2 = 0; for (int yy1=y, yy2=templateY; yy1<stopY1 && yy2 < stopY2; yy1++, yy2++) { for (int xx1=x, xx2=templateX; xx1<stopX1 && xx2 < stopX2; xx1++, xx2++) { float ival = (img[yy1][xx1] - imgMean); float tval = (template[yy2][xx2] - templateMean); float prod = (ival * tval); score += prod; s1 += (ival * ival); s2 += (tval * tval); } } double norm = Math.sqrt(s1*s2); if (norm == 0) return 0; return (float) (score / norm); }
@Override public final float computeMatchScore(final float[][] img, final int x, final int y, final float[][] template, final int templateX, final int templateY, final int templateWidth, final int templateHeight) { float imgMean = MeanCenter.patchMean(img, x, y, templateWidth, templateHeight); float templateMean = MeanCenter.patchMean(template, templateX, templateY, templateWidth, templateHeight); return computeMatchScore(img, x, y, imgMean, template, templateX, templateY, templateWidth, templateHeight, templateMean); }
@Override protected final float computeMatchScore(final FImage image, final FImage template, final int x, final int y, final Object workingSpace) { final int width = template.width; final int height = template.height; float imgMean = MeanCenter.patchMean(image.pixels, x, y, width, height); float score = 0; float si = 0; final float st = (Float)workingSpace; final float[][] imageData = image.pixels; final float[][] templateData = template.pixels; for (int j=0; j<height; j++) { for (int i=0; i<width; i++) { float ival = imageData[j+y][i+x] - imgMean; float prod = (ival * templateData[j][i]); score += prod; si += (ival * ival); } } double norm = Math.sqrt(si * st); if (norm == 0) return 0; return (float) (score / norm); }
@Override public final float computeMatchScore(final float[][] img, final int x, final int y, final float[][] template, final int templateX, final int templateY, final int templateWidth, final int templateHeight) { float imgMean = MeanCenter.patchMean(img, x,y,templateWidth, templateHeight); float templateMean = MeanCenter.patchMean(template, templateX, templateY, templateWidth, templateHeight); final int stopX1 = templateWidth + x; final int stopY1 = templateHeight + y; final int stopX2 = templateWidth + templateX; final int stopY2 = templateHeight + templateY; float score = 0; float s1 = 0; float s2 = 0; for (int yy1=y, yy2=templateY; yy1<stopY1 && yy2 < stopY2; yy1++, yy2++) { for (int xx1=x, xx2=templateX; xx1<stopX1 && xx2 < stopX2; xx1++, xx2++) { float ival = (img[yy1][xx1] - imgMean); float tval = (template[yy2][xx2] - templateMean); float prod = (ival * tval); score += prod; s1 += (ival * ival); s2 += (tval * tval); } } double norm = Math.sqrt(s1*s2); if (norm == 0) return 0; return (float) (score / norm); }
@Override protected final float computeMatchScore(final FImage image, final FImage template, final int x, final int y, final Object workingSpace) { final int width = template.width; final int height = template.height; float imgMean = MeanCenter.patchMean(image.pixels, x, y, width, height); float score = 0; float si = 0; final float st = (Float)workingSpace; final float[][] imageData = image.pixels; final float[][] templateData = template.pixels; for (int j=0; j<height; j++) { for (int i=0; i<width; i++) { float ival = imageData[j+y][i+x] - imgMean; float prod = (ival * templateData[j][i]); score += prod; si += (ival * ival); } } double norm = Math.sqrt(si * st); if (norm == 0) return 0; return (float) (score / norm); }
@Override protected final float computeMatchScore(final FImage image, final FImage template, final int x, final int y, final Object workingSpace) { final float[][] imageData = image.pixels; final float[][] templateData = template.pixels; final float templateMean = (Float)workingSpace; final float imgMean = MeanCenter.patchMean(imageData); return computeMatchScore(imageData, x, y, imgMean, templateData, 0, 0, template.width, template.height, templateMean); }
@Override protected final float computeMatchScore(final FImage image, final FImage template, final int x, final int y, final Object workingSpace) { final float[][] imageData = image.pixels; final float[][] templateData = template.pixels; final float templateMean = (Float)workingSpace; final float imgMean = MeanCenter.patchMean(imageData); return computeMatchScore(imageData, x, y, imgMean, templateData, 0, 0, template.width, template.height, templateMean); }
@Override public void processImage(FImage image) { final int width = image.width; final int height = image.height; final float[][] data = image.pixels; image.subtractInplace(patchMean(data, 0, 0, width, height)); }
@Override public void processImage(FImage image) { final int width = image.width; final int height = image.height; final float[][] data = image.pixels; image.subtractInplace(patchMean(data, 0, 0, width, height)); }
threshImg = image.clone().threshold(MeanCenter.patchMean(image.pixels) - 10f / 255f); MaxFilter.filter(threshImg, dilations);