Presentation is loading. Please wait.

Presentation is loading. Please wait.

Image representation using arrays Image processing examples

Similar presentations


Presentation on theme: "Image representation using arrays Image processing examples"— Presentation transcript:

1 Image representation using arrays Image processing examples
Lecture Feb 14, 2011 Goals: Image representation using arrays Image processing examples image filtering mean and median filters 1

2 Array representation of images
Image: A pixel is a square region on a display device that can be illuminated with one of the color combinations. A wide range of colors can be specified using 3 bytes – one for each color R, G and B. R = 255, G = 255, B = 255 represents White. R = 0, G = 0, B = 0 represents Black. Bitmap format: uncompressed, each pixel information stored. Header + each pixel description 2

3 Image processing problems
image storage and access problems format conversion rotate, combine and other edit operations compress, decompress image enhancement problems Remove noise Extract features Identify objects in image Medical analysis (e.g. tumor or not) 3

4 An image filtering problem
A small percentage (~ 5%) of pixels have become corrupted – randomly changed to arbitrary value. (salt and pepper noise). How should we remove this noise? Original image image with noise after filtering The image has become blurred, but this can be corrected. 4

5 Mean filtering For each pixel, consider its eight neighbors.
Replace its color value by the average of the 9 color values, itself and the 8 neighbors. Example: Suppose all the neighbors were blue pixels (0, 0, 150), but the center was red (noise), say (200, 0, 0). Then, the average value = (22, 0, 133). This color is much closer to blue, so the noise has been removed. 5

6 Algorithm for mean filtering
I = input image; O = output image; w = width of the image; h = height of the image; for j from 1 to w-2 do for k from 1 to h-2 do O(j,k)->Blue = (I(j,k)->Blue + I(j-1,k)->Blue + I(j+1,k)->Blue + I(j,k-1)->Blue + I(j-1,k-1)->Blue+ I(j+1,k-1)->Blue +I(j,k+1)->Blue + I(j-1,k+1)->Blue+ I(j+k+1)->Blue)/9; // similarly for other colors end do; On a 1024 x 1024 pixel image, how many operations does this perform? More generally, on an n x n image? Answer: O(n2) which is linear since the size of the input is O(n2). More precisely, ~ 30 n2 operations. 6

7 Algorithm for mean filtering
I = input image; O = output image; w = width of the image; h = height of the image; for j from 0 to w-1 do O(0,j)->Blue = I(0,j)->Blue; // etc. for all colors end for; for k from 0 to h-1 do O(k,0)->Blue = I(k,0)->Blue; // etc. for all colors for j from 1 to w-2 do for k from 1 to h-2 do O(j,k)->Blue = (I(j,k)->Blue + I(j-1,k)->Blue + I(j+1,k)->Blue + I(j,k-1)->Blue + I(j-1,k-1)->Blue+ I(j+1,k-1)->Blue +I(j,k+1)->Blue + I(j-1,k+1)->Blue+ I(j+k+1)->Blue)/9; // similarly for other colors 7

8 Median filter A problem with mean filter is that the image loses its sharpness. Median filter does a better job. Median filter examines the neighborhood pixel values and sort them, replace the current pixel value by the median value. Example: 37 41 39 40 234 38 42 44 Sorted sequence: 37, 38, 38, 39, 40, 41, 42, 44, 234 A good choice to find the median is insertion sorting. Which is better - Insertion sorting or selection sorting? 8

9 Median filter algorithm
I = input image with random noise O = output image by median filtering I w = width of the image; h = height of the image; for j from 0 to w-1 do O(0,j)->Blue = I(0,j)->Blue; // etc. for all colors end for; for k from 0 to h-1 do O(k,0)->Blue = I(k,0)->Blue; // etc. for all colors for j from 1 to w-2 do for k from 1 to h-2 do copy { I(j-1,k)->Blue, I(j+1,k)->Blue, I(j,k-1)->Blue, I(j-1,k-1)->Blue, I(j+1,k-1)->Blue, I(j,k+1)->Blue, I(j-1,k+1)->Blue, I(j+k+1)->Blue)} into a temp array of size 9; sort(temp) using insertion sorting; O(j,k)-> Blue = temp[4]; // similarly for other colors 9

10 Median filter output - example

11 Time complexity of median filtering
Worst-case: for each color component, sorting an array of size 9 involves about 45 comparisons and about 45 data movements. Total number of operations is ~ 270 n2. For a 1024 x 1024 image, the total number of operations is ~ 270 million. 11

12 Summary algorithm analysis involves measuring the number of operations performed by an algorithm before implementing it. This will provide some guideline on which one to implement. many ways to measure efficiency of algorithms: average vs. best case vs. worst-case time, storage, bandwidth etc. which operations? +, == , assignment, or all of them? O notation is used to approximate the time complexity. (gives just the order of magnitude).


Download ppt "Image representation using arrays Image processing examples"

Similar presentations


Ads by Google