line word and character segmentation matlab code
I=imread('1line.tif'); %% Read Image
figure(1) imshow(I); title('INPUT IMAGE WITH NOISE');
if size(I,3)==3 I=rgb2gray(I); end threshold = graythresh(I); I =~im2bw(I,threshold); I = bwareaopen(I,60); figure(2) imshow(~I); title('INPUT IMAGE WITHOUT NOISE')
Iedge=edge(uint8(I)); figure(3), imshow(Iedge); title('EDGE ONLY')
se=strel('square',1); Iedge2=imdilate(Iedge,se); figure(4), imshow(Iedge2); title('DILATED IMAGE')
seD = strel('diamond',1); BWfinal = imerode(Iedge2,seD); l BWfinal = imerode(BWfinal,seD);
BWoutline = bwperim(BWfinal); Segout = I; Segout(BWoutline) = 255; figure(5), imshow(Segout), title('SEGMENTED IMAGE');
[L, a,]=bwlabel(Segout); propied=regionprops(L,'BoundingBox'); for n=1
ize(propied,1) rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',1); end for n=1:a [r,c] = find(L==n); n1=Segout(min®:max®,min©:max©); figure, subimage(~n1); pause(0.5) imsave(); end
Segmenting the Hindi text into number of lines and words and characters
clc;
clear all;
a=imread('D:/sahoo/sample.jpg');
%figure,imshow(a)
b=rgb2gray(a);
%Igray1=medfilt2(b);
Ibw = im2bw(b,graythresh(b));
[m n] = size(Ibw);
Ibw2=~Ibw;
Iedge = edge(uint8(Ibw));
imshow(Iedge)
se = strel('square',2);
Iedge2 = imdilate(Iedge, se);
imshow(Iedge2);
%Image Filling
Ifill= imfill(Iedge2,'holes');
imshow(Ifill)
Ilabel = bwlabel(Ifill);
%disp(num);
Ibox = regionprops(Ilabel,'BoundingBox');
Ibox(1)
%Ibox = [Iprops.BoundingBox];
%Ibox = reshape(Ibox,[4 15]);
imshow(Ibw2)
hold on;
for cnt = 1:53
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end