diff --git a/src/main/java/net/sf/javaanpr/imageanalysis/Plate.java b/src/main/java/net/sf/javaanpr/imageanalysis/Plate.java index 5ddebb3..b5c3af9 100644 --- a/src/main/java/net/sf/javaanpr/imageanalysis/Plate.java +++ b/src/main/java/net/sf/javaanpr/imageanalysis/Plate.java @@ -127,7 +127,7 @@ private BufferedImage cutTopBottom(BufferedImage origin, PlateVerticalGraph grap private BufferedImage cutLeftRight(BufferedImage origin, PlateHorizontalGraph graph) { graph.applyProbabilityDistributor(new Graph.ProbabilityDistributor(0f, 0f, 2, 2)); - Vector peaks = graph.findPeak(3); + Vector peaks = graph.findPeak(); if (peaks.size() != 0) { Graph.Peak p = peaks.elementAt(0); return origin.getSubimage(p.getLeft(), 0, p.getDiff(), getImage().getHeight()); @@ -162,7 +162,7 @@ private PlateVerticalGraph histogramYaxis(BufferedImage bi) { } private PlateHorizontalGraph histogramXaxis(BufferedImage bi) { - PlateHorizontalGraph graph = new PlateHorizontalGraph(this); + PlateHorizontalGraph graph = new PlateHorizontalGraph(); int w = bi.getWidth(); int h = bi.getHeight(); for (int x = 0; x < w; x++) { diff --git a/src/main/java/net/sf/javaanpr/imageanalysis/PlateHorizontalGraph.java b/src/main/java/net/sf/javaanpr/imageanalysis/PlateHorizontalGraph.java index 2627fba..e474f78 100644 --- a/src/main/java/net/sf/javaanpr/imageanalysis/PlateHorizontalGraph.java +++ b/src/main/java/net/sf/javaanpr/imageanalysis/PlateHorizontalGraph.java @@ -25,31 +25,26 @@ public class PlateHorizontalGraph extends Graph { private static int horizontalDetectionType = Configurator.getConfigurator().getIntProperty("platehorizontalgraph_detectionType"); - private Plate handle; - - public PlateHorizontalGraph(Plate handle) { - this.handle = handle; - } - public float derivation(int index1, int index2) { - return this.yValues.elementAt(index1) - this.yValues.elementAt(index2); + return yValues.elementAt(index1) - yValues.elementAt(index2); } - public Vector findPeak(int count) { + public Vector findPeak() { if (PlateHorizontalGraph.horizontalDetectionType == 1) { - return this.findPeak_edgedetection(count); + return findPeakEdgedetection(); } - return this.findPeak_derivative(count); + return findPeakDerivative(); } - public Vector findPeak_derivative(int count) { - int a, b; - float maxVal = this.getMaxValue(); - for (a = 2; (-this.derivation(a, a + 4) < (maxVal * 0.2)) && (a < (this.yValues.size() - 2 - 2 - 4)); a++) { - // intentionally empty + public Vector findPeakDerivative() { + int a = 2; + int b = yValues.size() - 1 - 2; + float maxVal = getMaxValue(); + while ((-derivation(a, a + 4) < (maxVal * 0.2)) && (a < (yValues.size() - 2 - 2 - 4))) { + a++; } - for (b = this.yValues.size() - 1 - 2; (this.derivation(b - 4, b) < (maxVal * 0.2)) && (b > (a + 2)); b--) { - // intentionally empty + while ((derivation(b - 4, b) < (maxVal * 0.2)) && (b > (a + 2))) { + b--; } Vector outPeaks = new Vector(); outPeaks.add(new Peak(a, b)); @@ -57,18 +52,19 @@ public Vector findPeak_derivative(int count) { return outPeaks; } - public Vector findPeak_edgedetection(int count) { - float average = this.getAverageValue(); - int a, b; - for (a = 0; this.yValues.elementAt(a) < average; a++) { - // intentionally empty + public Vector findPeakEdgedetection() { + float average = getAverageValue(); + int a = 0; + int b = yValues.size() - 1; + while (yValues.elementAt(a) < average) { + a++; } - for (b = this.yValues.size() - 1; this.yValues.elementAt(b) < average; b--) { - // intentionally empty + while (yValues.elementAt(b) < average) { + b--; } Vector outPeaks = new Vector(); a = Math.max(a - 5, 0); - b = Math.min(b + 5, this.yValues.size()); + b = Math.min(b + 5, yValues.size()); outPeaks.add(new Peak(a, b)); super.peaks = outPeaks; return outPeaks;