在 MATLAB 中细化手写字符

Thinning handwritten characters in MATLAB

我想将手写字符细化如下所示:

下面的代码给出了我的预期结果:

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

这是正确的做法吗?或者在 MATLAB 中有其他方法吗?

是的。

大家一致认为你的代码没问题。然而,为了让 Shai 对他的观点有所了解,我添加了一个小评论:

可能没有必要使用imcomplement,请参阅documentation

特别是:

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.