How to detect the resemblance in signals to the shape of the signal?

1 次查看(过去 30 天)
I'm making a simple OCR detector in MATLAB. For now, only for uppercase letters (A-Z).
I have got the algorithms done to segment lines and individual characters. Now, I need to compare each extracted character against a database of all the alphabet letters.
For that, I have used the projections of the binarized (black-and-white) character on the x-axis and y-axis.
To compare the two projections with the projections in the database I have used the cross-correlation (with the mean substracted, to remove the DC).
This works perfectly when the characters are exactly the same as those in the database, but when I extract the characters from another image, the characters will be rescaled, compressed... but the patterns remain, my algorithm is not useful, and worked only for 40-50% of the characters of the image.
I put an example:
This are the projections of the character C of the database (on the top) and of the character D of the image (on the bottom).
And this are the projections of the character D of the database (on the top) and of the character D of the image (on the bottom).
Ok, then, my code says that the projections of C are more resamblance than those of D. With numbers, the correlation of C is 0.9 for horizontal and 0.7 for vertical. And the correlation of D is 0.78 for horizontal and 0.67 for vertical.
I am going to attach my code, the final question is: What is the best algorithm (not too advanced) that could work well?
My code:
proj_horizontal_database = caracter_alfabeto(2, :) - mean(caracter_alfabeto(2, :));
proj_vertical_database = caracter_alfabeto(1, :) - mean(caracter_alfabeto(1, :));
proj_horizontal_letter = sum(caracteresLeidos{i}{j}, 1) - mean(sum(caracteresLeidos{i}{j}, 1));
proj_vertical_letter = sum(caracteresLeidos{i}{j}, 2)' - mean(sum(caracteresLeidos{i}{j}, 2)');
correlation = xcorr(proj_horizontal_database, proj_horizontal_letter, 'coeff');
correlation_horizontal = max(correlacion);
correlation = xcorr(proj_vertical_database, proj_vertical_letter, 'coeff');
correlation_vertical = max(correlacion);
% and then, I select the characters with higher correlation, I don't put
% the code because it has no importance.

采纳的回答

Jacob Mathew
Jacob Mathew 2025-5-6
Hey Javier,
Looking at the attached graph, it seems like while the general shape of the projections match between the database projection of D and the image projection of D, the axis scaling is wildly different. The axes are much more comparable when you look at the database projection of C against the image projection of D. This could be the root cause on the misidentification.
Consider normalising the projections either to have the same range or the same area under the curve in tandem with normalised cross correlation to try and recitfy this. You can refer to the corr function below for more information:
Further, you can also resize the characters themselves to a standardized size. For example, each character's bounding box snippet can be resized to a 32x32 bit image which ensures that the projection's axis will be consistent across letters. This can be achieved using functions like imresize. You can refer to the following documentation to learn more about it:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parametric Spectral Estimation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by