Clean some stuff
This commit is contained in:
@@ -10,10 +10,15 @@ import java.util.function.Supplier;
|
||||
public class UseCaseService {
|
||||
|
||||
public Image reduceNoise(Image i0) {
|
||||
|
||||
double cutoff = 0.7 * getMaxCutoff(i0.getWidth(), i0.getHeight());
|
||||
|
||||
GrayScaleMatrix m0 = i0.toGrayScale();
|
||||
GrayScaleMatrix m1 = GlobalLinearFiltering.butterworthLowPassFiltering(m0, 10, 1);
|
||||
|
||||
GrayScaleMatrix m1 = measureTime("Butterworth low pass", () -> GlobalLinearFiltering.butterworthLowPassFiltering(m0, cutoff, 1));
|
||||
Image i1 = m1.toImage();
|
||||
return ComplexMorphology.medianFilter(i1, 9).toImage();
|
||||
|
||||
return measureTime("Median filter", () -> ComplexMorphology.medianFilter(i1, 5).toImage());
|
||||
}
|
||||
|
||||
public Image[] equalizeHistogram(Image image) {
|
||||
@@ -88,10 +93,19 @@ public class UseCaseService {
|
||||
return image;
|
||||
}
|
||||
|
||||
public <T> long measureTime(Supplier<T> operation) {
|
||||
public <T> T measureTime(String name, Supplier<T> operation) {
|
||||
long start = System.nanoTime();
|
||||
operation.get();
|
||||
return (System.nanoTime() - start) / 1_000_000;
|
||||
|
||||
T result = operation.get();
|
||||
|
||||
long elapsed = (System.nanoTime() - start) / 1_000_000;
|
||||
System.out.println(name + " took " + elapsed + " ms");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private double getMaxCutoff(int width, int height) {
|
||||
return Math.sqrt(Math.pow(width / 2.0, 2) + Math.pow(height / 2.0, 2));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user