You are on page 1of 8

Assignment # 6th

Applied Image Processing


Submitted To: Sir Arfan Jaffar Submitted By: M.Faisal Abbas i07-0443

FAST- NUCES Islamabad

Question 1: Consider the 7x7 image segment shown below. Each value is gray level of a pixel. 1234567 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 Find the following distances between pixels with gray levels 25 and 36. (a) Euclidean distance= sqrt ( (6-4)2 +(1-4)2 ) = sqrt ( 4 + 9 ) = 3.6 (b) City block distance= abs( 6-4 ) + abs(1-4) =2+3=5 (c) Chessboard distance= max( abs( 6- 4 ) , abs( 1-4)) = max( 2 , 3) = 3 Question 2: Repeat Question 1 for pixels with gray levels 34 and 9. a. Euclidean distance= sqrt ( (5-2)2 +(6-2)2 ) = sqrt ( 9 + 16 ) = 5 b. City block distance= abs( 5-2 ) + abs(6-2) =3+4=7 c. Chessboard distance= max( abs( 5 -2 ) , abs( 6-2 )) = max( 3 , 4) = 4 Question 3: For the image of Question 1, write the gray levels of the pixels that are within a distance of 3 (distance 3 or less) from the pixel with gray level 25. Solve for the following distance types: (a) Euclidean distance 9 10 11 12 13 16 17 18 19 20 23 24 - 26 27 30 31 32 33 34 37 38 39 40 41 (b) City block distance - 10 11 12 16 17 18 19 20 23 24 - 26 27 30 31 32 33 34 - 38 39 40 (c) Chessboard distance 1234567 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 - 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 Question 4: Explain the advantages of using array sensors instead of line sensors to acquire an image. Ans. Line sensor is one dimensional and takes one line at a time and requires a large amount of processing time. Array sensors are two dimensional , it takes the whole image reducing the processing time.

Question 5: (a) What will be size of a 256 gray level image in bits if the size of the image is 1000x500 pixels. (b) If the image is down-sampled to 500x250 and total number of gray levels is changed to 64, what will be the size of the new image in bits? Ans. a. 1000 * 500 * 8 b. 500 * 250 * 6 Question 6: Consider the image segmentation of a binary image shown below. You have to find a path from the two encircled pixels with gray level 1 (top-left and bottom-right pixels). Show the path by drawing the image and connecting the points that make the path. If there is no path, just write No Path Exists. If multiple paths are possible, show all paths. 11000 01000 00100 00011 00001 (a) 4-Connectivity (b) 8-Connectivity (c) M-Connectivity Ans. a. No Path Exist b. There are 4 paths exist. 1. 1 1 - - -1----1----11 ----1 2. 1 - - - -1----1----11 ----1 3. 1 1 - - -1----1----1----1 4. 1 - - - -1----1----1----1 c. There is only single path exist 11---1----1----11 ----1 Question 7: Explain the difference (in terms of the values of the gray levels used for pixels) between the following four types of images: (a) Binary Image

Binary image also known as a bi-level image. Logical array containing only 0s and 1s, interpreted as black and white, respectively. (b) Gray level Image (e.g. 256 gray levels image) A grayscale image (also called gray-scale, gray scale, or gray-level) is a data matrix whose values represent intensities within some range. MATLAB stores a grayscale image as a individual matrix, with each element of the matrix corresponding to one image pixel. By convention, this documentation uses the variable name I to refer to grayscale images. The matrix can be of class uint8, uint16, int16, single, or double.While grayscale images are rarely saved with a colormap, MATLAB uses a colormap to display them. For a matrix of class single or double, using the default grayscale colormap, the intensity 0 represents black and the intensity 1 represents white. For a matrix of type uint8, uint16, or int16, the intensity intmin(class(I)) represents black and the intensity intmax(class(I)) represents white. (c) RGB Image OR True Color Image A truecolor image is an image in which each pixel is specified by three values one each for the red, blue, and green components of the pixel's color. MATLAB store truecolor images as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. Truecolor images do not use a colormap. The color of each pixel is determined by the combination of the red, green, and blue intensities stored in each color plane at the pixel's location. Graphics file formats store truecolor images as 24-bit images, where the red, green, and blue components are 8 bits each. This yields a potential of 16 million colors. The precision with which a real-life image can be replicated has led to the commonly used term true color image. A true color array can be of class uint8, uint16, single, or double. In a true color array of class single or double, each color component is a value between 0 and 1. A pixel whose color components are (0,0,0) is displayed as black, and a pixel whose color components are (1,1,1) is displayed as white. The three color components for each pixel are stored along the third dimension of the data array. For example, the red, green, and blue color components of the pixel (10,5) are stored in RGB(10,5,1), RGB(10,5,2), and RGB(10,5,3), respectively. (d) Intensity Image An intensity image is a data matrix, I, whose values represent intensities within some range. An intensity image is represented as a single matrix, with each element of the matrix corresponding to one image pixel. The matrix can be of class double, uint8, or uint16. While intensity images are rarely saved with a color map, a color map is still used to display them. In essence, handles intensity images are treated as indexed images. Intensity images contain pixel values that range between the minimum and maximum values supported by their data type. Question 8: Consider the 2x2 image shown below. Draw the new image if the original image is zoomed 1.5 times along both rows and columns (i.e. to size 3x3) using: (a) Nearest Neighborhood (b) Bilinear Interpolation 24 68 Ans a. 244 688 688 b. 234 456 678

