1

The program should detect circles and colour them in red. The symmetry method was suggested where I assume each pixel is a center of a circle and check the four points r (radius) distance from it. If they are the same, draw a circle. However in the code bellow I get way to many unnecessary circles

static boolean isCenterOfCircle(int row, int col, int r, BufferedImage image) {

            //getPixels gets the color of the current pixel. 
        if(getPixel(row,col,image) == getPixel(row+r,col,image)
             || getPixel(row,col,image) == getPixel(row-r,col,image)
                || getPixel(row,col,image) == getPixel(row,col+r,image)
                    || getPixel(row,col,image) == getPixel(row,col-r,image)){
            return true;
        }else{
        return false;
        }
    }
user1118321
  • 25,567
  • 4
  • 55
  • 86
user2012107
  • 9
  • 1
  • 3

2 Answers2

2

This can be done using the Hough transform for circles.

See algorithm for detecting a circle in an image

Community
  • 1
  • 1
Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121
  • Yes I've read it but we need to do something relatively simple for our assignment and that's complicated. Thanks anyways – user2012107 Jan 27 '13 at 20:26
  • It may look complicated at first, but it is very elegant and will safe a lot of time that you would spend otherwise. See http://www.markschulze.net/java/hough/ for a nice demo – Rob Audenaerde Jan 27 '13 at 20:27
0

You should check more than 4 points to detect the circle. What about 16 or more. Maybe depending on the radius. For bigger radius you should check more points.

Or search the web for circle detecting algorithms. There are other approaches than checking a few pixels.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49