CITS 4402 Computer Vision A/Prof Ajmal Mian Adj/A/Prof Mehdi Ravanbakhsh, CEO at Mapizy (www.mapizy.com) and InFarm (www.infarm.io) Lecture 02 Binary Image Analysis
Objectives Revision of image formation Binary image analysis Otsu s thresholding Morphological operations Grayscale image analysis (basics for now) Industry project
Lecture 01 Image Formation
Lecture 01 Sampling and Quantization
Lecture 01 Continuous Image Projected onto a Sensor Array
Lecture 01 Representing Image as a Matrix
Lecture 01 Computer Vision: Make Sense of Numbers 255 255 240 255 255 248 232 255 252 247 238 239 255 255 255 255
Frequency How Many Grey Levels? Each pixel represented by one byte 256 discrete intensity values can be encoded 0 indicates perfect black 255 indicates perfect white Each value represents a shade of gray, called a grey-level Image histogram represents how many times each grey-level appears in the image Grey-Levels
Binarization Reduce number of grey levels to two (foreground and background) Objects segmented from background Textual images or document images Much `information' can be lost by binarization Binary images are often simpler to process than grayscale images These arguments need to be traded of before choosing between binary and gray scale image processing approaches
Binarization Binary images are usually the result of a thresholding process. T constant -> global thresholding T depends on local property p(x,y) -> local thresholding Possible principles for thresholding Manual (interactive / trial and error) x fraction for black and white and use histogram distribution-based (typically: two peaks in histogram; find `valley' between two `hills )
Why is Thresholding Difficult?
Otsu Thresholding The aim is to find a threshold that minimizes the intra-class variance (i.e. minimum variation in the foreground + minimum variation in the background) Question: How? Answer: Exhaustive search. Within-class variance = foreground variance + background variance Minimizing the within-class variance is the same as maximizing the between-class variance N. Otsu, A threshold selection method from gray-level histograms," IEEE Trans. on Systems, Man, & Cybernetics, 9(1), 62-66, 1979.
Algorithm: Otsu Thresholding
Otsu s Results
In Matlab I = imread('coins.png'); level = graythresh(i); BW = im2bw(i,level); imshow(bw) Its easy in Matlab, but you don t know what is happening inside For further reading visit: http://www.labbookpages.co.uk/software/imgproc/otsuthreshold.html
Local Thresholding
Local vs Global Methods Global Thresholding methods are: Fast Give good results when illumination over a page is uniform Fail when there are local changes in illumination Local Thresholding methods are: Slow Adapt to local changes in illumination Perform well for both uniform and non-uniform illumination
Analysing Binary Images How many objects are in this image?
Connected Component Analysis Scan the image row by row When a foreground pixel is encountered, assign it a label: If the left neighbour pixel belongs to the background, a new label is assigned to the current foreground pixel If the left neighbour pixel belongs to the foreground, its label is copied to the current pixel If the upper neighbour pixel belongs to the foreground, merge the label of the current pixel and that of the upper neighbour
Connected Component Analysis
Connected Component Analysis 4- or 8- Neighbourhood 4-neighbourhood 8-neighbourhood
Connected Component Analysis
Features of Connected Components Shape features Area Bounding box Boundary length Compactness Features may or may not have invariance properties Translation invariance Rotation invariance Scale invariance
Features of Connected Components Area Count number of pixels For an arbitrarily fine resolution, the area is translation and rotation invariant. Discretization effects may cause considerable variations.
Features of Connected Components Bounding Box Easy to compute Invariance?
Features of Connected Components Boundary Length The boundary length (perimeter) is defined as the number of pixels which constitute the boundary of a shape.
Features of Connected Components Compactness compactness = area / boundary length 2
Analysing Binary Images How many objects are in this image?
Morphological Image Processing View binary images as 2-dimensional sets Basic set-theory concepts you are familiar with: element, subset, union, intersection, disjoint sets, complement, difference
Morphological Image Processing Additional Basic Concepts
Morphological Image Processing Dilation Dilation of A by B: B is called the structuring element
Morphological Image Processing Dilation
Morphological Image Processing Erosion Erosion of A by B:
Morphological Image Processing Erosion Image containing squares of sizes 1, 3, 5, 7, 9, and 15 pixels on the side Erosion using a 13x13 structuring element Dilation using the same 13x13 structuring element
Morphological Image Processing Opening Opening of A by B: Smoothens outlines Breaks narrow bridges, removes protrusions
Morphological Image Processing Closing Closing of A by B: Smoothens outlines Fuses narrow breaks, eliminates holes, fills gaps in contour
Morphological Image Processing Opening and Closing
Morphological Image Processing Boundary Extraction Boundary extraction using morphological operators
Analysing Binary Images How many objects are in this image?
Analysing Binary Images Opening How many objects are in this image?
Analysing Binary Images Closing How many objects are in this image?
The Distance Transform Finding Thickness of Objects Region 4-neighbourhood 8-neighbourhood
The Distance Transform Algorithm Two-Pass Algorithm: The distance transform can be computed by performing a series of local operations while scanning the image twice. For any p let B(p) (`before') be the set of pixels (4- or 8-) adjacent to p that precede p when scanning in standard order: If p has coordinates (x, y), B contains (x, y 1) and (x 1, y), and if we use 8- adjacency it also contains (x 1, y 1) and (x + 1, y 1). Let A(p) (`after') be the remaining (4- or 8-) neighbours of p.
The Distance Transform Algorithm First scan (standard order) Second scan (reverse order)
The Distance Transform Step 1 Step 2 4-neighbourhood 8-neighbourhood
The Distance Transform Euclidean distance (L2 norm) sqrt((x1 y1)^2+ (x2-y2)^2 +... ) City block distance (L1 norm) x1 y1 + x2-y2 + Original Image L 2 distance transform L 1 distance transform
Application: Separation of overlapping objects
Application: Separation of overlapping objects
Grayscale Image Analysis Generally, we can get more information from a grayscale image The bulk of computer vision techniques process grayscale images We will only touch upon the basics today Recall that a grayscale image is a matrix of integers in the range (0-255)
Images as Surfaces The same image represented as a surface on the right Brightness corresponds to height on the surface
Image as Surfaces
How does an edge look like?
What would a line look like?
What would a line look like?
And the ground
A feature
How does this help us?
The concept of terrain Uphill / downhill Contour lines Steepness of slope Peaks / valleys (local extrema)
Terrain Concepts Mathematical Notions Tangent plane Normal vector Curvature Gradient vectors (vectors of partial derivatives) will help compute all these
Example of 1-D Gradient
1-D Gradient
1-D Gradient
1-D Gradient
Gradients are informative
Images are 2-D Let us define 2-D Gradients
2-D Gradients Plotted as vectors Gradient at each pixel points uphill The gradient indicates the direction of steepest ascent The gradient is zero at the peak
2-D Gradients
2-D Gradients We can do these calculations for all points
2-D Gradient Example on a Real Image Notice how the contours of the cameraman have been detected
Importance of road junctions Application in car navigation, traffic management, intelligent transportation systems etc.
Carried out in three steps: Clipping island area where islands are present Morphological opening, closing and Gaussian smoothing Thresholding Clipped island area Pre-processed image Segmentation result
Summary Conversion of a grayscale image to binary (global vs local thresholds) Connected component analysis Morphological image processing Distance Transform Grayscale image analysis with gradients Industry project
Acknowledgements Material presented in this lecture is taken from different sources including previous lectures prepared at UWA, textbooks of image processing and computer vision, online resources and Robert Collins lectures (Penn State University)