Homework 7 – Image Processing (Gray scale image and blurring image)


• Write a program that contain at least two functions.

• The first function is called grayscale(image). This function takes an image and return a grayscale (black and white) version of the image. When all three RGB channel have the same value, you get a shade of gray image. You can take the three-color channels and combine them to get a value that we called luminance for that particular pixel. One way to do this is by taking the average of the three channels.

• The second function is called lpfilter(image). This function takes an image and return an image that has passed through a low pass filer version of the original image. Low pass filtered image is a blurred version of the original image.

• The function lpfilter(image) should do the following:

o Step 1: Convert image to a gray scale image (See below)

o Step 2: Pass though this gray scale image through the low pass filter. You should ignore the outermost row and column of the image when do this operation. Change the outermost row and column as value zero.

o Step 3: Return the low-pass filtered image


There are many ways to do the low pass filtering of an image. We will use something called convolution kernel. A kernel is a small array that show the pixel’s filtered as determined by it’s neighbors. This is an averaging adjacent pixels value.

Try the following 3x3 kernel:


+1/9 +1/9 +1/9

+1/9 +1/9 +1/9

+1/9 +1/9 +1/9


img(x-1.y-1) img(x-1.y)    img(x-1.y+1)

img(x.y-1)         img(x.y)    img(x.y+1)

img(x+1.y-1) img(x+1.y)   img(x+1.y+1)


For example, the center pixel (red) is the pixel we are operating on. Its new value will be replaced by the sum of its eight neighbors by 1/9. To avoid having to deal with the edges of the image, assume we will ignore the outer row and column (normally we will add padding to the image to take care of the cases in the rim).


The New value of img(x, y) = 1/9[img(x-1.y-1)+ img(x-1.y)+ img(x- 1.y+1)+ img(x.y-1)+ img(x.y)+ img(x.y+1)+ img(x+1.y-1)+ img(x+1.y)+ img(x+1.y+1)]


See this webpage for more information on low pass filer https://diffractionlimited.com/help/maximdl/Low-Pass_Filtering.htm


• In the main program, you should

o include examples that show the operation of the function.

o use the time module to output the time it takes to run your program (in seconds, to 3 decimal places using the string format function


• If you submit HW7 and using a method other than the algorithm that was specified in the homework specification, you will receive zero marks for this assignment.

• Do not use other libraries to do this homework.  So, for example, do not use numPy. 


Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

© 2024 Codify Tutor. All rights reserved