MATLAB: How to detect orientation of an object

computer visionComputer Vision Toolboxfeature extractionimage processingImage Processing Toolboxsegmentation

Hello!
I've been stuck on this particular task for a while, so I thought I would ask the Computer Vision gurus on here. So far I've tried regionprops (specifically – orientation property of regionprops), which has been fairly poor for in terms of results. I was wondering if anyone has any tips or method for which I could calculate the orientation of a letter in the attached image. I've also attached an example image of what I would like to achieve.
Thank you.
Edit: Attached an input example image
Edit2: Attached imgmat.mat file containing the original image and a binary image.
Edit3: Attached shapeLetters.mat binary and an RGB image containing both letters and shapes for possible advice on clean segmentation of shapes and letters.

Best Answer

First find the letters. Pretty easy. Just threshold and call imclearborder() to get rid of the background, then do a little cleanup with bwareafilt() or bwareaopen().
Then detect which letter is which with Hu's moments http://www.youtube.com/watch?v=Nc06tlZAv_Q or Deep Learning. Or else just get the orientation from regionprops() and look at the angle delta from a correctly oriented letter.