Image Segmentation and Morphological Processing Digital Image Processing in Life- Science Aviad Baram 4-4-2012 Processing vs Analysis Image processing: Enhance Smooth contrast Image In Image out Image analysis: “meaning” Region Edges Image In Attributes out Part I - Segmentation Subdivide the image into constituent regions or objects (sets) n ∑ Ri =R Q (Ri )≠ Q (R j ) i=1 Based on properties of intensity values ▪ Discontinuity – changes (e.g. edges) ▪ Similarity – partition into similar regions Basic set operations Exclusive or (R ⊕R cg) r(R Complementary Intersect (R ∩R ) r g rg Union (Rr∪Rg) ) Synonyms in set operations Selection Binary Mathematical ROI Mask Set (Ri) Make Inverse Inverse Complementary (Ric) OR (Combine) OR Union (Ri∪Rj) AND AND Intersect (Ri∩Rj) XOR Exclusive disjunction (Ri⊕Rj) XOR Automatic approaches Why? Human comprehension is far superior Unbiased High throughput – ImageJ macros ■ ■ Discontinuity – Edge based methods ■ Classical gradient detectors (Sobel, Prewitt...) ■ Canny edge detector Similarity - threshold Edge detection Find the boundary of a region by identifying points, lines and edges Tools: ▪ ▪ Second derivatives (Laplacian) operators ▪ Very sensitive to noise ▪ Double line detection (show example) First derivative ▪ Smoother ▪ Less sensitive Derivatives noise First derivative Second derivative Derivatives noise First derivative Second derivative Derivatives noise First derivative Second derivative Laplacian double edge Prewitt and Sobel Derivative Sobel -2 -1 0 -1 0 1 0 1 2 Laplacian of Gaussian - LoG Laplacian LoG Canny edge detector Nonmaxima suppression along gradient Double threshold → use TH edge pixels as seeds to connect TL edges norm angle Edge detection Summary 1st derivative 2nd derivative Source Sobel LoG Canny Similarity - Threshold Partition Image into regions ▪ Global threshold ▪ Adaptive threshold ▪ Smaller image blocks ▪ Threshold for each blocks ▪ Interpolate results for each pixels Global threshold - noise T1 { a g (x,y )= b c iff (x,y )>T 2 ifT1<f (x,y )≤ T 2 iff (x,y )≤ T 1 } c T2 b a Global threshold - background Automatic global threshold Example 1 - mean: Initial estimate for T Segment into G1 and G2 Compute mean for G1 and G2 Repeat until no significant change G1 G2 ⟨G1⟩ ⟨G2⟩ Compute new threshold T= 1 (〈G 1 〉+ 〈G 2 〉 ) 2 Automatic global threshold Example 2 – Otsu: minimize error in pixel assignment to groups mean1 Global mean: mG Global variance: σ2G mean2 Between-class variance: σ2B Calculate for all thresholds and choose the max σ2B 2 “goodness” of TH: η= σB 2 σG smoothing images improves auto segmentation Local thresholding Calculate T from “subimage” histogram (e.g. edges...) ⇒ apply to full image Variable thresholding For each pixel, f(x,y), compute a threshold, Txy, based on mxy and σxy of neighborhood Sxy m - mean Mean T xy =aσ xy +bm xy T xy =aσ xy +bmG { 1 g (x,y )= 0 iff (x,y )>T xy iff (x,y )≤ T xy } σ - variance Part II - Morphology Processing of region shapes Structuring Elements Erosion A⊖B Erosion Remove connecting lines Shrink regions Dilation A⊕ B Dilation Bridge gaps Grow regions Dilate⇔ErodeC Open A◦B nX Erode → n X dilate Smooth contour Break narrow bridges Eliminate protrusions Close A•B nX dilate → n X erode Smooth contour Fuse narrow breaks Eliminate small holes Fills gaps Open⇔CloseC Boundary extraction Subtract the eroded image from original Skeletons Minimal set required for reconstruction ImageJ built in function – erode to single pixel Fill holes Hole – background region surrounded by a foreground connected border Hit or Miss Shape detection C A⊛B=(A⊖B1)∩(A ⊖B2) Probe for object Probe for background Watershed Gray level Segmentation ImageJ built in ImageJ Set Measurement... Gray level morphology Erode Open Dilate Close Examples Yael Mutsafi Ayelet Tetelboim