After filtering the image in its Fourier Space, I binarized the image and did some closing morphological operation using a 2x2 square image as the structuring element. Finally, I labelled the image and used the hotcolormap function in scilab to separate the labelled parts of the image.
Figure 2. Result
I will give myself a grade of 9 because some of the horizontal lines were not removed.
Appendix:
Source Code in Scilab:
a= imread("G:\AP 186\Activity 10\image.jpg");
b = im2gray(a);
g = imread("G:\AP 186\Activity 10\filter3.bmp");
h = im2gray(g);
filter1 = fftshift(h);
c= (fft2(b));
scf(1);imshow(b,[]);
d = (fft2(filter1.*c));
I = abs(fft2(fft2(d)));
scf(2);imshow(I,[]);
w = I/max(I);
q = floor(255*w);
mat = size(q);
newpict = q;
for i = 1:mat(1) // Number of rows
for j = 1:mat(2) // Number of columns
if newpict(i,j) <>
newpict(i,j) = 0;
else
newpict(i,j) = 1;
end
end
end
SE_sq = [];
for i = 1:2
for j =1:2
SE_sq(i,j) = 1;
end
end
//
//SE_cross(1:3,1:3)=0;
//SE_cross(2,1:3) = 1;
//SE_cross(1:3,2) = 1;
//////////////////////////
p = abs(newpict-1);
Image_close1 = erode(dilate(p,SE_sq),SE_sq);//Closing
//Image_open1 = dilate(erode(Image_close1,SE_cross),SE_cross);//Opening
Invert = abs(Image_close1 - 1);
scf(3);imshow(Invert,[]);
o = bwlabel(Image_close1);
scf(4); imshow(o,[]);xset("colormap",hotcolormap(255));
scf(5); imshow(Invert,[]);
1 comment:
Hi Jorge,
A 2x2 square structuring element may not be the best for this application. Since the letters are mostly vertical lines a 3x1 element may be used. Or if the handwriting is tilted, you can use a tilted element as well.
Post a Comment