CSE 554 Lctur 1: Binary Picturs Fall 2016 CSE554 Binary Picturs Sli 1
Gomtric Forms Continuous forms Dfin by mathmatical functions Curvs Surfacs E.g.: parabolas, splins, subivision surfacs 2 y x z Sin[ x] Sin[ y] Discrt forms Disjoint lmnts with connctivity rlations E.g.: polylins, triangl surfacs, pixls an voxls Polylin Triangl surfacs CSE554 Binary Picturs Sli 2 Pixls Voxls
Digital Picturs Ma up of iscrt points associat with colors Imag: 2D array of pixls 2D Imag CSE554 Binary Picturs Sli 3
Digital Picturs Color rprsntations Low High Grayscal: 1 valu rprsnting grays from black (lowst valu) to whit (highst valu) Grayscal 8-bit (0-255), 16-bit, tc. RGB: 3 valus ach rprsnting colors from black (lowst valu) to pur r, grn, or blu (highst valu). Low R Low G Low B High R High G High B 24-bit (0-255 in ach color) XYZ, HSL/HSV, CMYK, tc. RGB B R G CSE554 Binary Picturs Sli 4
Digital Picturs Ma up of iscrt points associat with colors Volum: 3D array of voxls Voxl 3D Volum CSE554 Binary Picturs Sli 5
Binary Picturs A grayscal pictur with 2 colors: black (0) an whit (1) Th st of 1 or 0 pixls (voxls) is call objct or backgroun A blocky gomtry Backgroun Objct Analogy: Lgo, Mincraft CSE554 Binary Picturs Sli 6
Binary Picturs Cration Procssing CSE554 Binary Picturs Sli 7
Sgmntation Sparating objct from backgroun in a grayscal pictur A simpl mtho: thrsholing by pixl (voxl) color All pixls (voxls) with color abov a thrshol is st to 1 Grayscal pictur Thrshol binary pictur CSE554 Binary Picturs Sli 8
Sgmntation Sparating objct from backgroun in a grayscal pictur A simpl mtho: thrsholing by pixl (voxl) color Othr mthos: K-mans clustring Watrsh Rgion growing Snaks an Lvl st Graph cut Mor tails covr in Computr Vision cours CSE554 Binary Picturs Sli 9
Rastrization Filling th intrior of a shap by pixls or voxls Known as scan-convrsion, or pixlization / voxlization Mor tails covr in Computr Graphics cours 2D Polygon Binary Pictur CSE554 Binary Picturs Sli 10
Binary Picturs Cration Procssing CSE554 Binary Picturs Sli 11
Binary Picturs Rmoving islans an hols Smoothing jagg bounaris CSE554 Binary Picturs Sli 12
Rmoving Islans & Hols Obsrvations: Islans (hols) of th objct ar hols (islans) of th backgroun Islans (hols) ar not as wll-connct as th objct (backgroun). Tak th largst 2 connct componnts of th objct Invrt th largst connct componnt of th backgroun CSE554 Binary Picturs Sli 13
Connct Componnts Dfinition A maximum st of pixls (voxls) in th objct or backgroun, such that any two pixls (voxls) in th st ar connct by a path of connct pixls (voxls) CSE554 Binary Picturs Sli 14
Connct Componnts How many connct componnts ar thr in th objct? What about backgroun? CSE554 Binary Picturs Sli 15
Connctivity (2D) Two pixls ar connct if thir squars shar: A common g 4-connctivity Two connct pixls All pixls connct to x x A common vrtx 8-connctivity 4-connctivity x 8-connctivity CSE554 Binary Picturs Sli 16
Connctivity (2D) Objct: 8-connctivity (1 comp) Objct: 4-connctivity (4 comp) CSE554 Binary Picturs Sli 17
Connctivity (2D) What connctivity shoul b us for th backgroun? Objct: 8-connctivity (1 comp) Backgroun: 8-connctivity (1 comp) Objct: 4-connctivity (4 comp) Backgroun: 4-connctivity (2 comp) Paraox: a clos curv os not isconnct th backgroun, whil an opn curv os. CSE554 Binary Picturs Sli 18
Connctivity (2D) Diffrnt connctivity for objct (O) an backgroun (B) 2D pixls: 4- an 8-connctivity rspctivly for O an B (or B an O) Objct: 8-connctivity (1 comp) Backgroun: 4-connctivity (2 comp) Objct: 4-connctivity (4 comp) Backgroun: 8-connctivity (1 comp) CSE554 Binary Picturs Sli 19
Connctivity (3D) Two voxls ar connct if thir cubs shar: A common fac Two connct voxls All voxls connct to th cntr voxl 6-connctivity A common g 6-connctivity 18-connctivity A common vrtx 26-connctivity 18-connctivity Us 6- an 26-connctivity rspctivly for O an B (or B an O) 26-connctivity CSE554 Binary Picturs Sli 20
Fining Connct Componnts Th flooing algorithm Start from a s pixl/voxl, xpan th connct componnt Eithr o pth-first or brath-first sarch (a LIFO stack or FIFO quu) // Fining th connct componnt containing an objct pixl p 1. Initializ 1. Crat a rsult st S that contains only p 2. Crat a Visit flag at ach pixl, an st it to b Fals xcpt for p 3. Initializ a quu (or stack) Q that contains only p. 2. Rpat until Q is mpty: 1. Pop a pixl x from Q. 2. For ach unvisit objct pixl y connct to x, a y to S, st its flag to b visit, an push y to Q. 3. Output S CSE554 Binary Picturs Sli 21
Fining Connct Componnts Why using a visit flag? Othrwis, th program will not trminat Why not chcking to s if y is in S? Chcking th visit flag is much fastr ( O(1) vs. O(log n) ) 1. 2. Rpat until Q is mpty: 1. Pop a pixl x from Q. 2. For ach unvisit objct pixl y connct to x, a y to S, st its flag to b visit, an push y to Q. 3. Output S CSE554 Binary Picturs Sli 22
Connctivity (2D) Connct componnts containing th blu pixl: 8-connctivity 4-connctivity CSE554 Binary Picturs Sli 23
Fining Connct Componnts Labling all componnts in an imag: Loop through ach pixl (voxl). If it is not labl, us it as a s to fin a connct componnt, thn labl all pixls (voxls) in th componnt. On componnt Two componnts 8-connct objct 4-connct objct CSE554 Binary Picturs Sli 24
Using Connct Componnts Pruning isolat islans from th main objct Filling intrior hols of th objct Tak th largst componnts of th objct Invrt th largst componnts of th backgroun CSE554 Binary Picturs Sli 25
Morphological Oprators Smoothing out objct bounary Opning Closing CSE554 Binary Picturs Sli 26
Morphological Oprators Oprations to chang shaps Erosion Dilation Opning: first ro, thn ilat. Closing: first ilat, thn ro. CSE554 Binary Picturs Sli 27
Mathmatical Morphology Input: x Objct (A) Structur lmnt (B x ) Erosion Dilation A B = {x A B x A} A B = x A B x CSE554 Binary Picturs Sli 28
Mathmatical Morphology Structur lmnt B is symmtric if: x B y y B x Exampls: x y x y x y Circl Squar Triangl CSE554 Binary Picturs Sli 29
Mathmatical Morphology Duality (for symmtric structuring lmnts) Erosion (ilation) is quivalnt to ilation (rosion) of th backgroun Erosion Dilation A B = A B A B = A B CSE554 Binary Picturs Sli 30
Mathmatical Morphology Opning (ro, thn ilat) x Objct (A) Structur lmnt (Bx) Opning A B = (A B) B Union of all B that can fit insi A Shavs off convx cornrs an thin spiks CSE554 Binary Picturs Sli 31
Mathmatical Morphology Closing (ilat, thn ro) x Objct (A) Structur lmnt (Bx) Closing A B = (A B) B Complmnt of union of all B that can fit in th complmnt of A Fills concav cornrs an thin tunnls CSE554 Binary Picturs Sli 32
Mathmatical Morphology Duality, again! (for symmtric structuring lmnts) Opning (closing) objct is quivalnt to closing (opning) backgroun Opning Closing A B = A B A B = A B CSE554 Binary Picturs Sli 33
Digital Morphology Structuring lmnts (symmtric) 2D pixls: squar or cross x x 3D voxls: cub or cross CSE554 Binary Picturs Sli 34
Digital Morphology Structuring lmnt: x Erosion : an objct pixl with som backgroun pixl in its squar nighborhoo Dilation : a backgroun pixl with som objct pixl in its squar nighborhoo CSE554 Binary Picturs Sli 35
Digital Morphology Structuring lmnt: 3x3 x squar Opning Union of whit squars within th objct Erosion Dilation Closing Union of black squars within th backgroun Dilation Erosion CSE554 Binary Picturs Sli 36
Digital Morphology Incrasing th siz of th structuring lmnt Las to mor growing/shrinking an mor significant smoothing Original Opning by 3x3 squar Opning by 5x5 squar Equivalnt to rpat applications with a small structuring lmnt E.g.: k rosions (ilations) follow by k ilation (rosions) with a 3x3 squar is quivalnt to opning (closing) with a (2k+1)x(2k+1) squar. CSE554 Binary Picturs Sli 37
Digital Morphology Implmntation tips Using uality of rosion an ilation, you only n to implmnt on function to o both morphological oprations (for symmtric structur lmnts). Dilation is sam as rosion of th backgroun Whn prforming multipl-roun opning, mak sur you first o k tims rosion thn k tims ilation What happns if you altrnat rosion an ilation for k tims? Hanl imag bounary in a gracful way (not crashing th program ) For xampl, trat outsi of th imag as backgroun CSE554 Binary Picturs Sli 38
Lab Moul 1 A simpl 2D sgmntation routin Initial sgmntation using thrsholing (using your co from Lab 0) Using connct componnts an opning/closing to clan up th sgmntation. CSE554 Binary Picturs Sli 39