7
votes

I have a Canny edge detected image of a ball (see link below) which contains a lot of noisy edges. What are the best image processing techniques that I can use to remove these noisy edges without removing the edges belonging to the ball?

Original image

original

Canny edge image

canny

Many thanks everyone in advance for your help and advice, much appreciated!

Ps I am trying to clean up the edge image prior to using the Circle Hough Transform to detect the ball.

3
It would be useful to see the original image. Canny has three parameters as inputs, one of which is the size of the Gaussian blur filter used for pre-processing and the other two are thresholds that control the level of detail returned. I suspect you can improve the result with more suitable choices but would need the original image to be sure.Roger Rowland
I'm auto-calculating Canny parameters as follows: double high_thres = cv::threshold( orig_img, thres_img, 0, 255, CV_THRESH_BINARY+CV_THRESH_OTSU ); lower thres = 0.1 * high_thres cv::Canny(orig_img, cannyOP, lower_thres, high_thres); If I go any lower than the 0.1 multiple for the 'lower_thres' I get too much noise, if I go higher, I lose the edges that belong to the ball. This is taken from: stackoverflow.com/questions/4292249/…Adam
Ok, then can you provide a link to the original image (I'll add it to your question)?Roger Rowland
I will do no problem, but it will be later in the evening when I'm home :) Thanks.Adam
Hi Roger, a little off topic, are there any other ways of detecting/tracking a ball (which may be occluded), that you know of, other than the Circle Hough Transform?Adam

3 Answers

7
votes

The best option is to filter the image before applying the edge detector. In order to keep the sharp edges you need to use a more sophisticated filter than the Gaussian blur.

Two easy options are the Bilateral filter or the Guided filter. These two filters are very easy to implement and they provide good results in most cases: gaussian noise removal preserving edges. If you need something more powerful, you can try the filter BM3D, which is one of the state-of-the-art filters, and you can find an open source implementation here.

7
votes

Canny edge detection works best only after you set optimal threshold levels (lower and upper thresholds)

How do you set them?

  • First, calculate the median of the gray scale image.
  • Choose the optimal threshold values using the median of the image.

The following pseudo-code shows you how its done:

v = np.median(gray_img)
sigma = 0.33

#---- apply optimal Canny edge detection using the computed median----
lower_thresh = int(max(0, (1.0 - sigma) * v))
upper_thresh = int(min(255, (1.0 + sigma) * v))

Set lower_thresh and upper_thresh as the parameters for the canny edge function.

sigma is set to 0.33 because in statistics along a distribution curve, values lying between 33% from the start and end of the curve are considered. Values lying beyond and below this curve as considered to be outliers.

This is what I got for your image:

enter image description here

2
votes

The best way to remove those is probably not to have them in the first place if you can. If the lines are noisy artifacts in the image apply a smoothing filter such as a Gaussian to level the image out. -> Gaussian filter info

Removing them once they are there is tricky and would probably involve some higher level shape recognition stuff