THE WATERSHED SEGMENTATION NADINE GARAISY 1 GENERAL DEFINITION A drainage basin or watershed is an extent or an area of land where surface water from rain melting snow or ice converges to a single point at a lower elevation, usually the exit of the basin, where the waters join another waterbody, such as a river, lake, wetland, sea, or ocean 2 INTRODUCTION οΆThe Watershed transformation is a powerful tool for image segmentation, it uses the regionbased approach and searches for pixel and region similarities. οΆThe watershed concept was first applied by Beucher and Lantuejoul at 1979, they used it to segment images of bubbles and SEM metallographic pictures 3 IMAGE REPRESENTATION οΆWe will represent a gray-tone image by a function: π: β€2 → β€ π(π₯) is the gray value of the image at point π₯ οΆ A section of π at level π is a set ππ (π) defined as: ππ π = π₯ ∈ β€2 : π π₯ ≥ π And in the same way we define ππ (π) as: ππ π = π₯ ∈ β€2 : π π₯ ≤ π βΊ ππ π =π π π+1 π 4 REMINDER-IMAGE GRADIENT An image gradient is a directional change in the intensity or color in an image. Image gradients may be used to extract information from images. 5 IMAGE GRADIENT an intensity image a gradient image in the x a gradient image in the y direction measuring direction measuring vertical horizontal change in intensity change in intensity 6 IMAGE GRADIENT οΆThe morphological gradient of a picture is defined as π π = πβ¨π΅ − π β π΅ Where πβ¨π΅ is the dilation of π and π β π΅ is its erosion. But because π is continuously differentiable, π π₯ is nothing more than the modulus of the gradient of π: π π = ππππ π π₯ = ππ ππ₯ 2 ππ + ππ¦ 2 1/2 7 GEODESIC DISTANCE οΆFor two points π₯, π¦ ππ when π ⊂ β€2 we define the geodesic distance ππ (π₯, π¦) as the length of the shortest path (if any) included in π and linking π₯ and π¦. οΆLet π be any set included in π, then: π π π = {π₯ ∈ π: ∃π¦ ∈ π, ππ π₯, π¦ πππππ‘π} is the set of all points of π that are at a finite geodesic distance from π. 8 GEODESIC ZONE OF INFLUENCE οΆThe geodesic zone of influence of ππ (when π is composed of π connected components ππ ) is the set of points in π whose finite distance is closest to ππ (among all π components) ππ§π ππ = {π₯ ∈ π: ππ π₯, ππ finite and ∀ π ≠ π, ππ π₯, ππ < ππ π₯, ππ } 9 GEODESIC SKELETON BY ZONES OF INFLUENCE οΆ The boundaries between the various zones of influence give the geodesic skeleton by Zones of influence of π in π. πΌππ π = ππ§π (ππ ) π ππΎπΌππ π = π/πΌππ (π) 10 MINIMA AND MAXIMA οΆThe set of points in the function π can be seen as topographic surface π, The lighter the gray value of the function at the point π₯ the higher the altitude of the corresponding point on the surface 11 MINIMA AND MAXIMA οΆ An ascending path is a sequence {π 1 , π 2 , . . } On the surface such that: ∀π π π₯π , π π₯π , π π π₯π , π π₯π π ≥ π βΊ π π₯π ≥ π(π₯π ) οΆ A point π belongs to a minimum if there is a no ascending path starting from π . It can be considered as a sink of the topographic surface (see next slide). The set π of all the minima of π is made of various connected components ππ (π) 12 ASCENDING PATH 13 NON-ASCENDING PATH 14 THE WATERSHED TRANSFORMATION If we look at the image π as a topographic surface, imagine that we pierce each ππ (π) of the topographic surface π and then we plunge this surface into a lake, the water entering through the holes floods the surface and if two or more floods coming from different minima attempt to merge, we avoid this event by building a dam on the points of the surface where the floods would merge. At the end of the process only these dams will emerge and this is what define the watershed of the function π 15 THE WATERSHED TRANSFORMATION 16 THE WATERSHED TRANSFORMATION οhttp://cmm.ensmp.fr/~beucher/lpe1.gif 17 BUILDING THE WATERSHED οΆSuppose the flood of the surface has reached the section ππ (π), when it continue and reach ππ+1 π the flooding is performed in the zones of influence πΌπππ+1 π ππ π . οΆThe components of ππ+1 π which are not reached by the flood are the minima at this level and must be added to the flooded area 18 BUILDING THE WATERSHED 19 BUILDING THE WATERSHED οΆIf we define ππ π as the catchment basins of π at level π and ππ (π) as the minima of π at height π + 1 then: ππ+1 π = πΌπππ+1 π ππ π ππ+1 = ππ+1 (π)/π ππ+1 ∪ ππ+1 π π (ππ π ) • The initiation of this iterative algorithm is π−1 π =β • In the end the watershed line is π·πΏ π = π π π π when π = max(π) ο Visual illustration 20 OVER-SEGMENTATION PROBLEM Unfortunately, most times the real watershed transform of the gradient present many catchment basins, Each one corresponds to a minimum of the gradient that is produced by small variations, mainly due to noise. 21 OVER-SEGMENTATION: SOLUTION The over-segmentation could be reduced by appropriate filtering, but the best results is obtained by marking the patterns to be segmented before preforming the watershed transformation of the gradient. 22 OVER-SEGMENTATION: SOLUTION FIRST: we mark each blob of protein of the original image (by extracting the minima of the image function) 23 OVER-SEGMENTATION: SOLUTION SECOND: by applying the watershed on the initial image we can mark the background with connected marker surrounding the blobs οΆ We define these two steps as marker set π 24 HOMOTOPY MODIFICATION The first two steps of this algorithm can be done by modifying the gradient function to a new wery similar function π′ , the difference between the two is that in π′ the initial minima are replaced by the set π, this modification is called homotopy modification 25 OVER-SEGMENTATION: SOLUTION Now we look at the final result of the marking as a topographic surface, but in the flooding process instead of piercing the minima, we only make holes through the components of the marker set that we produced The initial image marked with the set π 26 OVER-SEGMENTATION: SOLUTION This way the flooding will produce as many catchment basins as there are markers in π, this way the watershed lines of the contours of the objects will be on the crest lines of this topographic surface 27 OVER-SEGMENTATION: SOLUTION οΆThe algorithm for this solution is as follows: ππ (π) – section at level π of the new catchment basins of π Then: ππ+1 (π) = πΌπππ+1 ∪π (ππ π ) Initialization: π−1 π = π 28 OVERLAPING GRAINS οΆ In some cases we have an image with overlapping figures, that we need to segment, in order to do that we need to point out the overlapping regions. οΆ For example the figure here is a TEM (transmission electron microscopy) image of grains of silver nitrate scattered on a photographic plate. 29 OVERLAPING GRAINS To point out the overlapping regions we first threshold the initial image to a binary image with only two gray values 30 REMINDER: DISTANCE FUNCTION the distance function of an image assigns for each pixel a number that is the Euclidean distance between that pixel and the nearest nonzero pixel. For example: suppose we have this image matrix0 0 0 0 1 0 0 0 1 Then the distance matrix will be1.4142 1 1.4142 1 0 1 1.4142 1 0 31 OVERLAPING GRAINS By calculation the maxima of the distance function of the binary image we can provide the markers of the grains 32 OVERLAPING GRAINS The markers of the overlapping regions are obtained by executing the watershed transformation of the inverted distance function −π π₯ , it will produce divide lines which will cut the overlapping grains, that way we can mark them. 33 OVERLAPING GRAINS Finally after marking the background and calculation the gradient function we run the homotopy modification and the watershed construction are preformed 34 THE SEGMENTATION PARADIGM The segmentation process is divided into two steps: I. Finding the markers and the segmentation. II. Performing a markercontrolled watershed with these two elements 35 WATERSHED TRANSFOTMATION PROCESS Source: A gray scale image Step 1: Use the Gradient Magnitude as the Segmentation Function The gradient is high at the borders of the objects and low (mostly) inside the objects. FROM - WWW.MATHWORKS.COM Step 2: Mark the foreground objects 36 WATERSHED TRANSFOTMATION PROCESS Step 3: computing the opening-byreconstruction of the image Step 4: Following the opening with a closing can remove the dark spots and stem marks. FROM - WWW.MATHWORKS.COM Step 5: Calculate the regional maxima to obtain good foreground markers. 37 WATERSHED TRANSFOTMATION PROCESS Step 6: Superimpose the foreground marker image on the original image, Notice that the foreground markers in some objects go right up to the objects' edge Step 7: cleaning the edges of the marker blobs and then shrinking them a bit FROM - WWW.MATHWORKS.COM Step 8: Compute Background Markers, Starting with thresholding operation 38 WATERSHED TRANSFOTMATION PROCESS Step 9: Compute Background Markers, using the watershed transform of the distance transform and then looking for the watershed ridge lines of the result Step 10: Visualize the Result, one of the techniques is to superimpose the foreground markers, background markers, and segmented object boundaries. FROM - WWW.MATHWORKS.COM 39 WATERSHED TRANSFOTMATION PROCESS – ADVANCE OPTIONS *Another useful visualization technique is to display the label matrix as a color image We can use transparency to superimpose this pseudocolor label matrix on top of the original intensity image. FROM - WWW.MATHWORKS.COM 40 ROAD SEGMENTATION οΆIn this study they use the watershed algorithm among others to extract vehicle position on the road and possible obstacles ahead. οΆThe algorithms have been tested on a small database representing different driving situations. 41 ROAD SEGMENTATION The original road image The morphological gradient image 42 ROAD SEGMENTATION Due to noise and inhomogeneities in the gradient image, the watershed will produce a lot of minima which leads to over-segmentation of the image 43 ROAD SEGMENTATION We can enhance the watershed on the gradient image by modifying the gradient function by defining new markers which will be imposed as the new minima. 44 ROAD SEGMENTATION The difference between watershed on simple gradient and watershed on the gradient after modifying using the regularized gradient 45 ROAD SEGMENTATION Then by selecting the catchment basin located at the front of the vehicle we can extract a coarse marker of the road. After smoothing this marker we define it as π1 46 ROAD SEGMENTATION Then we build an outer marker to mark the region of the image which do not belong to the road This marker is defined by π2 47 ROAD SEGMENTATION Using π1 and π2 we modify the gradient which now contain only two minima and the divide lines are the contours of the road 48 ROAD SEGMENTATION οΆTo obtain the road markers we do a simplification on the image using its gradient, the result is an image made of catchment basins tiles of constant gray values- this image is called the mosaic-image. οΆThe gradient of this image will be null everywhere except on the divide lines where it will be equal to the absolute difference of the gray-tone values of the to catchment basins. 49 ROAD SEGMENTATION Watershed of the mosaic-image points out only the regions surrounded by higher contrast edges, and we can still extract a marker for the road 50 ROAD SEGMENTATION The result – Road borders, corresponding to the watershed of the modified gradient image 51 LANE BY LANE ROAD SEGMENTATION Original image Mosaicimage Watershed of mosaicimage Lanes Final result markers enhancement 52 POTENTIAL OBSTACLES DETECTION The second part of this study was identifying obstacles on the road, but this detection is useless without a good definition of the nature of the obstacles, the problem in this part was distinguishing a dangerous obstacle from a light variation in intensity due, for instance to a shading. Black marker- the edges of the road White marker- obstacles-free zone 53 POTENTIAL OBSTACLES DETECTION Difficulties in this segmentation: οfalse detection due to the shadows, because they are considered as obstacles, this can be solved if given complementary information by telemetry or stereovision 54 VISUAL EXAMPLES ο Illustration of watershed road segmentation: https://www.youtube.com/watch?v=Tibi6a_aeeE ο Road Detection Using Region Growing and Segmentation: https://www.youtube.com/watch?v=ADdkfE_J4a0 55 REFERENCES οΆTHE WATERSHED TRANSFORMATION APPLIED TO IMAGE SEGMENTATION – S.Beucher οΆROAD SEGMENTATION BY WATERSHEDS ALGORITHEMS – S.Beucher, M.Billodeau and X.Yu οΆUSE OF WATERSHEDS IN CONTOUR DETECTION- S.Beucher and C.Lantuejoul οΆMATHWORKS.COM οΆWIKIPEDIA 56 57 TOPOGRAPHIC MAP 58