How to extract letters and increase background size without changing character size

3 vues (au cours des 30 derniers jours)
I've got somewhat of a working OCR, it works for reading numbers, Uppercase and some lower case letters. I'm having trouble with lower case letters mostly because my character segmentation makes characters with similar strokes like the letter C/c and O/o read the as a capital letter.
The segmentation uses bounding boxes and afterwards gets patched with zeros on the left and right side to make it a square then gets resized to 28by28 pixels by a seperate for loop (for it to become usable with the EMNIST dataset I'm using). But it downscales the entire character and makes it look like the upper case version.
Basically I just want to make segment a character then make it 28x28 without changing the actual size of the character. I have a feeling it has something to do with how I segment the characters.
Should look lower case instead of upscaled one on the right
Here's the code I have right now followed by the rough function I made for the segmentation and the one I use to make it squared
% Part of the code I want to replace, it basically resizes lower case to look like upper case letters
item1resized = []; item2resized = [];
App.item1vec = []; App.item2vec = [];
% Resize everything to 28x28
for s1 = 1 : length(storeitem1)
[storeitemt1] = squarit(storeitem1{s1});
resized1 = imresize(storeitemt1,[28 28]);
item1resized{s1} = resized1;
% Function to segment the characters.
function [store,cent] = Segment(appim)
binim = imbinarize(appim);
box = regionprops(binim,'BoundingBox');
bd = [box];
coor = [];
store = {};
for k = 1 : length(box)
BB = box(k).BoundingBox;
coor{k} = BB;
st = imcrop(appim,[BB(1),BB(2),BB(3),BB(4)]);
sz = size(st);
if (sz(1) < 250) && (sz(2) < 250) && sz(1) > 4 && sz(2) > 4
store{k} = st;
% Function to patch up sides to make it a square. Pretty much a bruteforce way of making it compatible with EMNIST
function [storeitemt] = squarit(st)
[m,n] = size(st);
if m > n
x = m-n;
storeitemt = [zeros(m,floor(x/2)) st zeros(m,floor(x/2))];
elseif m < n
storeitemt = [zeros(floor(n/3),n); st; zeros(floor(n/3),n)];
elseif m==n
storeitemt = st;

Réponses (0)


En savoir plus sur Characters and Strings dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by