Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed analysis warning about if statements in PlateHorizontalGraph. #38

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
4 changes: 2 additions & 2 deletions src/main/java/net/sf/javaanpr/imageanalysis/Plate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Graph.Peak> peaks = graph.findPeak(3);
Vector<Graph.Peak> peaks = graph.findPeak();
if (peaks.size() != 0) {
Graph.Peak p = peaks.elementAt(0);
return origin.getSubimage(p.getLeft(), 0, p.getDiff(), getImage().getHeight());
Expand Down Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,46 @@ 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<Peak> findPeak(int count) {
public Vector<Peak> findPeak() {
if (PlateHorizontalGraph.horizontalDetectionType == 1) {
return this.findPeak_edgedetection(count);
return findPeakEdgedetection();
}
return this.findPeak_derivative(count);
return findPeakDerivative();
}

public Vector<Peak> 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<Peak> 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++;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: Would you formatting the name of this and the other findPeak method to camelCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

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<Peak> outPeaks = new Vector<Peak>();
outPeaks.add(new Peak(a, b));
super.peaks = outPeaks;
return outPeaks;
}

public Vector<Peak> findPeak_edgedetection(int count) {
float average = this.getAverageValue();
int a, b;
for (a = 0; this.yValues.elementAt(a) < average; a++) {
// intentionally empty
public Vector<Peak> 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<Peak> outPeaks = new Vector<Peak>();
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;
Expand Down