# mmdconcrete
Aggregate and anhydrous phase extraction from a concrete section observed by a SEM image.

## Description

This example shows an image analysis technique to detect anhydrous phase and aggregate from a polished concrete section observed by scanning electron microscope (SEM). The anhydrous phase appears as white grains while the aggregate appears in the image as an homogeneous medium-gray grains. This image was kindly provided by Prof. Gladis Camarini from FEC-UNICAMP.
The steps for this analysis are: i) anhydrous detection by automatic threshold analysis; ii) homogeneous grain detection using watershed technique; iii) aggregate are homogeneous grains that are not from the anhydrous phase. The automatic threshold analysis is done using 1D-signal morphological processing using watershed.

## Demo Script

### Reading

The SEM image of a polished concrete section is read. The anhydrous phase are the white pores, while the aggregate are the medium-gray homogeneous pores.

    >>> f = mmreadgray('csample.jpg')

    >>> mmshow(f)

f |

### Histogram

The histogram has a small peak in the white region related to the anhydrous phase.

    >>> h = mmhistogram(f)

    >>> mmplot([[h]])

[[h]] |

### Automatic threshold from histogram.

The threshold value is extracted using the watershed technique. The aim is to detect the middle valley of the histogram. If the histogram is negated, we need to extract the middle peak of the 1D signal. This is accomplished by find proper markers on the valleys. These markers are extracted by detecting the regional minima of the filtered signal (alternating sequential filtering, closing followed by opening of length 5 pixels). To discard the detection of peaks near the limits of the histogram, an intersection is done using the mmframe function. For illustrative purpose, a plot of all the signals involved is displayed.

    >>> hf = mmasf(mmneg(h),'co',mmseline(5))

    >>> ws = mmwatershed(hf)

    >>> wsf = mmintersec(mmneg(mmframe(ws,20)),ws)

    >>> t = nonzero(wsf)

    >>> print t

    [186]

    >>> mmax = mmstats(h,'max')

    >>> hf_plot = mmneg(hf)

    >>> ws_plot = mmgray(ws, 'uint16', mmax)

    >>> wsf_plot = mmgray(wsf, 'uint16', mmax)

    >>> mmplot([[hf_plot],[ws_plot],[wsf_plot]])

[[hf_plot],[ws_plot],[wsf_plot]] |

### Anhydrous using thresholding and filtering

The threshold value found in the previous step is applied. After, a filter to remove blobs smaller then 20 pixels is applied. For illustrative, the contour of the anhydrous grains are displayed as an overlay on the original image.

    >>> aux = mmthreshad( f, t, 255)

    Warning: Converting input image from int32 to uint8.
    Warning: Converting input image from int32 to uint8.

    >>> anidro = mmareaopen(aux, 20)

    >>> mmshow( f, mmgradm(anidro))

f, mmgradm(anidro) |

### Homogeneous regions

The watershed applied on the gradient using the markers from filtered regional minima of the gradient is a standard watershed based technique. In this case the filter was chosen to be a contrast mmhmin.

    >>> g=mmgradm(f)

    >>> m=mmregmin(mmhmin(g,10))

    >>> ws=mmcwatershed(g,m)

    >>> mmshow(ws)

ws |

### Aggregate detection

The result of the watershed in the previous step is the detection of a large number of regions. The larger ones are the aggregate and the anhydrous. So first the regions are filtered out using an area criterion of 300 pixels. Small holes (area <= 50) are closed. The aggregate is obtained by removing the anhydrous phase.

    >>> aux1=mmareaopen(mmneg(ws),300)

    >>> aux2=mmareaclose(aux1,50)

    >>> aggr=mmsubm(aux2,anidro)

    >>> mmshow(f, mmgradm(aggr))

f, mmgradm(aggr) |

### Measurement and display

Finally each phase is measured and an illustrative display is constructed. The grains contoured by red are the aggregate and those contoured by green, the anhydrous.

    >>> n = product(shape(f))

    >>> anidro_phase = mmstats(anidro,'sum')/n

    >>> print 'anidro=',anidro_phase

    anidro= 0.114593098958

    >>> aggr_phase = mmstats(aggr,'sum')/n;

    >>> print 'aggr=',aggr_phase

    aggr= 0.252001953125

    >>> mmshow( f, mmgradm(aggr), mmgradm(anidro))

f, mmgradm(aggr), mmgradm(anidro) |

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