com.machinezoo.sourceafis.engine.extractor.ImageResizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sourceafis Show documentation
Show all versions of sourceafis Show documentation
Fingerprint recognition engine that takes a pair of human fingerprint images and returns their similarity score. Supports efficient 1:N search.
// Part of SourceAFIS for Java: https://sourceafis.machinezoo.com/java
package com.machinezoo.sourceafis.engine.extractor;
import com.machinezoo.sourceafis.engine.primitives.*;
public class ImageResizer {
private static DoubleMatrix resize(DoubleMatrix input, int newWidth, int newHeight) {
if (newWidth == input.width && newHeight == input.height)
return input;
DoubleMatrix output = new DoubleMatrix(newWidth, newHeight);
double scaleX = newWidth / (double)input.width;
double scaleY = newHeight / (double)input.height;
double descaleX = 1 / scaleX;
double descaleY = 1 / scaleY;
for (int y = 0; y < newHeight; ++y) {
double y1 = y * descaleY;
double y2 = y1 + descaleY;
int y1i = (int)y1;
int y2i = Math.min((int)Math.ceil(y2), input.height);
for (int x = 0; x < newWidth; ++x) {
double x1 = x * descaleX;
double x2 = x1 + descaleX;
int x1i = (int)x1;
int x2i = Math.min((int)Math.ceil(x2), input.width);
double sum = 0;
for (int oy = y1i; oy < y2i; ++oy) {
double ry = Math.min(oy + 1, y2) - Math.max(oy, y1);
for (int ox = x1i; ox < x2i; ++ox) {
double rx = Math.min(ox + 1, x2) - Math.max(ox, x1);
sum += rx * ry * input.get(ox, oy);
}
}
output.set(x, y, sum * (scaleX * scaleY));
}
}
return output;
}
public static DoubleMatrix resize(DoubleMatrix input, double dpi) {
return resize(input, (int)Math.round(500.0 / dpi * input.width), (int)Math.round(500.0 / dpi * input.height));
}
}