Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thinning handwritten characters in MATLAB

I want to thin handwritten characters like shown below:

enter image description here

Code below give my expected result:

BW = imread('s.png');
BWI = imcomplement(BW);
BW2D = im2bw(BWI,0.1);
BWT = bwmorph(BW2D,'thin',Inf),
BWFinal = imcomplement(BWT);
figure, imshow(BWFinal);

Is this the correct approach? Or is there another way to do it in MATLAB?

like image 970
JR Galia Avatar asked Feb 09 '15 06:02

JR Galia


2 Answers

Yes.‏‏‏ ‏‏ ‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏‏

like image 166
rayryeng Avatar answered Sep 28 '22 00:09

rayryeng


The consensus is that your code is ok. However, to give Shai some mileage on his points, I add a minor comment:

The use of imcomplement may not be necessary, see the documentation.

In particular:

Tip If IM is a grayscale or RGB image of class double, you can use the expression 1-IM instead of this function.

If IM is a binary image, you can use the expression ~IM instead of this function.

like image 21
Buck Thorn Avatar answered Sep 28 '22 00:09

Buck Thorn