auto crop image (need idea or code)

Hey. I want to auto crop/trim the attached image. An image for every kanji character should be the solution. thanks for the help.

2 件のコメント

Rik
Rik 2017 年 4 月 24 日
Unless every pixel is identical for each character, this will be very difficult. If you are in luck, you can simply look for completely white rows to separate the characters.
Image Analyst
Image Analyst 2017 年 4 月 24 日
It looks like there is kerning involved, so looking for white columns won't solve the problem.

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

 採用された回答

Image Analyst
Image Analyst 2017 年 4 月 24 日

2 投票

23.4.4 Chinese and Kanji Characters
23.4.4.1 Chinese Characters, Review, Survey, Evaluations
23.4.4.2 Chinese Characters, Using Stroke and Radical Analysis, Features
23.4.4.3 Chinese Characters, Japanese Characters, Handwritten
23.4.4.4 Online Recognition of Chinese Characters
23.4.4.5 Chinese Character Seals

6 件のコメント

symmm
symmm 2017 年 4 月 25 日
Thanks for the help, but i need to solve this without using ocr(school project). I think i didn't explain the problem enough. I need to trim the strip (see red line for example).
So is there a possibility to count the white pixels between the kanji characters. Or maybe search for a box with white pixels (see black box in picture) and find out the center of the box for the x, y coordinate.
Image Analyst
Image Analyst 2017 年 4 月 25 日
To find lines, I'd find white areas like Rik says:
verticalProfiles = sum(binaryImage, 2);
Then if depends if you want to crop the letters really tight around the black, or if you want to split them down the middle of the white zone between lines. Which is it?
So now that you've got two characters in a line, now you need to specify the two characters in the line despite the fact that there may be many separate blobs. So what you're going to do is to invert the image, so the letters are white, then label then and call regionprops and ask for centroids. If the x coordinate of the centroid is closer to 1, then the blob belongs on the left side, and if it's closer to the number of columns, then it belongs on the right. Here's a start
% For one two-character sub-image...
[labeledImage, numberOfRegions] = bwlabel(~binaryImage);
[rows, columns] = size(binaryImage);
props = regionprops(labeledImage, 'Centroid');
% Make two images for the left and right characters.
leftChar = false(rows, columns);
rightChar = false(rows, columns);
for k = 1 : numberOfRegions
% Get a binary image of this blob alone.
thisBlob = ismember(labeledImage, k);
x = props(k).Centroid(1);
if x < (columns - x)
% Blob is closer to the left edge of the image.
% Blob belongs to the left character. Add it in.
leftChar(thisBlob) = true;
else
% Blob is closer to the right edge of the image.
% Blob belongs to the right character. Add it in.
rightChar(thisBlob) = true;
end
end
subplot(1, 2, 1);
imshow(leftChar);
subplot(1, 2, 2);
imshow(rightChar);
This should be able to handle kerning (where one character invades the bounding box of another character).
symmm
symmm 2017 年 4 月 25 日
編集済み: symmm 2017 年 4 月 25 日
I am grateful for your help, but unfortunately this is not the solution i am looking for. I am sorry if I was not clear enough. I want to split the kanji horizontally and not vertically. The trim should be in the middle. I hope you can help me once more.
Image Analyst
Image Analyst 2017 年 4 月 25 日
I told you how to do it. Both vertically and horizontally. First chop up vertically into 8 pairs. Then for each pair use the code I just gave you to get the left and right characters. So you have it all - 16 images. If I get time, I'll try to do a complete demo.
Image Analyst
Image Analyst 2017 年 4 月 25 日
編集済み: Image Analyst 2017 年 4 月 26 日
symmm, just try the attached code and you'll see it gets every character in every row.
symmm
symmm 2017 年 4 月 26 日
Thank You!

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

その他の回答 (1 件)

symmm
symmm 2017 年 4 月 25 日

0 投票

Thanks for the help, but i need to solve this without using ocr(school project). I think i didn't explain the problem enough. I need to trim the strip (see red line for example).
So is there a possibility to count the white pixels between the kanji characters. Or maybe search for a box with white pixels (see black box in picture) and find out the center of the box for the x, y coordinate.

1 件のコメント

Rik
Rik 2017 年 4 月 25 日
For that orange line, you can use my idea of looking for white rows. To separate them further is much more complicated.

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

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2017 年 4 月 24 日

コメント済み:

2017 年 4 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by