from Location of Text in Images of Natural Scenes by Ashwin
A Novel Algorithm to detect and localize text in Natural Scene Images

TextLocalization.m
clc;
clear all;

[file path] = uigetfile('*.jpg','Image Files');
img = imread([path file]);
try
    img = rgb2gray(img);
end

img_edge = edge(img,'canny');

%Find the filled image
img_filled = imfill(img_edge,'holes');

imshow(img_filled);

%Now find the region with the maximum area
props = regionprops(img_filled,'Area','PixelList');

max_area = props(1).Area;
max_count = 1;
for count=1:size(props,1)
    if(max_area < props(count).Area)
        max_area = props(count).Area;
        max_count = count;
    end
end

if(max_area > 2000)
    
    out_img = zeros([size(img_edge,1) size(img_edge,2)]);

    pixels = props(max_count).PixelList;

    for count=1:size(pixels,1)
        out_img(pixels(count,2),pixels(count,1)) = 1;
    end
else
    out_img = img_edge;
end

%Now show the confidence region to the user
conf_region = uint8(double(img) .* double(out_img));

%Apply some edge filtering on the image
text_region = edge(conf_region);

%Now get the text from this area
out_img = double(img) .* text_region;

subplot(2,2,1);
imshow(img);
title('Original Image');
subplot(2,2,2);
imshow(img_edge);
title('Edge Image');
subplot(2,2,3);
imshow(conf_region);
title('Text Confidence Region Image');
subplot(2,2,4);
imshow(uint8(out_img));
title('Text Region Image');

Contact us