Automatically Detect and Recognize Text in Natural ImagesOpen
this ExampleThis example shows how to detect regions containing
text in an image. It is a common task performed on unstructured
scenes, for example when capturing video from a moving vehicle for
the purpose of alerting a driver about a road sign. Segmenting out
the text from a cluttered scene greatly helps with additional tasks
such as optical character recognition O!"#.The automated text
detection algorithm in this example starts with a large number of
text region candidates and progressively removes those less likely
to contain text. To highlight this algorithm$s flexibility, it is
applied to images containing a road sign, a poster and a set of
license plates.Step 1: Load image%oad the image. The text can be
rotated in plane, but significant out of plane rotations may
re&uire additional pre'processing.colorImage =
imread('handicapSign.jpg');fgure; imshow(colorImage);
title('Original image')Step 2: Detect MSER RegionsSince text
characters usually have consistent color, we begin by finding
regions of similar intensities in the image using the (SE" region
detector )*+.% Detect and etract regionsgra!Image =
rg"#gra!(colorImage);mser$egions =
detect%S&$'eatures(gra!Image('$egion)rea$ange'(*+,-
#---.);mser$egions/iels = 0ertcat(cell#mat(mser$egions./iel1ist));%
etract regions% 2isuali3e the %S&$ regions o0erlaid on the
original imagefgure; imshow(colorImage); hold on;plot(mser$egions(
'show/iel1ist'( true('show&llipses'(4alse);title('%S&$
regions');Some of these regions include extra background pixels. ,t
this stage, the letter E and - in .TO/E-. combine into one region.
,lso notice that the space between bricks is included.Step 3: Use
Canny Edge Detector to Further Segment the TetSince written text is
typically placed on clear background, it tends to produce high
response to edge detection. 0urthermore, an intersection of (SE"
regions with the edges is going to produceregions that are even
more likely to belong to text.% 5on0ert %S&$ piel lists to a
"inar! mas6mser%as6 = 4alse(si3e(gra!Image));ind =
su"#ind(si3e(mser%as6)( mser$egions/iels(7(#)(
mser$egions/iels(7(+));mser%as6(ind) = true;% $un the edge
detectoredge%as6 = edge(gra!Image( '5ann!');% 'ind intersection
"etween edges and %S&$ regionsedge)nd%S&$Intersection =
edge%as6 8 mser%as6;fgure; imshowpair(edge%as6(
edge)nd%S&$Intersection( 'montage');title('5ann! edges and
intersection o4 cann! edges with %S&$ regions')1ote that the
original (SE" regions in mser%as6 still contain pixels that are not
part of the text./e can use the edge mask together with edge
gradients to eliminate those regions.2row the edges outward by
using image gradients around edge locations. helper9row&dges
helper function.*:( gDir. = imgradient(gra!Image);% ;ou must
speci4! i4 the tet is light on dar6 "ac6ground or 0ice
0ersagradient9rown&dges%as6 =
helper9row&dges(edge)nd%S&$Intersection( gDir( '1ightiA);%
5ompute normali3ed stro6e width 0ariation and compare to common
0aluei4 std(stro6ewidths)Gmean(stro6ewidths) ?
-.H,a4terStro6eEidthiA) = -; % $emo0e 4rom tet candidatesendend%
2isuali3e the e=ect o4 stro6e width flteringfgure;
imshowpair(region'iltered