Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Requirement
You can do this assignment in a Python .py file or in a Jupyter Notebook. Recall that if you run into problems with code in a Jupyter Notebook, the best thing would be to try to debug that code in PyCharm (even if you want to copy it back to a Jupyter Notebook).
Q1
For this question, perform some basic operations on an image that I have loaded onto Brightspace (nashville.jpg).
(a) Read in nashville.jpg, display it, and convert it from RGB to grayscale using the following formula to convert from red, green, and blue values to grayscale intensity:
intensity = 0.2989*red + 0.5870*green + 0.1140*blue
Save the image as a jpg file called nashvillegray.jpg, read it back in, and display it. You will use this grayscale version in the remaining parts below.
(b) Create a scrambled version of the grayscale image nashvillegray.jpg. Imagine dividing the image into an 8x8 grid. Create a scrambled version of the image where each of the sections in the 8x8 grid is randomly shuffled (a permutation). An example of the grayscale version and one possible scrambled version is shown below. We discussed a way to accomplish this scrambling in class.
Your code should read in the image into a numpy array. Create a function that takes this numpy array as an argument and takes the number of ways to slice the image (for example 8 to create an 8x8 grid) and returns a numpy array containing the scrambled image. Your code should display the scrambled image. Aside from using a built in permutation function and other non-image-processing functions in Python, the scrambling of the image should be done by your code (in other words, do not search for any built-in image/signal processing functions or existing packages that might do this scrambling for). Please try to write your code so that you can change the “8” in the 8x8 grid to some other value, like a 4x4 grid, or a 64x64 grid; you can assume that the number is chosen to equally divide the image size. Save the resulting scrambled image to a jpg file.
(c) Add “noise” to an image (in this case nashvillegray.jpg). Your code should read in the image into a numpy array, that numpy array should be passed to a function that adds the noise, with the noise specified by other arguments passed to the function.
The noise should be normally distributed with mean 0 and standard deviation sigma. This “noise” is added to the intensity (brightness) of each pixel in the image. This kind of noise is what sometimes called “salt and pepper noise”, whereby the intensity of each image pixel is jiggled up or down by a normally distributed random number.
When you add noise, allow for two options (as an optional argument in your function): one version where added noise that would cause a pixel value to go above 255 is capped at 255 go below 0 is capped at 0, and another version where noise is allowed to jump from 255 to 0 or from 0 to 255 when you cast as an uint8. Your code should show what happens (displaying two images) to illustrate the two ways of manipulating noise (and capping vs. rolling over at the extremes).
Your function should return a numpy array as uint8.
For each version, create one image and save it with a low but perceptible level of noise and create another image and save it with a relatively high level of noise; you will be saving four images.
Q2
We talked about using the Laplacian of Gaussians filter to find edges in images. For this question, I would like you to explore the Laplacian, the Gaussian, and the Laplacian of Gaussians (LoG). This question uses the convolution computations we talked about in class and illustrated in the posted Jupyter Notebooks from class.
For this assignment, read in and use nashvillegray.jpg from above, but your code should work for any image that is read in.