Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/net/sf/javaanpr/imageanalysis/Band.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public BufferedImage renderGraph() {
return this.graphHandle.renderHorizontally(this.getWidth(), 100);
}

private Vector<Graph.Peak> computeGraph() {
private Vector<Peak> computeGraph() {
if (this.graphHandle != null) {
return this.graphHandle.peaks;
}
Expand All @@ -59,12 +59,12 @@ private Vector<Graph.Peak> computeGraph() {
*/
public Vector<Plate> getPlates() {
Vector<Plate> out = new Vector<Plate>();
Vector<Graph.Peak> peaks = this.computeGraph();
Vector<Peak> peaks = this.computeGraph();
for (int i = 0; i < peaks.size(); i++) {
// Cut from the original image of the plate and save to a vector.
// ATTENTION: Cutting from original,
// we have to apply an inverse transformation to the coordinates calculated from imageCopy
Graph.Peak p = peaks.elementAt(i);
Peak p = peaks.elementAt(i);
out.add(new Plate(getImage().getSubimage(p.getLeft(), 0, p.getDiff(), getImage().getHeight())));
}
return out;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/javaanpr/imageanalysis/BandGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public BandGraph(Band handle) {
}

public Vector<Peak> findPeaks(int count) {
Vector<Graph.Peak> outPeaks = new Vector<Graph.Peak>();
Vector<Peak> outPeaks = new Vector<Peak>();
for (int c = 0; c < count; c++) {
float maxValue = 0.0f;
int maxIndex = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/javaanpr/imageanalysis/CarSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public BufferedImage renderGraph() {
return this.graphHandle.renderVertically(100, this.getHeight());
}

private Vector<Graph.Peak> computeGraph() {
private Vector<Peak> computeGraph() {
if (this.graphHandle != null) {
return this.graphHandle.peaks;
}
Expand All @@ -75,12 +75,12 @@ private Vector<Graph.Peak> computeGraph() {
*/
public Vector<Band> getBands() {
Vector<Band> out = new Vector<Band>();
Vector<Graph.Peak> peaks = this.computeGraph();
Vector<Peak> peaks = this.computeGraph();
for (int i = 0; i < peaks.size(); i++) {
// Cut from the original image of the plate and save to a vector.
// ATTENTION: Cutting from original,
// we have to apply an inverse transformation to the coordinates calculated from imageCopy
Graph.Peak p = peaks.elementAt(i);
Peak p = peaks.elementAt(i);
out.add(new Band(getImage().getSubimage(0, (p.getLeft()), getImage().getWidth(), (p.getDiff()))));
}
return out;
Expand Down
62 changes: 11 additions & 51 deletions src/main/java/net/sf/javaanpr/imageanalysis/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void deActualizeFlags() {
*/
public boolean allowedInterval(Vector<Peak> peaks, int xPosition) {
for (Peak peak : peaks) {
if ((peak.left <= xPosition) && (xPosition <= peak.right)) {
if ((peak.getLeft() <= xPosition) && (xPosition <= peak.getRight())) {
return false;
}
}
Expand Down Expand Up @@ -185,9 +185,9 @@ public BufferedImage renderHorizontally(int width, int height) {
final double multConst = (double) width / this.yValues.size();
int i = 0;
for (Peak p : this.peaks) {
graphicContent.drawLine((int) (p.left * multConst), 0, (int) (p.center * multConst), 30);
graphicContent.drawLine((int) (p.center * multConst), 30, (int) (p.right * multConst), 0);
graphicContent.drawString(i + ".", (int) (p.center * multConst) - 5, 42);
graphicContent.drawLine((int) (p.getLeft() * multConst), 0, (int) (p.getCenter() * multConst), 30);
graphicContent.drawLine((int) (p.getCenter() * multConst), 30, (int) (p.getRight() * multConst), 0);
graphicContent.drawString(i + ".", (int) (p.getCenter() * multConst) - 5, 42);
i++;
}
}
Expand Down Expand Up @@ -237,9 +237,13 @@ public BufferedImage renderVertically(int width, int height) {
int i = 0;
double multConst = (double) height / this.yValues.size();
for (Peak p : this.peaks) {
graphicContent.drawLine(width, (int) (p.left * multConst), width - 30, (int) (p.center * multConst));
graphicContent.drawLine(width - 30, (int) (p.center * multConst), width, (int) (p.right * multConst));
graphicContent.drawString(i + ".", width - 38, (int) (p.center * multConst) + 5);
graphicContent.drawLine(width,
(int) (p.getLeft() * multConst),
width - 30, (int) (p.getCenter() * multConst));
graphicContent.drawLine(width - 30,
(int) (p.getCenter() * multConst), width,
(int) (p.getRight() * multConst));
graphicContent.drawString(i + ".", width - 38, (int) (p.getCenter() * multConst) + 5);
i++;
}
}
Expand Down Expand Up @@ -330,48 +334,4 @@ public Vector<Float> distribute(Vector<Float> peaks) {
return distributedPeaks;
}
}

public class Peak {
private int left, center, right;

public Peak(int left, int center, int right) {
this.left = left;
this.center = center;
this.right = right;
}

public Peak(int left, int right) {
this.left = left;
this.center = (left + right) / 2;
this.right = right;
}

public int getLeft() {
return this.left;
}

public void setLeft(int left) {
this.left = left;
}

public int getRight() {
return this.right;
}

public void setRight(int right) {
this.right = right;
}

public int getCenter() {
return this.center;
}

public void setCenter(int center) {
this.center = center;
}

public int getDiff() {
return this.right - this.left;
}
}
}
61 changes: 61 additions & 0 deletions src/main/java/net/sf/javaanpr/imageanalysis/Peak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2013 JavaANPR contributors
* Copyright 2006 Ondrej Martinsky
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package net.sf.javaanpr.imageanalysis;

public class Peak {
private int left, center, right;

public Peak(int left, int center, int right) {
this.left = left;
this.center = center;
this.right = right;
}

public Peak(int left, int right) {
this.left = left;
this.center = (left + right) / 2;
this.right = right;
}

public int getLeft() {
return this.left;
}

public void setLeft(int left) {
this.left = left;
}

public int getRight() {
return this.right;
}

public void setRight(int right) {
this.right = right;
}

public int getCenter() {
return this.center;
}

public void setCenter(int center) {
this.center = center;
}

public int getDiff() {
return this.right - this.left;
}
}
45 changes: 45 additions & 0 deletions src/main/java/net/sf/javaanpr/imageanalysis/PeakComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2013 JavaANPR contributors
* Copyright 2006 Ondrej Martinsky
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package net.sf.javaanpr.imageanalysis;

import java.util.Comparator;
import java.util.Vector;

public class PeakComparator implements Comparator<Peak> {
private Vector<Float> yValues;

public PeakComparator(Vector<Float> yValues) {
this.yValues = yValues;
}

private float getPeakValue(Peak peak) {
// heuristic: how high (wide on the graph) is the candidate character (prefer higher ones)
// return peak.getDiff();

// heuristic: height of the peak
return yValues.elementAt(peak.getCenter());

// heuristic: how far from the center is the candidate
// int peakCenter = (peak.getRight() + (peak.getLeft() )/2;
// return Math.abs(peakCenter - yValues.size()/2);
}

@Override
public int compare(Peak peak1, Peak peak2) {
return Double.compare(getPeakValue(peak2), getPeakValue(peak1));
}
}
14 changes: 7 additions & 7 deletions src/main/java/net/sf/javaanpr/imageanalysis/Plate.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BufferedImage renderGraph() {
return this.graphHandle.renderHorizontally(this.getWidth(), 100);
}

private Vector<Graph.Peak> computeGraph() {
private Vector<Peak> computeGraph() {
if (this.graphHandle != null) {
return this.graphHandle.peaks;
}
Expand All @@ -59,12 +59,12 @@ private Vector<Graph.Peak> computeGraph() {

public Vector<Char> getChars() {
Vector<Char> out = new Vector<Char>();
Vector<Graph.Peak> peaks = this.computeGraph();
Vector<Peak> peaks = this.computeGraph();
for (int i = 0; i < peaks.size(); i++) {
// Cut from the original image of the plate and save to a vector.
// ATTENTION: Cutting from original,
// we have to apply an inverse transformation to the coordinates calculated from imageCopy
Graph.Peak p = peaks.elementAt(i);
Peak p = peaks.elementAt(i);
if (p.getDiff() <= 0) {
continue;
}
Expand Down Expand Up @@ -121,15 +121,15 @@ public void normalize() {

private BufferedImage cutTopBottom(BufferedImage origin, PlateVerticalGraph graph) {
graph.applyProbabilityDistributor(new Graph.ProbabilityDistributor(0f, 0f, 2, 2));
Graph.Peak p = graph.findPeak(3).elementAt(0);
Peak p = graph.findPeak(3).elementAt(0);
return origin.getSubimage(0, p.getLeft(), getImage().getWidth(), p.getDiff());
}

private BufferedImage cutLeftRight(BufferedImage origin, PlateHorizontalGraph graph) {
graph.applyProbabilityDistributor(new Graph.ProbabilityDistributor(0f, 0f, 2, 2));
Vector<Graph.Peak> peaks = graph.findPeak();
Vector<Peak> peaks = graph.findPeak();
if (peaks.size() != 0) {
Graph.Peak p = peaks.elementAt(0);
Peak p = peaks.elementAt(0);
return origin.getSubimage(p.getLeft(), 0, p.getDiff(), getImage().getHeight());
}
return origin;
Expand All @@ -148,7 +148,7 @@ public PlateGraph histogram(BufferedImage bi) {
}

private PlateVerticalGraph histogramYaxis(BufferedImage bi) {
PlateVerticalGraph graph = new PlateVerticalGraph(this);
PlateVerticalGraph graph = new PlateVerticalGraph();
int w = bi.getWidth();
int h = bi.getHeight();
for (int y = 0; y < h; y++) {
Expand Down
62 changes: 11 additions & 51 deletions src/main/java/net/sf/javaanpr/imageanalysis/PlateVerticalGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,40 @@
import net.sf.javaanpr.configurator.Configurator;

import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

public class PlateVerticalGraph extends Graph {

private static final double peakFootConstant =
Configurator.getConfigurator().getDoubleProperty("plateverticalgraph_peakfootconstant"); // 0.42

private Plate handle;

public PlateVerticalGraph(Plate handle) {
this.handle = handle;
}

public Vector<Peak> findPeak(int count) {
// lower the peak
for (int i = 0; i < this.yValues.size(); i++) {
this.yValues.set(i, this.yValues.elementAt(i) - this.getMinValue());
for (int i = 0; i < yValues.size(); i++) {
yValues.set(i, yValues.elementAt(i) - getMinValue());
}
Vector<Peak> outPeaks = new Vector<Peak>();
for (int c = 0; c < count; c++) {
float maxValue = 0.0f;
int maxIndex = 0;
for (int i = 0; i < this.yValues.size(); i++) { // left to right
if (this.allowedInterval(outPeaks, i)) {
if (this.yValues.elementAt(i) >= maxValue) {
maxValue = this.yValues.elementAt(i);
for (int i = 0; i < yValues.size(); i++) { // left to right
if (allowedInterval(outPeaks, i)) {
if (yValues.elementAt(i) >= maxValue) {
maxValue = yValues.elementAt(i);
maxIndex = i;
}
}
}
// we found the biggest peak
if (this.yValues.elementAt(maxIndex) < (0.05 * super.getMaxValue())) {
if (yValues.elementAt(maxIndex) < (0.05 * super.getMaxValue())) {
break; // 0.4
}
int leftIndex = this.indexOfLeftPeakRel(maxIndex, PlateVerticalGraph.peakFootConstant);
int rightIndex = this.indexOfRightPeakRel(maxIndex, PlateVerticalGraph.peakFootConstant);
outPeaks.add(new Peak(Math.max(0, leftIndex), maxIndex, Math.min(this.yValues.size() - 1, rightIndex)));
int leftIndex = indexOfLeftPeakRel(maxIndex, PlateVerticalGraph.peakFootConstant);
int rightIndex = indexOfRightPeakRel(maxIndex, PlateVerticalGraph.peakFootConstant);
outPeaks.add(new Peak(Math.max(0, leftIndex), maxIndex, Math.min(yValues.size() - 1, rightIndex)));
}
Collections.sort(outPeaks, new PeakComparer(this));
Collections.sort(outPeaks, new PeakComparator(yValues));
super.peaks = outPeaks;
return outPeaks;
}

public class PeakComparer implements Comparator<Object> {

private PlateVerticalGraph graphHandle = null;

public PeakComparer(PlateVerticalGraph graph) {
this.graphHandle = graph;
}

private float getPeakValue(Object peak) {
// heuristic: how high (wide on the graph) is the candidate character (prefer higher ones)
// return ((Peak)peak).getDiff();

// heuristic: height of the peak
return this.graphHandle.yValues.elementAt(((Peak) peak).getCenter());

// heuristic: how far from the center is the candidate
// int peakCenter = ( ((Peak)peak).getRight() + ((Peak)peak).getLeft() )/2;
// return Math.abs(peakCenter - this.graphHandle.yValues.size()/2);
}

@Override
public int compare(Object peak1, Object peak2) {
double comparison = this.getPeakValue(peak2) - this.getPeakValue(peak1);
if (comparison < 0) {
return -1;
}
if (comparison > 0) {
return 1;
}
return 0;
}
}
}
Loading