Possible Duplicate:
How to find tennis courts in aerial imagery

I am trying to detect tennis courts that are present in aerial images ..

I have the following image:

enter image description here

I tried color image segmentation on it but no success it gives a bad result :

enter image description here

What techniques should i apply for the same please suggest i think Hough transform or watershed could be used however watershed causes over segmentation and the results i get are not satisfactory

Tried using adaptive thresholding:

enter image description here

Some more things that i tried Connected components :


enter image description here

  • $\begingroup$ Is this the only photo, or do you have a series of them? Are the courts aligned to X and Y axes of image or may they be rotated? Are the images made from the same altitude (such that size of the courts on the image is similar on each photo) or not? Provide more details :) $\endgroup$
    – Spook
    Commented Apr 10, 2012 at 10:35
  • $\begingroup$ I have many of these images at different angles $\endgroup$
    – vini
    Commented Apr 10, 2012 at 10:39
  • $\begingroup$ This comment can be deleted on the DSP side, but personally, I think this question is awesome. $\endgroup$
    – casperOne
    Commented Apr 10, 2012 at 12:55
  • $\begingroup$ The problem is this question was already asked on DSP and was finding some alternatives that could be adopted rather than using a hough transform or watershed $\endgroup$
    – vini
    Commented Apr 10, 2012 at 13:06
  • 2
    $\begingroup$ Can't you merge questions like this when you close as duplicate? $\endgroup$
    – endolith
    Commented Apr 10, 2012 at 14:57

5 Answers 5


Since you are trying to discover structure in the images it's better to work in grayscale.

This is a very nice case where the court appears to be a nice rectangle, but in general, courts might come in different sizes and orientations. Also, white lines on green background is not a general rule, consider for example Roland Garos.

Having said this, you can try thresholding your image (you might have to use adaptive thresholding for this) to get something like this: enter image description here

You can then go through the image creating chains of pixels that are 4 or 8 connected

Since you are looking for lines, you can get each of the chains and fit a line to it.

At this point, the "interesting pixels" in your image have been transformed to a set of line models and some of them will be intersecting. You can now apply simple rules to discover which sets of lines are intersecting (here is a good example ).

To discover the set of intersecting lines that make up a tennis court you would search for (this is an example) "A set of 9 lines where 4 are intersecting at right angles, two more parallel to the long lines intersecting them at 1/8 of the width of the field, two more parallel to the short sides and lying about 1/5 from the beginning of the court and a third running in the middle of the court and intersecting the two shorter ones"...In other words, you will have to express the tennis court as a set of intersecting lines with relative positioning to each other (so that your expression is free of the absolute dimensions).

For a very good application of the above technique you can have a look at this paper that outlines the recognition of shotcodes in an image.

For the theoretical background and more information about these techniques you can refer to the excellent "Digital Image Processing With Matlab" and specifically, chapters 10-13 which are the most relevant to your problem

I hope this helps.

  • $\begingroup$ This solution would probably work, but it's very ad hoc. Using more generic methodologies such as affine-invariant features and rigid template registration would probably simplify development (since you will be able to rely on existing libraries) and allow you to more easily process other structures in the future if the need arises. $\endgroup$
    – static_rtti
    Commented Apr 10, 2012 at 11:45
  • $\begingroup$ I don't understand how "ad-hoc" comes into this :-) . It is a synthesis of well established image processing methods to deal with the task at hand. affine-invariant-features would still leave you one step behind. That is, you would still have to express the court as a set of relatively positioned features. In this case it is better to look for intersecting lines rather than points (take advantage of given knowledge) rigid-template-registration would require a large number of "templates" (rotated and scaled at finite angles / scales) and would therefore run the danger of missing some targets. $\endgroup$
    – A_A
    Commented Apr 10, 2012 at 12:03
  • $\begingroup$ a rigid transformation includes rotations. What I mean by "ad hoc" in this context is that you include a large number of assumptions directly into your methodology, which makes the final method fragile to changes in requirements (think changes in tennis courts, image acquisition methods, or changes in requirements (detect pools instead of tennis courts)). $\endgroup$
    – static_rtti
    Commented Apr 10, 2012 at 12:06
  • $\begingroup$ I don't think that there is a large number of assumptions in this answer and i do accept that there are points needing further work (e.g. rejecting some 'noisy' pixels). The question specifically refers to "tennis courts". Not pools. BTW, template registration would return every target that looks like the template (for example a small patch that looks like a pool but is actually the top of a van). Intersecting lines / chains would reject this (take a look at the shotcode paper for more details). A.I.F and R.T.R are not "bad" (at all), but i am not sure these would perform well in this case. $\endgroup$
    – A_A
    Commented Apr 10, 2012 at 12:22
  • $\begingroup$ "template registration would return every target that looks like the template " --> Nope since you'd use SIFT or similar for detection, and use local template registration only for rough segmentation. $\endgroup$
    – static_rtti
    Commented Apr 10, 2012 at 12:31