Question 9: Consider the 3x3 image shown below. Draw the new image if the original image is zoomed 2 times along both rows and columns (i.e. to size 6x6) using: (a) Pixel Replication (b) Nearest Neighborhood 246 468 246 Ans. a. 2 2 4 4 6 6 224466 446688 446688 224466 224466 b. (1/2 , 1/2) (1/2 , 2/2) (1/2 , 3/2) (1/2 , 4/2) (1/2 , 5/2) (1/2 , 6/2) (2/2 , 1/2) (2/2 , 2/2) (2/2 , 3/2) (2/2 , 4/2) (2/2 , 5/2) (2/2 , 6/2) (3/2 , 1/2) (3/2 , 2/2) (3/2 , 3/2) (3/2 , 4/2) (3/2 , 5/2) (3/2 , 6/2) (4/2 , 1/2) (4/2 , 2/2) (4/2 , 3/2) (4/2 , 4/2) (4/2 , 5/2) (4/2 , 6/2) (5/2 , 1/2) (5/2 , 2/2) (5/2 , 3/2) (5/2 , 4/2) (5/2 , 5/2) (5/2 , 6/2) (6/2 , 1/2) (6/2 , 2/2) (6/2 , 3/2) (6/2 , 4/2) (6/2 , 5/2) (6/2 , 6/2) = (0.5,0.5) (0.5,0.5) (0.5,1.5) (0.5,2) (0.5,2.5) (0.5,3) (1,0.5) (1,1) (1,1.5) (1,2) (1,2.5) (1,3) (1.5,0.5) (1.5,1) (1.5,1.5) (1.5, 2) (1.5,2.5) (1.5,3) (2,0.5) (2,1) (2,1.5) (2,2) (2,2.5) (2,3) (2.5,0.5) (2.5,1) (2.5, 1.5) (2.5,2) (2.5,2.5) (2.5,3) (3,0.5) (3,1) (3,1.5) (3,2) (3,2.5) (3,3) = (1,1) (1,1) (1,2) (1,2) (1,3) (1,3) (1,1) (1,1) (1,2) (1,2) (1,3) (1,3) (2,1) (2,1) (2,2) (2,2) (2,3) (2,3) (2,1) (2,1) (2,2) (2,2) (2,3) (2,3) (3,1) (3,1) (3,2) (3,2) (3,3) (3,3) (3,1) (3,1) (3,2) (3,2) (3,3) (3,3) = 224466 224466 446688 446688 224466 224466 Question 10: An image has a total of 8 gray levels ranging from 0 to 7. (a) Find a square root transformation function for this image and draw it. Both x and y axes range from 0 to 7. First scale gray level range 0 7 to range 0 1, then take square root of each scaled gray level to find transformed gray level in range 0 1 and finally up-scale to range 0 7. Ans. 07 01 sqrt(01)

