# mmdfabric
Detection of vertical weave in fabrics.

## Description

In this example, an enlarged image of a fabric (with backlight illumination) is processed. The purpose is getting a quantitative index of the fabric quality. For that, fabric spaces are detected and measured.

## Demo Script

### Reading

The image to be processed is read.

    >>> a = mmreadgray('fabric.tif');

    >>> mmshow(a);

a |

### Enhancement of the white vertical stripes

A sequence of dilations (by a disk and two line segments) is applied to enhance the white stripes

    >>> b = mmdil(a,mmsedisk(4));

    >>> c = mmdil(b,mmseline(25,90));

    >>> d = mmdil(c,mmseline(25,-90));

    >>> mmshow(d);

d |

### The markers are the dark regions

The markers are the regional minima with contrast 25.

    >>> e = mmhmin(d,25);

    >>> f = mmregmin(e);

    >>> mmshow(f);

f |

### Watershed lines detect the white stripes center

Watershed of the original image from the dark stripes markers just created. Show the result overlayed on the original image.

    >>> g = mmcwatershed(a,f);

    >>> mmshow(a,mmdil(g));

a,mmdil(g) |

### Watershed lines detect the white stripes region

Create a new marker by taking the union of the dark markers and the watershed lines just created. The gradient of the original image is computed.

    >>> h = mmunion(g,f);

    >>> i = mmgradm(a);

    >>> mmshow(h);

    >>> mmshow(i);

h | i |

### Final watershed lines

The watershed of the gradient of the original image, taking the marker just created, gives the extend of the white regions.

    >>> j = mmcwatershed(i,h,mmsebox());

    >>> mmshow(a,j);

a,j |

### Final watershed regions and area measurement

The watershed regions area computed. The area of each watershed regions is measured and displayed.

    >>> k = mmcwatershed(i,h,mmsebox(),'REGIONS');

    >>> mmlblshow(k,'border');

    >>> l = mmblob(k,'area');

    >>> mmshow(l);

k,'border' | l |

### Select only the narrow region (small area)

To select only the fabric spacing, select the regions with small area (less than 2000). Label the narrow regions.

    >>> m = mmcmp(l,'<=',2000);

    >>> mmshow(m);

    >>> n = mmlabel(m,mmsebox());

    >>> mmlblshow(n,'border');

m | n,'border' |

### Area measurement and ploting

Compute the area of each region and plot them. Also display the original image for illustration. From the plot, we can notice that the two rightmost weave spacing are significantly larger than the others.

    >>> mmshow(a);

    >>> o = mmblob(n,'area','data');

    >>> mmplot([[o]],[['style','impulses']])

a | [[o]],[['style','impulses']] |

[`mmdcornea`] [Up] [`mmdfila`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.