Do you want to detect (find out their existence) them or segment them (find out their precise contours)? Those are two very different problems.

If you only want to do detection, I'd look into using image features such as SIFT. You can try these methods very easily with OpenCV.

Segmentation is a completely different topic. Supposing you have detected the court roughly with SIFT, you could use a simple registration based method to find out more precisely where the court lies (by registering a template tennis court image to your image). Then you could use any local refinement technique to improve your segmentation.

  • $\begingroup$ i would like to segment out the courts .. as well as find a precise location for where they are located $\endgroup$
    – vini
    Commented Apr 10, 2012 at 11:00

I think that I would do this in at least 2 steps.

First, look for sets of lines which match the lines along the length of a tennis court.

Second, within the boundary of those sets of lines, look for lines across the width of the court.

You can assume that all tennis courts have white lines on green backgrounds if you wish, though I'm not sure it's a good assumption.


Actually, I'd suggest 3 steps. First one would be to binarise the image, I don't think I've ever seen a tennis court with dark lines on a light background so you can probably constrain the problem to looking for white lines.

  • $\begingroup$ yes i will try that out what approach should i try for what you are suggesting? $\endgroup$
    – vini
    Commented Apr 10, 2012 at 11:02
  • $\begingroup$ Well, the Hough transform is pretty good for detecting lines in an image. It's potentially computationally expensive, but you can probably constrain its operations in this case, the lines you are looking for are very straight. If that isn't good enough, the other answers contain good suggestions. $\endgroup$
    – High Performance Mark
    Commented Apr 10, 2012 at 11:06

I think the Hough transform is the way to go here, if you can assume that the courts will always have the same type of line markings. First run an edge detector on the image. Then run the Hough transform to detect straight lines. Then see which of the lines are parallel or perpendicular to each other, and see which ones form rectangles of the right aspect ratio. For that you may want to sort the parallel and perpendicular lines by their spatial proximity in the image. Then check for the appropriate lines within the rectangles.

However, you may have problems if the camera is not looking straight down, because then you will not get the right angles.


I would suggest the following

  • Create a template or templates of the Tennis courts. Make these in gray scale. Match these templates one by one to the image above and see which one fits bets. This is not the best approach. Worst approach.

  • Again , create a template or templates. Compute the SURF features of the template and match them against the image above. This is more robust. Is pretty tolerant to skew, rotation, perspective cuts of image. Matching will occur to the court area in the image.

  • Create a bank of Gabor Filters. Match the response of each filter applied to the image above. there WILL be a specific response to where the courts exists in the image. That is your court area.

Work a little more and your will nail it :)

  • $\begingroup$ yes i find gabor filters very interesting would like to try that out $\endgroup$
    – vini
    Commented Apr 10, 2012 at 11:01
  • $\begingroup$ @vini, good luck they might not be good at skew and perspective cuts. But do post your finding and share them with us :) $\endgroup$
    – Wajih
    Commented Apr 10, 2012 at 11:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.