CSE554Laplacian DeformationSlide 1 CSE 554 Lecture 8: Laplacian Deformation Fall 2012.
CSE 554 Lecture 1: Binary Pictures
description
Transcript of CSE 554 Lecture 1: Binary Pictures
![Page 1: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/1.jpg)
CSE554 Binary Pictures Slide 1
CSE 554
Lecture 1: Binary Pictures
CSE 554
Lecture 1: Binary Pictures
Fall 2013
![Page 2: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/2.jpg)
CSE554 Binary Pictures Slide 2
2xy ][][ ySinxSinz
Triangle surfaces
Polyline
Voxels
Curves Surfaces
Geometric FormsGeometric Forms
• Continuous forms
– Defined by mathematical functions
– E.g.: parabolas, splines, subdivision surfaces
• Discrete forms
– Disjoint elements with connectivity relations
– E.g.: polylines, triangle surfaces, pixels and voxels
Pixels
![Page 3: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/3.jpg)
CSE554 Binary Pictures Slide 3
Digital PicturesDigital Pictures
• Made up of discrete points associated with colors
– Image: 2D array of pixels
2D Image
![Page 4: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/4.jpg)
CSE554 Binary Pictures Slide 4
Digital PicturesDigital Pictures
• Color representations
– Grayscale: 1 value representing grays from black (lowest value) to white (highest value)
• 8-bit (0-255), 16-bit, etc.
– RGB: 3 values each representing colors from black (lowest value) to pure red, green, or blue (highest value).
• 24-bit (0-255 in each color)
– XYZ, HSL/HSV, CMYK, etc.
Grayscale
Low High
RGB
Low R High R
Low G High G
Low B High B
R G
B
![Page 5: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/5.jpg)
CSE554 Binary Pictures Slide 5
Digital PicturesDigital Pictures
• Made up of discrete points associated with colors
– Volume: 3D array of voxels
3D Volume
Voxel
![Page 6: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/6.jpg)
CSE554 Binary Pictures Slide 6
Binary PicturesBinary Pictures
• A grayscale picture with 2 colors: black (0) and white (1)
– The set of 1 or 0 pixels (voxels) is called object or background
– A “blocky” geometry
Background
ObjectAnalogy: lego
![Page 7: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/7.jpg)
CSE554 Binary Pictures Slide 7
Binary PicturesBinary Pictures
Creation Processing
![Page 8: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/8.jpg)
CSE554 Binary Pictures Slide 8
SegmentationSegmentation
• Separating object from background in a grayscale picture
– A simple method: thresholding by pixel (voxel) color
• All pixels (voxels) with color above a threshold is set to 1
Grayscale picture Thresholded binary picture
![Page 9: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/9.jpg)
CSE554 Binary Pictures Slide 9
SegmentationSegmentation
• Separating object from background in a grayscale picture
– A simple method: thresholding by pixel (voxel) color
– Other methods:
• K-means clustering
• Watershed
• Region growing
• Snakes and Level set
• Graph cut
• …
– More details covered in Computer Vision course
![Page 10: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/10.jpg)
CSE554 Binary Pictures Slide 10
RasterizationRasterization
• Filling the interior of a shape by pixels or voxels
– Known as “scan-conversion”, or “voxelization” in 3D
– More details covered in Computer Graphics course
2D Polygon Binary Picture
![Page 11: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/11.jpg)
CSE554 Binary Pictures Slide 11
Binary PicturesBinary Pictures
Creation Processing
![Page 12: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/12.jpg)
CSE554 Binary Pictures Slide 12
Connected ComponentsConnected Components
Take the largest 2 components of the object
![Page 13: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/13.jpg)
CSE554 Binary Pictures Slide 13
Connected ComponentsConnected Components
How many connected components are there in the object?
![Page 14: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/14.jpg)
CSE554 Binary Pictures Slide 14
Connectivity (2D)Connectivity (2D)
• Two pixels are connected if their squares share:
– A common edge
• 4-connectivity
– A common vertex
• 8-connectivity
Two connected pixels
x
x
All pixels connected to x
4-connectivity
8-connectivity
![Page 15: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/15.jpg)
CSE554 Binary Pictures Slide 15
Connectivity (2D)Connectivity (2D)
• Connected component
– A maximum set of pixels (voxels) in the object or background, such that any two pixels (voxels) are connected via a path of connected pixels (voxels)
4-connected object(4 components)
8-connected object(1 component)
![Page 16: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/16.jpg)
CSE554 Binary Pictures Slide 16
Connectivity (2D)Connectivity (2D)
• What is the component connected to the blue pixel?
8-connectivity 4-connectivity
![Page 17: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/17.jpg)
CSE554 Binary Pictures Slide 17
Connectivity (2D)Connectivity (2D)
• Can we use arbitrary connectivity for object and background?
Object: 8-connectivity (1 comp)
Paradox: a closed curve does not disconnect the background, while an open curve does.
Background: 8-connectivity (1 comp)
Object: 4-connectivity (4 comp)
Background: 4-connectivity (2 comp)
![Page 18: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/18.jpg)
CSE554 Binary Pictures Slide 18
Connectivity (2D)Connectivity (2D)
• Different connectivity for object (O) and background (B)
– 2D pixels: 4- and 8-connectivity respectively for O and B (or B and O)
Object: 8-connectivity (1 comp)
Background: 4-connectivity (2 comp)
Object: 4-connectivity (4 comp)
Background: 8-connectivity (1 comp)
![Page 19: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/19.jpg)
CSE554 Binary Pictures Slide 19
Connectivity (3D)Connectivity (3D)
• Two voxels are connected if their cubes share:
– A common face
• 6-connectivity
– A common edge
• 18-connectivity
– A common vertex
• 26-connectivity
• Use 6- and 26-connectivity respectively for O and B (or B and O)
6-connectivity
18-connectivity
26-connectivity
Two connected voxels
All voxels connected to the center voxel
![Page 20: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/20.jpg)
CSE554 Binary Pictures Slide 20
Finding Connected ComponentsFinding Connected Components
• The “flooding” algorithm
– Start from a seed pixel/voxel, expand the connected component
– Either do depth-first or breadth-first search (a LIFO stack or FIFO queue)
// Finding the connected component containing an object pixel p
1. Initialize
1. Create a result set S that contains only p
2. Create a Visited flag at each pixel, and set it to be False except for p
3. Initialize a queue (or stack) Q that contains only p.
2. Repeat until Q is empty:
1. Pop a pixel x from Q.
2. For each unvisited object pixel y connected to x, add y to S, set its flag to be visited, and push y to Q.
3. Output S
// Finding the connected component containing an object pixel p
1. Initialize
1. Create a result set S that contains only p
2. Create a Visited flag at each pixel, and set it to be False except for p
3. Initialize a queue (or stack) Q that contains only p.
2. Repeat until Q is empty:
1. Pop a pixel x from Q.
2. For each unvisited object pixel y connected to x, add y to S, set its flag to be visited, and push y to Q.
3. Output S
![Page 21: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/21.jpg)
CSE554 Binary Pictures Slide 21
Finding Connected ComponentsFinding Connected Components
• Why having a “visited” flag?
– Avoid inserting the same pixel to the queue (stack) multiple times
• Only look for “unvisited” neighbors
– Avoid searching in the list S for visited pixels
1. …
2. Repeat until Q is empty:
1. Pop a pixel x from Q.
2. For each unvisited object pixel y connected to x, add y to S, set its flag to be visited, and push y to Q.
3. Output S
1. …
2. Repeat until Q is empty:
1. Pop a pixel x from Q.
2. For each unvisited object pixel y connected to x, add y to S, set its flag to be visited, and push y to Q.
3. Output S
![Page 22: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/22.jpg)
CSE554 Binary Pictures Slide 22
Finding Connected ComponentsFinding Connected Components
• Labeling all components in an image:
– Loop through each pixel (voxel). If it is not labeled, find its connected component, then label all pixels (voxels) in the component.
8-connected object 4-connected object
One component
Two components
![Page 23: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/23.jpg)
CSE554 Binary Pictures Slide 23
Using Connected ComponentsUsing Connected Components
• Pruning isolated islands from the main object
• Filling interior holes of the object
Take the largest 2 components of the object
Invert the largest component of the background
![Page 24: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/24.jpg)
CSE554 Binary Pictures Slide 24
Morphological OperatorsMorphological Operators
• Smoothing out object boundary
Opening
Closing
![Page 25: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/25.jpg)
CSE554 Binary Pictures Slide 25
Morphological OperatorsMorphological Operators
• Operations to change shapes
– Erosion
– Dilation
– Opening: first erode, then dilate.
– Closing: first dilate, then erode.
![Page 26: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/26.jpg)
CSE554 Binary Pictures Slide 26
Morphological OperatorsMorphological Operators
Object (A) Structure element (Bx)
x
A B x A Bx A A B xA
Bx
DilationErosion
![Page 27: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/27.jpg)
CSE554 Binary Pictures Slide 27
Morphological OperatorsMorphological Operators
• Duality (if the structuring element is symmetric)
– Dilation is equivalent to erosion of the background
DilationErosion
A B A B A B A B
![Page 28: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/28.jpg)
CSE554 Binary Pictures Slide 28
Morphological OperatorsMorphological Operators
• Opening (erode, then dilate)
– Union of all structuring elements B contained in A
– Shaves off convex corners and thin spikes
A B A B B
Object (A) Structure element (Bx)
x
Opening
![Page 29: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/29.jpg)
CSE554 Binary Pictures Slide 29
Morphological OperatorsMorphological Operators
• Closing (dilate, then erode)
– Complement of union of structuring elements B outside A
• Equivalent to “opening” the background (because of duality)
– Fills concave corners and thin tunnels
A B A B BClosing
Object (A)
Structure element (Bx)
x
![Page 30: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/30.jpg)
CSE554 Binary Pictures Slide 30
Digital MorphologyDigital Morphology
• Structuring elements (symmetric)
– 2D pixels: square or cross
– 3D voxels: cube or cross
xx
![Page 31: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/31.jpg)
CSE554 Binary Pictures Slide 31
Digital MorphologyDigital Morphology
• Structuring element: square
– Erosion
• e: an object pixel with some background pixel in its square neighborhood
– Dilation
• d: a background pixel with some object pixel in its square neighborhood
e
e
e
e
e
ee e
e
d
dd d
d d
d
d
d
d
d
d
d d
d d
d d
![Page 32: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/32.jpg)
CSE554 Binary Pictures Slide 32
Digital MorphologyDigital Morphology
• Structuring element: square
– Opening
– Closing
e
e
e
e
e
ee e
e dd d
dd d
d d
Erosion Dilation
dd d
d dd d
d d
d d
d d
d ddd d
d
ee e
e ee e
e e
e e
e e
e eee e
Dilation Erosion
Union of white squares within the object
Union of white squares within the object
Union of black squares within the background
Union of black squares within the background
![Page 33: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/33.jpg)
CSE554 Binary Pictures Slide 33
Digital MorphologyDigital Morphology
• Increasing the size of the structuring element
– Leads to more growing/shrinking and more significant smoothing
– Equivalent to repeated applications with a small structuring element
• E.g.: k erosions (dilations) followed by k dilation (erosions) with a 3x3 square is equivalent to opening (closing) with a (2k+1)x(2k+1) square.
Original Opening by 3x3 square Opening by 5x5 square
![Page 34: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/34.jpg)
CSE554 Binary Pictures Slide 34
Digital MorphologyDigital Morphology
• Smoothing out object boundary
Opening
Closing
Using a 5x5 square
![Page 35: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/35.jpg)
CSE554 Binary Pictures Slide 35
Digital MorphologyDigital Morphology
• Implementation tips
– Using duality of erosion and dilation, you only need to implement one function to do both morphological operations.
• Dilation is same as erosion of the background
– When performing multiple-round opening, make sure you first do k times erosion then k times dilation
• What happens if you alternate erosion and dilation for k times?
– Handle image boundary in a graceful way (not crashing the program…)
• Treat outside of the image as background
![Page 36: CSE 554 Lecture 1: Binary Pictures](https://reader036.fdocuments.us/reader036/viewer/2022062723/56813f64550346895daa3754/html5/thumbnails/36.jpg)
CSE554 Binary Pictures Slide 36
• A simple 2D segmentation routine
– Initial segmentation using thresholding (using your code from Lab 0)
– Using connected components and opening/closing to “clean up” the segmentation.
Lab Module 1Lab Module 1