Presentation is loading. Please wait.

Presentation is loading. Please wait.

240-373: Chapter 4: Statistical Operations 1 Montri Karnjanadecha ac.th/~montri 240-373 Image Processing.

Similar presentations


Presentation on theme: "240-373: Chapter 4: Statistical Operations 1 Montri Karnjanadecha ac.th/~montri 240-373 Image Processing."— Presentation transcript:

1 240-373: Chapter 4: Statistical Operations 1 Montri Karnjanadecha montri@coe.psu.ac.th http://fivedots.coe.psu. ac.th/~montri 240-373 Image Processing

2 240-373: Chapter 4: Statistical Operations 2 Chapter 4 Statistical Operations

3 240-373: Chapter 4: Statistical Operations 3 Statistical Operations Gray-level transformation Histogram equalization Multi-image operations

4 240-373: Chapter 4: Statistical Operations 4 Histogram If the number of pixels at each gray level in an image is counted (may use the following code fragment) for (row=0; row<rowmax; roww++) for (col=0; col=colmax; col++) { count[image[row,col]]++; }

5 240-373: Chapter 4: Statistical Operations 5 Histogram The array “count” can be plotted to represent a “histogram” of the image as the number of pixels at particular gray level The histogram can yield useful information about the nature of the image. An image may be too bright or too dark.

6 240-373: Chapter 4: Statistical Operations 6 Histogram Illustration 0 12345 0 1 2 3 4 5 6 7 8 9 10 1 2 3 2 3 2 0 0 1 2 1 4 4 4 2 1 2 1 1 2 1 2 1 2 5 4 2 1 4 0 Histog ram

7 240-373: Chapter 4: Statistical Operations 7 Global Attenuation in Brightness To alter the brightness of an image by adding or subtracting all pixel values with a constant for (row=0; row<rowmax; roww++) for (col=0; col=colmax; col++) { image[row,col] += constant; }

8 240-373: Chapter 4: Statistical Operations 8

9 9

10 10

11 240-373: Chapter 4: Statistical Operations 11

12 240-373: Chapter 4: Statistical Operations 12 Thresholding Use: –To remove the gray level trends in an image –To make gray level more discrete –To segment or split an image into distinct parts Operation: –setting all gray levels below a certain level to “zero”, and above a certain level to a maximum brightness

13 240-373: Chapter 4: Statistical Operations 13 Code for Thresholding for (row=0; row<rowmax; roww++) for (col=0; col=colmax; col++) { if (image[row,col] > threshold) image[row,col] = MAX; else image[row,col] = MIN; }

14 240-373: Chapter 4: Statistical Operations 14

15 240-373: Chapter 4: Statistical Operations 15 Thresholding Errors Rarely is it possible to identify a perfect gray level break, what we want to be background pixels become foreground or vice versa –Type 1: not all pixels caught that should be included –Type 2: some pixels caught should not be included in the group

16 240-373: Chapter 4: Statistical Operations 16 An image before and after thresholding

17 240-373: Chapter 4: Statistical Operations 17 Bunching (Quantizing) Use: –to reduce the number of different gray level in an image –to segment an image –to remove unwanted gray level degradation Operation: –Close gray levels are combined, thus removing unwanted variations in data

18 240-373: Chapter 4: Statistical Operations 18 Bunching (Quantizing) Method 1: inspecting histogram and combining close group into single gray level Method 2: identifying a set of gray levels allowed in the final image, then changing the gray level in every pixel to its nearest allowed value

19 240-373: Chapter 4: Statistical Operations 19 Bunching Example 0 **** 1 ** 2 ***** 3 ********* 4 ***** 5 ***** 6 ***** 7 ***** 8 ********* 9 *** 0 ****** 1 2 3 ******************* 4 5 6 *************** 7 8 9 ************

20 240-373: Chapter 4: Statistical Operations 20 Bunching Code for (row=0; row<rowmax; row++) for (col=0; col<colmax; col++) { image[row,col] = bunchsize*((int)image[row,col]/bunchsize); } bunchsize = number of levels to be grouped into one

