Skip to content

Commit 3ed0da7

Browse files
committed
Fixed a bug where image data would not be put in the float array.
I did this by not defining the size of the array beforehand, instead I let getPixels do it.
1 parent 360fd7f commit 3ed0da7

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

Diff for: HoughTransformer.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717

1818
public class HoughTransformer{
1919

20+
int centerTolerance, houghTolerance;
21+
22+
/**
23+
* The first constructor for HoughTransformer which
24+
* will set the tolerance for the center of the circle.
25+
*
26+
* @param centerTolerance The tolerance in pixels for center of the circle.
27+
* @param houghTolerance Tolerance for the hough transform (0.0 - 1.0)
28+
*/
29+
public HoughTransformer(int centerTolerance, double houghTolerance){
30+
this.centerTolerance = centerTolerance;
31+
this.houghTolerance = houghTolerance;
32+
}
33+
2034
/**
2135
* This method will try to find a circle of a
2236
* certain size, and then return true or
@@ -26,9 +40,9 @@ public class HoughTransformer{
2640
* @return boolean Whether or not a circle was found.
2741
*/
2842
public void process(RenderedImage img){
29-
float[] imgData = new float[img.getWidth() * img.getHeight()];
30-
img.getData().getPixels(0,0, img.getWidth(),
31-
img.getHeight(), imgData);
43+
int width = img.getWidth(), height = img.getHeight();
44+
float[] imgData = img.getData().getPixels(0,0, width,
45+
height, (float[])null);
3246

3347
/*Find out more about what threshold does
3448
I'm referring to this site: http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm
@@ -38,9 +52,22 @@ public void process(RenderedImage img){
3852

3953
LocatedCircle circle = hough.getLargestCircle(imgData,
4054
img.getWidth(), img.getHeight());
55+
56+
/**
57+
* Check that the circle we're looking for is near the center.
58+
* If it is not, then the hough transform probably found
59+
* a larger object than the one in question and failed.
60+
*/
61+
int circX = circle.getX(), circY = circle.getY();
62+
if((circX < width-centerTolerance || circX > width-centerTolerance)
63+
|| (circY < height-centerTolerance || circY>height+centerTolerance))
64+
return Category.UNDEFINED;
4165

4266
System.out.println(circle.getRadius());
67+
System.out.println("Location: ("+circle.getX() +"," +circle.getY());
68+
System.out.println("Confidence: " + circle.getConfidence());
4369
}
70+
4471

4572
public static void main(String args[]){
4673
if(args.length < 1)

Diff for: ImageProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void main(String args[]){
2121
processor.add(new MorphologicalCloseProcess());
2222
processor.add(new GrayConvertProcess());
2323
processor.add(new MonoscaleProcess());
24-
processor.add(new SobelDetectionProcess());
24+
// processor.add(new SobelDetectionProcess());
2525

2626
for(int n = 0; n < args.length; n++){
2727
String inputFilename = args[n];

0 commit comments

Comments
 (0)