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 comentarios

Rik
Rik el 24 de Abr. de 2017
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 el 24 de Abr. de 2017
It looks like there is kerning involved, so looking for white columns won't solve the problem.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 24 de Abr. de 2017
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 comentarios

symmm
symmm el 25 de Abr. de 2017
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.
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 el 25 de Abr. de 2017
Editada: symmm el 25 de Abr. de 2017
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 el 25 de Abr. de 2017
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 el 25 de Abr. de 2017
Editada: Image Analyst el 26 de Abr. de 2017
symmm, just try the attached code and you'll see it gets every character in every row.
symmm
symmm el 26 de Abr. de 2017
Thank You!

Iniciar sesión para comentar.

Más respuestas (1)

symmm
symmm el 25 de Abr. de 2017

0 votos

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 comentario

Rik
Rik el 25 de Abr. de 2017
For that orange line, you can use my idea of looking for white rows. To separate them further is much more complicated.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 24 de Abr. de 2017

Comentada:

el 26 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by