21 240-373: Chapter 4: Statistical Operations 21 Splittings Use: –to increase the different two groups of gray levels so that the contrast between segments compose of one group of the other is enhanced Operation: –rounding the gray levels up if they are in the range and down if they are in another

22 240-373: Chapter 4: Statistical Operations 22 Splitting Example The characters on a car number-plate are at gray level 98 The background of the characters is at gray level 99 Pushing 98 down to 80 and pushing 99 up to 120 will give the picture a better contrast around the number plate Question: How to find a good splitting level?

23 240-373: Chapter 4: Statistical Operations 23 Automatic Selection of Splitting Level Use: –to find the best gray level for splitting--usually for thresholding to black and white Operation: –Let

24 240-373: Chapter 4: Statistical Operations 24 Automatic Selection of Splitting Level –Let P=NxM = the number of pixels under consideration –Let m(g) = mean gray level for only those pixels containing gray level between zero and g, i.e. If the maximum number of gray level is G (G=0,…,G-1) then evaluate the following equation (T = splitting threshold) AB

25 240-373: Chapter 4: Statistical Operations 25 Example Histogramf(g)t(g)g.f(g)  g.f(g) m(g)ABA*B 0 ****440000.0823.040.18 1 **26220.30.1320.252.83 2 *****51110121.10.2713.693.70 3 *********920273920.637.844.94 4 *****52520592.40.935.765.36 5 *****53025842.81.364.005.44 6 *****535301143.32.062.254.64 7 *****540351493.73.331.214.03 8 *********949722214.516.330.091.47 9 ***352272484.8-INF- T = max(A*B) - 1 = 4

26 240-373: Chapter 4: Statistical Operations 26 Technique 6: General gray-level transformations USE: To combine thresholding, bunching and splitting into one operation. This is also useful as a single tool in a set of software tools for image processing, since it does anyone of the technique on any part of the histogram. OPERATION: A function F(g) can be specified which transforms any gray level g to a new gray level q F(g) transform

27 240-373: Chapter 4: Statistical Operations 27 Original histogram Final histogram

28 240-373: Chapter 4: Statistical Operations 28 Histogram equalization Technique 7: Histogram equalization USE: To improve contrast of an image. Can be used on a whole image or just on a part of an image. THEORY: where G is total number of gray levels.

29 240-373: Chapter 4: Statistical Operations 29 Histogram equalization (cont’d) OPERATION: if t(g) is the actual number of pixels at old gray level g or less, then

30 240-373: Chapter 4: Statistical Operations 30 Histogram equalization example

31 240-373: Chapter 4: Statistical Operations 31 Example

32 240-373: Chapter 4: Statistical Operations 32 Example

33 240-373: Chapter 4: Statistical Operations 33 Multi-image operations Occasionally, it is useful to prepare a new image from a number of previous images. Example: white shape on white paper –problem: difficult to distinguish between the shape and the paper due to bad lighting. –solution 1: improve the lighting –solution 2: capture an extra image of pure white paper without shape under the same lighting, then subtract the two images.

34 240-373: Chapter 4: Statistical Operations 34 Technique 8 Technique 8: Background subtraction USE: To remove light shading or discover movement from one image to another THEORY: Gray level in each pixel in one image is subtracted from the gray level in the corresponding pixel in other image, i.e. result = x-y (x >= y) If x < y the result is negative: -1 is held as 255, -2 is held as 254 and so on

35 240-373: Chapter 4: Statistical Operations 35 Technique 8 cont’d A better operation: result = | x - y | OPERATION: Collect both images. One image, x, should be on a pure background. The image with object will form image y. For each pixel calculate abs(x-y) This will give a negative image of the object. To return the image to a positive, use the following formula new image = MAX - abs(x-y)

36 240-373: Chapter 4: Statistical Operations 36 Background with uneven lighting

37 240-373: Chapter 4: Statistical Operations 37 Original Image

38 240-373: Chapter 4: Statistical Operations 38 Image after background subtraction


Download ppt "240-373: Chapter 4: Statistical Operations 1 Montri Karnjanadecha ac.th/~montri 240-373 Image Processing."

Similar presentations


Ads by Google