07 0000 1 0.142857 0.377964 2.645751 2 0.285714 0.534522 3.741657 3 0.428571 0.654654 4.582576 4 0.571429 0.755929 5.291503 5 0.714286 0.845154 5.91608 6 0.857143 0.92582 6.480741 7117 (b) Apply the above transformation to the following image and show the new image. 000 135 777 Ans. 000 2.6 4.5 5.9 777 Question 11: Consider the image shown below. The image has a total of 8 gray levels ranging from 0 7. Draw the histogram of this image. 01267 25350 23560 15324 47621 Ans. All grayscales intensity values are, x = [0 1 2 3 4 5 6 7] Frequency of each grayscale intensity, y = [3 3 5 3 2 4 6 2] Plotting frequency of each pixels grayscale intensity value, we get the following bar chart 01234567 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 Grayscale intensities of pixels, x Frequency of grayscale intensity, y Question 12: Consider the image shown below. The image originally had 16 gray levels but only 4 gray levels in middle of the entire colors range were used. Use contrast stretching (slide 26 of chapter 3) to improve contrast of this image to the entire range of 16 gray levels (0 15) 68 10 12 Ans.

For 16 gray levels (4-bit) images the lower and upper limits might be lowerlimit = 0 and upperlim = 15. And the lowest and highest pixel values currently present in the image are Rmin = 6 and Rmax = 12 respectively. Therefor, using following formula we can stretch the contrast of the given image PixOut = (PixIn Rmin) * ((upperlim lowerlimit)/ (Rmax Rmin)) + lowerlimit For pixel value 6 the new value will be: PixOut = (6 6)(( 15 0)/( 12 6)) + 0 = 0 For pixel value 8 the new value will be: PixOut = (8 6)(( 15 0)/( 12 6)) + 0 = 5 For pixel value 10 the new value will be: PixOut = (10 6)(( 15 0)/( 12 6)) + 0 = 10 For pixel value 12 the new value will be: PixOut = (12 6)(( 15 0)/( 12 6)) + 0 = 15 After applying contrast stretching upon given image the resultant image becom 05 10 15 Question 13: Consider the 16 gray levels (0 -15) image shown below. We want to do histogram equalization of this image. (a) Find and draw the histogram equalization transformation function for this image. (b) Find the histogram equalized image. 1122 2222 8 8 10 12 12 14 14 14 Ans. N=16 L=16 Gray Level nk(frequency) nk/N cdf (L1)*cdf new gray level 000000 1 2 0.125 0.125 1.875 2 2 6 0.375 0.5 7.5 8 3 0 0 0.5 7.5 8 4 0 0 0.5 7.5 8 5 0 0 0.5 7.5 8 6 0 0 0.5 7.5 8 7 0 0 0.5 7.5 8 8 2 0.125 0.625 9.375 9 9 0 0 0.625 9.375 9 10 1 0.0625 0.6875 10.3125 10 11 0 0 0.6875 10.3125 10 12 2 0.125 0.8125 12.1875 12 13 0 0 0.8125 12.1875 12 14 3 0.1875 1 15 15 15 0 0 1 15 15 The Required Equalized Matrix: 2288 8888 9 9 10 12 12 15 15 15

Question 14: Consider the 256 gray levels (0 - 255) image shown below. Run a 3x3 Min Filter on whole image and write the resulting output image. There is no need to run mask on edges. 10 10 10 10 10 50 10 10 10 10 10 10 10 100 10 10 10 10 10 10 10 10 210 10 10 Ans. Question 15: Consider the 256 gray levels (0 - 255) image shown below. Run a 3x3 Median Filter on Central Pixel with gray level 40 ONLY (Central Pixel) and tell the gray level that must be used for this location in the output image. Note again that you have to run the filter only once by placing it at the central pixel. 10 10 10 10 10 10 10 12 14 10 10 10 10 10 10 50 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 210 10 10 10 12 40 12 10 10 10 12 12 10 10 10 10 10 10 Ans. 10 10 10 10 10 10 10 12 14 10 10 12 12 12 10 10 10 12 12 10 10 10 10 10 10 Question 16: For the image of Question 15 above, run a box filter on Central pixel and find out the gray level that must be used for this location in the output image. Note again that you have to run the filter only once by placing it at the central pixel. Ans. 10 10 10 10 10 10 10 12 14 10 10 12 15 12 10 10 10 12 12 10 10 10 10 10 10 Question 17: In no more than 10 lines, explain the difference between point operations, local operations and global operations used for image enhancement in spatial domain. Ans. In image enhancement, point operation takes a single input pixel and result is always a single output. It considers each pixel value. In point operation only concentration is on a pixel. Point operation does not consider neighboring pixels informations. Global operation is applying on a complete image. Image enhancement is performed on the entire image. Local operation is known as local window. This operation can be overlapping or no overlapping. In this we consider the neighboring elements and output is also depending on input and input neighboring pixels. Local operation is used for enhancement of some specific portion of image.