MATLAB: segment individual letters from a binary image

I am working on a project for optical character recognition, where I am trying to create a program that recognizes letters from an image. I am following a tutorial located on Mathworks ( Classification of Numbers ). In their example, their training images are already divided. Unfortunately, I was provided with instructional images containing hundreds of letters in a single file.

Here is an example:

I need an efficient way to segment each individual letter in an image, so I will have an array of 26Xn, where 26 is each letter in the alphabet, and n are image data variables containing individual letters. It would be extremely tiring to manually separate letters from each training image or try to segment letters of a certain length, since the separation between letters is not always the same.

Does anyone know about the MATLAB function or an easy way to determine the height and length of each continuous white color object and store all the individual white objects with their black background in the 26Xn array described above (or at least stored in some kind of array, so can I later process it into an array 26xn)?

+4
2

bwlabel, .
, , regionprops, 'Image'.

comment , , Matlab : Matlab- ( ), , "" . , :

[ind map] = imread('http://i.gyazo.com/0ca8d4416a52b8bc3401da0b71a527fd.gif'); %//read indexed image
BW = max( ind2rgb(ind,map), [], 3 ) > .15; %//convert RGB image to binary mask
seg = regionprops( BW.', 'Image' ); %'// transpose input mask
seg = arrayfun( @(x) x.Image.', seg, 'Uni', 0 ); %'// flip back

seg.

, , regionprops , bwlabel.

+2

, regionprops. BoundingBox, . cell . 26 x N, , , , . , . , MATLAB. , GIF, ... . PNG, :

enter image description here

MATLAB:

im = imread('http://i.stack.imgur.com/q7cnA.png');

, . , . . :

se = strel('square', 7);
im_close = imclose(im, se);

regionprops , ( ):

s = regionprops(im_close, 'BoundingBox');

, s, , , , . . BoundingBox 4 , :

[x y w h]

(x,y) - , w h - . 4- , , :

bb = round(reshape([s.BoundingBox], 4, []).');

, , , , . , :

imshow(im);
for idx = 1 : numel(s)
    rectangle('Position', bb(idx,:), 'edgecolor', 'red');
end

, :

enter image description here

- cell. cell, , cell . , , , , . :

chars = cell(1, numel(s));
for idx = 1 : numel(s)
    chars{idx} = im(bb(idx,2):bb(idx,2)+bb(idx,4)-1, bb(idx,1):bb(idx,1)+bb(idx,3)-1);
end

, ch = chars{idx};, idx - 1 , . , , imshow(ch);

, , , . !

+8

All Articles