MATLAB: Images and rotation angles

image analysisImage Processing Toolboxrotate

Hola,
I have a theoretical question as I'm looking for ideas how to solve my current image analysis problem (a field which I am not an expert).
The problem is: I have 40 images of different types of drinking bottles in various rotation angles. Therefore, I am looking for a way how to automate the rotation process so all of them will have the same angle (neck up, base down), any idea how to solve it?
Thank you.

Best Answer

Basically you first need to find the bottle, by thresholding or whatever. Then you need to run regionprops and look for the orientation - that will tell you the angle - and the Centroid and MajorAxisLength. It will fit an ellipse to the bottle. Look at the location of the midpoint of the MajorAxis. It will be closer to one end (thick or thin - I'm not sure) of the bottle than the Centroid will be. So, knowing that you'll be able to rotate it so the thick end is down.
Please upload some of your images, including the binary images showing the detected bottle mask.