How to centralize alphabets in an image?

2 ビュー (過去 30 日間)
Ihtisham Khan
Ihtisham Khan 2018 年 4 月 15 日
コメント済み: Walter Roberson 2018 年 4 月 15 日
Hello,
I have an 80x80 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.

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 15 日
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.
  1 件のコメント
Ihtisham Khan
Ihtisham Khan 2018 年 4 月 15 日
Thanks a lot Walter Roberson , your answer cleared my concept.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 4 月 15 日
I'd threshold and use regionprops() to find the centroid of the character.
binaryImage = grayImage < 128;
binaryImage = bwareafilt(binaryImage, 1);
props = regionprops(binaryImage, 'Centroid');
xCentroid = props.Centroid(1);
yCentroid = props.Centroid(2);
Then I'd use circshift() or imtranslate() to move the character centroid to the middle of the image.
[rows, columns] = size(binaryImage);
middleRow = rows/2;
middleColumn = columns/2;
etc.
  2 件のコメント
Ihtisham Khan
Ihtisham Khan 2018 年 4 月 15 日
Thats OK, but for alphabets with disconnected parts regionprops calculates more than one center. How to fix that.
Walter Roberson
Walter Roberson 2018 年 4 月 15 日
props = regionprops(double(binaryImage), 'Centroid');

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by