Take a text line in an image file to create a new image file MATLAB -


i need take each line of text image file , create new separate image each of lines. have way count how many lines in image file.

if has suggestions huge because i'm not images. im not allowed use image processing toolbox.

this code:

function out = countlines( imgfile ) % count number of lines in image file im = imread(imgfile); im = 255 - im; imbw = uint8(0.33*im(:,:,1) + 0.34*im(:,:,2) + 0.33*im(:,:,3)) > 127; imwrite(imbw, 'temp.jpg'); rvec = sum(imbw'); rvec1 = [0 rvec 0]; svec = [rvec 0 0]; out = sum(rvec1 == 0 & svec ~= 0);  

i tried method on test image found on internet , seemed work alright provided text straight. entries in rvec vector neighbouring entries both smaller them. local maximum entries (first image). after group clusters of lines decide split image (second image).

enter image description here enter image description here

clear; clc;   im = imread('text.png');        % load image [nrows,ncols,~] = size(im);     % size imgray = rgb2gray(im);          % convert grayscale  vec = mean(imgray,2);           % average intensities of each row localmax=[];                    % list of local maximum entries  = 2:nrows-1               % accept local max rows not have text     hastext = sum( imgray(i,:)<100 )>0;     if vec(i)>vec(i-1) && vec(i)>vec(i+1) && ~hastext         localmax = [localmax;i];     end end   nummax = length(localmax);                                       % distances between local max rows distances = localmax(2:end) - localmax(1:end-1); thresh = mean(distances);       % average distance our threshold  splitrows = [];                 % rows split image cluster = localmax(1);          % start cluster first local max row   = 1:nummax-1;                  if distances(i) < thresh    % if rows close together, keep them in cluster         cluster = [cluster;localmax(i+1)];     else                        % average cluster row split image         newsplit = round(mean(cluster));          splitrows = [ splitrows ; newsplit ];         cluster = localmax(i+1);     end end newsplit = round(mean(cluster)); % add last cluster splitrows = [ splitrows ; newsplit ]; 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -