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.
Asked
Active
Viewed 215 times
2
-
1Do 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
2 Answers
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.