Image recognition could be done in several ways, depending on the requirement and the scope of recognition. In a recent article I posted at LinkedIn, Understanding Deep-Learning (CNN) with Scilab, we could see there was a parameter for the user to set in GUI in order to get the good result which I named it as “Pre-process Param”. Let’s look into details what it is all about.
Let’s compare the following 2 images:
We will start with an image which is written with marker pen, which gave us a thick and clear handwriting.
S = imread('test2.jpg'); S2 = rgb2gray(S); S3 = ~S2; se = imcreatese('ell',15,15) ; Sbg = imerode(S3,se); S4 = imsubtract(S3,Sbg); S5 = im2bw(S4,imgraythresh(S4)); subplot(231); imshow(S2);title('Grayscale Image'); subplot(232); imshow(S3);title('Inverse Image'); subplot(233); imshow(Sbg);title('Backgroud Image'); subplot(234); imshow(S4);title('Image After BG Subtraction'); subplot(235); imshow(S5);title('Binary Image'); scf(); imshow(S5);title('Binary Image');
Change the image to the test1.jpg, and you shall obtain the result as below:
What we could see is that in the second image, after the image converted to binary, some detected digits are “broken” due to the thin line.
A simple way to improve this is the simple morphological operation – dilation, to make the line thicker.
se2 = imcreatese('ell',5,5) ; S6 = imdilate(S5,se2); scf; imshow(S6);
Here we go! The resulting binary image would give us more accurate results for recognition.