问题
I am currently working on a computer-vision program that requires me to determine the "direction" of a color blob in an image. The color blob generally follows an elliptical shape and thus can be used to track direction (with respect to an initially defined/determined orientation) through time.
The means by which I figured I would calculate changes in direction are described as follows:
- Quantize possible directions (360 degrees) into N directions (potentially 8, for 45 degree angle increments).
- Given a stored matrix representing the initial state (t0) of the color blob, also acquire a matrix representing the current state (tn) of the blob.
- Iterate through these N directions and search for the longest stretch of the color value for that given direction. (e.g. if the ellipse is rotated 45 degrees with 0 being vertical, the longest length should be attributed to the 45 degree mark / or 225 degrees).
The concept itself isn't complicated, but I'm having trouble with the following:
- Calculating the longest stretch of a value at any angle in an image. This is simple for angles such as 0, 45, 90, etc. but more difficult for the in-between angles. "Quantizing" the angles is not as easy to me as it sounds.
Please do not worry about potential issue with distinguishing angles such as 0 and 90. Inertia can be used to determine the most likely direction of the color blob (in other words, based upon past orientation states).
My main concern is identifying the "longest stretch" in the matrix.
Thank you for your help!
回答1:
You can use image moments as suggested here: Matlab - Image Momentum Calculation.
In matlab you would use regionprops
with the property 'Orientation', but the wiki article in the previous answer should give you all of the information you need to code it in the language of your choice.
来源:https://stackoverflow.com/questions/11454254/algorithm-for-finding-longest-stretch-of-a-value-at-any-angle-in-a-2d-matrix