# Figure 7.17 - Multiscale watershed

## Description

An example of the multiscale watershed applied to a real image is shown in Fig. 7.17: (a) input image; (b) the morphological gradient; (c) a mosaic image where the primitive catchment basins of the gradient are displayed with the grayscale proportional to the dynamics of their regional minima; and (d) through (f) showing three levels in the hierarchy, with markers as the regional minima with dynamics above 3, 8, and 15, respectively. Note that the highest dynamic corresponds to the background, the second highest corresponds to the largest circular cell, and the third corresponds to the elongated cell above it. This observation is confirmed by the three most prominent objects shown in part (f).

## Demo Script

``` 1 import numpy as np
2 import ia870 as MT
3 from iamxt.iamax_tree_alpha import MaxTreeAlpha
4 import ia636 as ia
5
7 g = MT.iagradm(f,MT.iasebox(),MT.iasebox());
8 mxt = MaxTreeAlpha(ia.ianeg(g))
9 H = mxt.computeHeight()
10 m1= mxt.getExtinctionValues(H,"height")
11 indexes = np.argsort(m1)[::-1]
12 node_index = mxt.node_index
13 m = m1[node_index] #regmin
14 ws0 = MT.iacwatershed(g, MT.iathreshad(m, 1), MT.iasebox(),'REGIONS');
15 mosaic = MT.iagrain(ws0, m,'max');
16 ws1 = MT.iacwatershed(g, MT.iathreshad(m, 4), MT.iasebox());
17 ws2 = MT.iacwatershed(g, MT.iathreshad(m, 9), MT.iasebox());
18 ws3 = MT.iacwatershed(g, MT.iathreshad(m,16), MT.iasebox());
19
20 fig_a = f
21 fig_b = g
22 fig_c = log(mosaic+1)
23 fig_d = MT.iaintersec(f,MT.iagray(MT.ianeg(ws1)))
24 fig_e = MT.iaintersec(f,MT.iagray(MT.ianeg(ws2)))
25 fig_f = MT.iaintersec(f,MT.iagray(MT.ianeg(ws3)))
26