CMPUT 206 Introduction to Digital Image Processing
Overview. What is a pixel in an image? 2. How does Photoshop, + human assistance, detect an edge in a picture/photograph? 3. Behind Photoshop - How does the computer do it?
Pixel as the basic unit An image is processed in memory as bytes (8bits/bytes) Grey scale image [0 255] byte pixel Color image [RGB of values 0-255] 3 bytes pixel
0, 0) X Pixel as the basic unit R 80 6 228 234 G 84 8 87 93 B 09 0 59 65 (256, 256)
Definition of Edges What are edges in an image? Locations where there is a sudden variation in the grey or color scale. Which image does not contain edges? a b c d e f g h i
Definition of Edges Use Photoshop Find Edges tool: a b c d e f g h i
Sharpen edges in images Photoshop Demo Sharp Blur High contrast Low contrast Increase contrast and sharpen edges Filter sharper sharpen edges/sharpen more
Sharpen edges in images Photoshop Demo Bright Low luminosity Sharpen and image-adjustcurves Discover features Filter sharper sharpen edges/sharpen more
Region growing + Edge detection The Magic Wand Tool in Photoshop
Can Computer do as well as human? Computer applies edge detection technique based on numeric computation, not based on human perception and cognitive skill
A Simple Edge Detector - gradient Based on grey scale gradient at a pixel g x ( x, y) f ( x+, y) f ( x, y) x g y ( x, y) f ( x, y+ ) f ( x, y ) y 98 98 98 06 0 03 0 6 5 38 60 0 95 68 60 29 0 6 95 65 03 0 6 20 00 3 9 72-35 39-5 5-60 -38-35 -50 78 35 42 56 Assuming threshold T = 50, a pixel is selected if >= T What is 2 2 x g y g + Answer: 7 40 36 87 85 52 44 76
Gradient detection (continued) Red squares represent selected pixels Detected edge 98 98 98 06 0 03 0 6 5 38 60 0 95 68 60 29 0 6 95 65 03 0 6 20 g 2 + 2 x g y = 7 40 36 87 85 52 44 76 Assuming threshold = 50
Gradient detection (continued) The two gradients g x and g y computed at each pixel are regarded as the x and y components of a gradient vector, which has gradient magnitude and direction given by: 2 2 = g x g y = g y θ tan g x g + where the orientation θ is measured relative to x axis. Gradient magnitude is sometimes approximated by: g = g x + g y
Find edges in images Photoshop Demo (Try R, G, B in lab) Extract Intensity values Stylize find edges Apply Edge Detection
Find edges in images Find Edges applying different thresholds T, the results are ferent: - sign value 255 if < T sign value 0 if >= T increasing threshold (Assume Gradient Approach) T T2 T3
Apply edge detection kernels. Suppose a nxn (n is an odd number) kernel is used and the centre position of the kernel is denoted by kc. 2. Slide the kernel across the image, one pixel at a time. 3. Compute the new value of each pixel, which is under kc, and repeat for all pixels in the image. 4. Note that the process is not in-place (new values are stored in a new image of same dimension. 5. Computation: For each pixel inside the kernel, multiply the pixel value with the kernel value. Take the sum of the products. 6. (a) The border pixel can be duplicated, or (b) take the mirror values of the border pixels, to fill up the kernel. C Image border R Image (RxC pixels) Kernel (nxn pixels) 6 (a) 23 23 23 20 8 6 (b) 8 20 23 20 8
Edge detection kernels Noise reduction or elimination Examples of Image pixels 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 0 0 0 Edge enhancement Concept of filtering An example of Low Pass Filtering: Edge localization 9 An example of High Pass Filtering: 8
Convolution operation Based on convolution operations compute weighted averages over a 3x3 neighborhood ), ( ), ( y x f h y x g x x = ), ( ), ( y x f h y x g y y = where the (Prewitt) kernels are: = 0 0 0 h x = 0 0 0 h y Note: high order convolution kernels ike 5x5, etc. can also be used, but they are more computational expensive
Convolution operation (continued) 0 = 0 h y = 0 0 suming threshold = ±50 0 0 () Is 98 an edge? 98 99 97 99 98 97 99 98 97 (2) What are the detected pixels? 98 98 98 06 0 03 0 6 5 38 60 0 95 68 60 29 0 6 95 65 03 0 6 20 09 93 74 46-4 -8-37 -80-45 -94 0-72 72 68 06 89 (3) What will happen if the threshold is ±00? ±50?
Simple Edge Detectors One edge but thick Result from gradient Result from Prewitt kernels Threshold=±50 Threshold=±00 or ±50
An Example Gradient magnitudes [Reference ] Apply threshold T: If < T, value If >= T, value 2 p Left) Original p Right) Apply gradient magnitudes and scale to 0-255 range tom Left) Apply threshold of 50 op Right tom Right) Apply threshold 50 to Top Right
Scaling grey values onto another range Let O range, O min and O max be the original range, minimum value and maximum value, i.e. O range = O max O min The N range, N min and N max be the original range, minimum value and maximum value, i.e. N range = N max N min To map a pixel P from the original range to P in the new range: P' = P O O min range N range + N min
Advantage of a bigger grey value range before processing Threshold 50 Map from 0-00 To 0-255 Find edges Threshold 28
Sobel kernels Sobel kernels, which give more weights to onaxis pixels h x 0 = 2 0 2 h y = 0 0 2 0 2 0 ross from grey white +ve value (assign pixel value 0 if <0) rom white o grey -ve value Original image convoluation with hx with hy
Noise in an image Problem with edge localization High threshold may suppress meaningful edges Low threshold may include unwanted edges Noise may have high magnitude With noise Without noise x Gradient magnitude Gradient magnitude is very sensitive to noise
Blurred edges The detected edge can be rather broad in the case of diffuse edges, resulting in a thick band of pixels instead of a single point of maximum gradient. Sharp edge Grey values Slightly blurred Heavily blurred x
Sharp & Blurred Edges Grey values 255 Sharp edge Blurred edge
Rank or order statistic filtering Non-linear In image processing it is usually necessary to perform high degree of noise reduction in an image before performing higher-level processing steps, such as edge detection. A non-linear digital filtering technique is often used to remove noise from images or other signals.
Rank or order statistic filtering (continued) Compile a list of grey scales in the neighborhood of a given pixel, sort them in ascending order and select a value as the new value Median filter; any structure that occupies less than half of the filter s neighborhood will be eliminated Minimum filter and Maximum filter Range filter: output the difference between the maximum and minimum
Rank or order statistic filtering (continued) Hybrids of linear and non-linear filters, e.g. α-trimmed mean filter: sorts the neighborhood into ascending order, discards a number of them and outputs the mean of the remaining (α is the number of values removed, in the range [0, (n 2 )/2] from each end of the list) when α = 0: mean filter when α = (n 2 )/2: median filter n 2 2α 2 n α f i i= α+
Median filter Non-linear technique Consider all pixels inside the filter. Compile a list of grey values and sort them in ascending order. select a value as the new value Median filter; any structure that occupies less than half of the filter s neighborhood will be eliminated Have the advantage of non kernel-based; no problem to filter a smaller neighborhood at the corners or sides of the image The shape of the filter applied at the corner can give different results, e.g. square vs. cross-shaped
Rank filtering examples 8 3 23 20 5 2 8 8 0 What is the filtered value of the centre pixel after applying a:. median filter 2 2. mean filter 3 3. maximum filter 23 4. minimum filter 5 5. range filter 8 6. 4-trim filter 2 7. 0-trim filter 3 8. 2-trim filter 2
Median filtering example The square and the cross are both median filters p P (a) (b) What is the filtered value of P in (a)? What is the filtered value of P in (b)?
References. Digital Image Processing a practical introduction using Java Nick Efford, Pearson Education 2000.