matlab - Having more control over the thinning algorithm? -
i have text documents want thin text varying widths such 2 pixel wide strokes, 4 pixel wide , on.
i know matlab has thinning algorithm in bwmorph , 1 can 1 pixel wide thinning using
thinned = bwmorph(bw_image, 'thin', 'n=inf'); but thins image 1 pixel width. changing value of n not produce desired result. there way ensure thinning n-pixel width?
you thin characters first, artificially expand skeletons performing morphology. expanding, morphological dilation suitable. such, thin characters using standard thinning algorithm, dilate result after using suitable structuring element size. size of structuring element should dictate how thick thinned result is.
to further exemplify point, here's example image found on google:
reading in matlab , converting binary:
im = im2bw(imread('https://lh3.ggpht.com/awaaz-bsaxsyyyhrlube_nkib-q-fdx-wpgg8qi5jqrnvavnp87amewsunr7pdbcizy=w300')); this get:

performing thinning gives us:
thinned = bwmorph(im, 'thin', 'n=inf'); 
if want increase thickness of thinning result thickness n pixels, use basic square structuring element size n x n , use imdilate function, performs morphological dilation on binary images. in general, increase thickness of text have overall thickness of n pixels, choose size of square structuring element n.
here examples of have discussed above.
n = 2
this increase thinning 2 pixels wide:
se = strel('square', 2); expand = imdilate(thinned, se); imshow(expand); the function strel defines different structuring elements, choose square 1 via 'square' flag. dilating thinned image see above, get:

n = 5
simply change structuring element size 5 x 5, , get:
se = strel('square', 5); expand = imdilate(thinned, se); imshow(expand); 
if take of results , zoom text, see width of each stroke indeed either 2 or 5 pixels. however, assumption above code each character sufficiently separated allow variable thickness of each stroke maintained. should characters close together, dilation merge these text characters together... thinning algorithm give bad results before dilation.
Comments
Post a Comment