Demo iadfabric

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.

Script

Reading

The image to be processed is read.

1. import ia870 as MT
2. import ia636 as ia
3. 
4. a = adreadgray('fabric.tif')
5. adshow(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

1. b = MT.iadil( a, MT.iasedisk(4))
2. c = MT.iadil( b, MT.iaseline(25,90))
3. d = MT.iadil( c, MT.iaseline(25,-90))
4. adshow(d)

The markers are the dark regions

The markers are the regional minima with contrast 25.

1. e = MT.iahmin(d,25)
2. f = MT.iaregmin(e)
3. adshow(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.

1. g = MT.iacwatershed(a,f)
2. adshow(MT.iagshow(a,MT.iadil(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.

1. h = MT.iaunion(g,f)
2. i = MT.iagradm(a)
3. adshow(h)
4. adshow(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.

1. j = MT.iacwatershed(i,h,MT.iasebox())
2. adshow(MT.iagshow(a,j))

Final watershed regions and area measurement

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

1. k = MT.iacwatershed(i,h,MT.iasebox(),'REGIONS')
2. adshow(MT.iaglblshow(k,'border'))
3. l = MT.iablob(k,'area')
4. adshow(ia.ianormalize(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.

1. m = (l <= 2000)
2. adshow(m)
3. n = MT.ialabel(m,MT.iasebox())
4. adshow(MT.iaglblshow(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.

1. adshow(a)
2. o = MT.iablob(n,'area','data')
3. adshow(ia.iaplot(o))