MATLAB: How to centralize alphabets in an image

digital image processingimage processingImage Processing Toolbox

Hello,
I have an 80×80 image that contains an Arabic alphabet (black pixels) against white background. The alphabet is dislocated from the center of the image. The idea is to centralize the alphabet in the image. As I have many alphabets, the algorithm should do the same for other alphabets.
Demo image is here,
Your help is highly appreciated.
Thanks.

Best Answer

regionprops() of imcomplement() of the image, requesting 'SubarrayIdx', and use those to access the image.
Note: you should also consider regionprops() of imcomplement() of the image, requesting 'Image' . You could use this if you are not interested in analyzing grayscale levels, just on/off
Note: if your image is binary, and your characters can have disconnected parts, then
regionprops(double(~BinaryImage), ...)
This prevents regionprops from considering each disconnected component separately.
Note: I am not familiar with the rules for Arabic, but in a number of other alphabets, the position of a character relative to the base-line can make a difference in the meaning of the character. For example in some languages a dot near the base-line is a period (punctuation) but a raised dot can indicate an accent or a vowel mark. Because of that, it is sometimes important to either not center the object, or else to also retain information about the object position for later testing against the base-line coordinates.