Toolbox ia870 | List of Figures | Fig. 7.4 | Fig. 7.8

Figure 7.6 - Watershed as a flooding process


Returning to the beef segmentation illustration of Fig. 7.2 , to use the watershed from markers we can place an inner marker in the center of the image, as we are sure the lean part of the beef is there, and we can place an outer marker near the edge of the whole beef. We repeat the same flooding process of the watershed from markers illustrated previously for the signal, but now in two dimensions using the beef example in Fig. 7.6: (a) the gradient image; (b) the gradient surface punched by different colors at the inner and outer markers; (c) initial flooding; (d) dam building to prevent the merging of different colors; (e) progressive flooding of many primitive catchment basins; and (f) the whole surface flooded and the final watershed line separating the catchment basins originating from the inner and outer markers.

Demo Script

 1 import ia870 as MT
 2 import numpy as np
 4 cross = MT.iasecross()
 6 a = np.transpose(adreadgray('beef.tif'))
 7 c = MT.iathreshad(a,uint8(10))
 8 d = MT.iaareaclose(c,200)
 9 e = MT.iagradm(d,cross,MT.iasebox(9))
10 f = MT.iaero(d,MT.iasecross(95))
11 g = MT.iaunion(e,f)
12 h = MT.iagradm(MT.iaclose(a))
13 ws = uint8(MT.iacwatershed(h,g,option='REGIONS'))
14 sur_in = MT.iainpos(e,h,cross)
15 sur_ex = MT.iainpos(f,h, cross)
17 ms = MT.iagsurf(MT.iaintersec(MT.iagray(MT.ianeg(g)),h))
19 adshow(MT.iagsurf(h),'(a)')
21 adshow(MT.iagshow(ms,e,f),'(b)')
22 adshow(MT.iagshow(ms,MT.iathreshad(sur_in,0, 5),MT.iathreshad(sur_ex,0, 5)),'(c)')
24 adshow(MT.iagshow(ms,MT.iathreshad(sur_in,0,12),MT.iathreshad(sur_ex,0,12)), '(d)')
25 adshow(MT.iagshow(ms,MT.iathreshad(sur_in,0,18),MT.iathreshad(sur_ex,0,16)),'(e)')
26 adshow(MT.iagshow(ws,MT.iathreshad(ws,1,1),MT.iathreshad(ws,2,2)),'(f)')