# Detection of number of yarns in the fabric image

I am a novice user in image processing and working on a project to determine number of yarns in a fabric image i.e. warps and wefts (Perpendicular and parallel yarns to x-axis).

I am trying to detect the yarns by taking the sum of columns and rows for warps and weft respectively but it doesn't seem working because the image is not very well focused and sharp. Also the method is much sensitive to the alignment of yarns in the fabric.

Please propose a better algorithm if possible for detection of yarns. Also if there is any possibility to make yarns straight for every captured image. I have tried IMROTATE but it creates the black regions in image which disturbs the sum of rows and algorithm gets failed.

Any help in this regard will be of much worth to me. Thanks.

• Use an FFT. Is this homework? Commented Jul 8, 2012 at 23:03
• Yeah, a Fourier transform is probably the correct starting point. It would "pull" the regularity of the image out of the fuzziness. Not sure how to handle partial rotation, though. Maybe you could transform stripes and note their phase, then determine if adjacent stripes were skewing left or right. Commented Jul 9, 2012 at 0:41

A fourier transform will give you the period of any periodic features in the image - eg it will tell you there is structure event 3pixels horizontally and 5 pixels vertically, from this and the pixel scale you can calculate the number of yarns

Some code in Mathematica:

i = ColorNegate@Import@"https://i.sstatic.net/Jlhgw.jpg";
i3 = DeleteSmallComponents[Binarize[i, .4], 10];
lines = ImageLines[i3, .6];
Show[i, Graphics[{Thick, Orange, Line /@ lines}]]
(*y coord mean increments at x=0 *)
b = Mean@Differences@ Sort[(#[[2, 1]] #[[1, 2]] - #[[1, 1]] #[[2, 2]])/(#[[1,1]] - #[[2, 1]]) & /@ lines];
(*mean slope*)
a = Mean[-(-#[[1, 2]] + #[[2, 2]])/(#[[1, 1]] - #[[2, 1]]) & /@ lines];