2

Using python, which may be the best algorithm or the best strategy to detect the presence of colored bands as in image? The image is scanned and cropped, the problem is that the crop not to be precise and I can not make use of a control that makes use of Cartesian coordinates to determine if the lines are present. The strips may be present or not.

Image

Dr. belisarius
  • 59,792
  • 15
  • 113
  • 189
originof
  • 796
  • 1
  • 7
  • 24
  • 1
    Do you expect the bands to always appear like the example (same width, same spacing)? – Mark Elliot Feb 21 '11 at 13:29
  • It would be very helpful if you could describe in more detail the problem you're trying to solve. In particular, what variety of images are you expecting your program to be able to handle? – DSimon Feb 21 '11 at 14:11
  • Allow me to welcome you to StackOverflow and remind three things we usually do here: 1) As you receive help, try to give it too **answering questions** in your area of expertise 2) [`Read the FAQs`](http://tinyurl.com/2vycnvr) 3) When you see good Q&A, vote them up[`using the gray triangles`](http://i.imgur.com/kygEP.png), as the credibility of the system is based on the reputation that users gain by sharing their knowledge. Also remember to accept the answer that better solves your problem, if any, [`by pressing the checkmark sign`](http://i.imgur.com/uqJeW.png) – Dr. belisarius Feb 21 '11 at 18:05

2 Answers2

2

You have a number of options at your disposal:

  • If the strips are going to be the same size, and their orientation is known, then you can use cross-correlation (with working Python source). Your template image could be a single stripe, or a multiple strip pattern if you know the number of strips and their spacing.
  • More generally, you could go with morphological image processing and look for rectangles. You'd first have to threshold your image (using Ohtsu's method or some empirically determined threshold) and then perform contour detection. Here's an example that does something similar, but for ellipses -- it's trivial to modify it to look for rectangles. This time the source in in C, but it uses OpenCV like the first example, so it should be trivial to port
  • There are other approaches such as edge detection and Fourier analysis, but I really think that the first two are going to be more than enough for you.
Community
  • 1
  • 1
mpenkov
  • 21,043
  • 8
  • 81
  • 123
1

enter image description here

Dr. belisarius
  • 59,792
  • 15
  • 113
  • 189