程序代写代做代考 Homework 10 – Images

Homework 10 – Images
Notice
This homework requires you to create images, which can be difficult to check using isequal​. To mitigate this, we have given you a function called ​checkImage that will compare two images. Use this to compare the image file that your code outputs with the image file that the solution code outputs. You can look at ​help checkImage​ to see how to use the function.
Remove all uses of ​imshow() in the code that you submit. You are encouraged to use it to debug, but you must remove it before submission. Any code that uses a function that displays the image in a window, such as ​imshow() ​or ​image()​, will automatically receive zero points.
All output images should be saved as ​.png​ images.
Happy coding! ~Homework Team

Homework 10 – Images
Function Name: ​Better4DataAnalysis
Inputs:
1. (​char​) The filename of the first (earlier) image
2. (char) ​The filename of the second (later) image
3. (uint8) A​ vector of R, G, B values that is a cutoff for a green leaf color.
Outputs:
1. (​char​) A string describing how your plant changed over the past week
Background:
We’ve learned even more MATLAB this past week, and our garden is still changing! Some plants have grown great! Others . . . well . . . the deer did a bit of damage. We’re going to analyze pictures from 2 points in time to see how our plant has changed!
Function Description:
Take in two pictures – the first from an earlier point in time, and the second from the current point in time. A pixel will be considered a green leaf color if:
1. It’s red and blue values are less than or equal to the values at the first and third indices, respectively, of the vector given by the third input of the function
AND
2. It’s green value is greater than or equal to the value at the second index of the vector given by the second input of the function.
Find the total number of green leaf color pixels in the first image and the total number of
green leaf color pixels in the second image. Calculate the percent change from the total number of green leaf color pixels in the first image to the total number of green leaf color pixels in the second image. Round the percent change to the nearest integer.
If the percent change is positive, your output string should be:
‘Yay! My plant grew by percent!’
If the percent change is negative or zero, your output string should be:
‘Uh oh, the deer ate percent of my plant!’

Example:
‘greenBeans.png’ =>
Homework 10 – Images
‘greenBeansEaten.png’ =>

Homework 10 – Images
fn1 = ‘greenBeans.png’;
fn2 = ‘greenBeansEaten.png’
vec = [220, 110, 200]
Out = Better4DataAnalysis(fn1,fn2, vec)
Out => ‘Uh oh, the deer ate 43 percent of my plant!’
Notes:
● Percent change is calculated as:
(value2 – value1) / (value1) * 100
Hints:
● If you ever grow a garden, make sure to keep it covered with netting at all times!

Homework 10 – Images
Function Name: ​Better5DataAnalysis
Inputs:
1. (​char​) The filename of image 1
2. (char) ​The filename of image 2
Outputs:
1. (​double​) The average distance between the grayscaled pixels in image 1 and image 2
Background:
We can’t get enough of gardening and MATLAB this week, so we’re now going to compare pictures of our plants to see how similar (or different) they are!
Function Description:
Open the first image and second image. Resize the second image to be the same size as the first image. We don’t want to compare the coloring of the plants, so find the grayscaled values of both images.
To calculate the distance between two grayscale values, use the formula:
distance = |(valueA – valueB)|
Calculate the distances between all corresponding grayscale values in image 1 and image 2, then take the average of all of these distances. Round the average distance to three decimal places.

Example:
‘greenBeans.png’ =>
Homework 10 – Images
‘greenBeansEaten.png’ =>

Homework 10 – Images
fn1 = ‘greenBeans.png’;
fn2 = ‘greenBeansEaten.png’ Out = Better5Data(fn1, fn2) Out => 55.594
Notes:
● Pixels are corresponding when they have the same row and column index
● There’s no need to concatenate the grayscaled values into 3 layers — one layer is all you
need for the calculations.

Homework 10 – Images
Function Name: ​summerBreak
Inputs:
1. (​char​) filename of an image of you
2. (​char​) filename of a background image
File Outputs:
1. Image file with ​’_vacation’​ appended after the background image’s filename.
Background:
You are still bummed out that you had to cancel your Summer Break plans. Your Instagram account desperately needs new content, so you decide to make your own vacation pictures. You turn to MATLAB for help.
Function Description:
You are given a background image with one of the quadrants colored pure green. The entire quadrant will be pure green. Create a mask that finds the pure green quadrant in the background image.Then, replace the pure green quadrant with the image of you; however, the image of you may have a different number of rows and columns as the green quadrant. You will need to resize the image of you to fit into the green quadrant. Finally, make the image grayscale and write it to the output file.
Notes:
● The pure green color will only be found in the designated area​.
● A quadrant is defined as half the rows and half the columns of an array, in either the top
left, top right, bottom left, or bottom right.
● The background image will have an even number of rows and columns, so there is no
confusion when rounding to find the quadrant.
● When creating the greyscale image, make three layers of the output of ​rgb2gray to
write to the image file.
(​continued…​)

Homework 10 – Images
Example:
you = ‘familyPic.png’ ​ ​bkgd = ‘hawaii.png’
*Border of ​familyPic.png​ shown for clarity purposes
summerBreak(you, bkgd) → ‘hawaii_vacation.png’

Homework 10 – Images
Function Name: ​noGlasses Inputs:
1. (​char​) The filename of an image File Outputs:
1. The new image after blurring it
Banned Functions:
imgaussfilt, conv2
Background:
As someone who wears glasses, I personally hate it when people who don’t wear glasses just assume that I straight up don’t see certain things without my glasses. The amount of times where I had my glasses off and someone put some fingers up and asked me how many fingers I thought they had up is way too high! In this problem you will use MATLAB to blur an image, so that those of you who don’t wear glasses can see what I see without glasses, and those of you who do can show their friends who don’t.
Function Description:
One way to blur images is to replace each center pixel (a pixel that is in the center of a 3×3 array) in each of the layers of the image with the average of all the 9 pixels surrounding it, including itself. For example, if the ​unit8 array from one of the layers of a certain image was the following 3×3 array, it would be modified as follows:
30 30 30
90 ​90​ 90 -> 60 60 60
** ** ** ** ​60​ ** ** ** **
To blur an entire image, follow the following steps:
1. Determine the size of the array of the output image (it will be smaller than the array of
the input image as we have to ignore the first and last row and column in each layer since there are not enough numbers surrounding them) and create an empty array with the required size.
2. Iteratively index out each center pixel in each layer in the input image array, and use those indices to index out each unique 3×3 piece from the array.
3. Find the average of the values in that 3×3 piece and round it to the nearest whole number. This will be your new pixel value that you will use to populate the empty array you created in step 1.
Write your final output array to an image with the name of the original image with ​‘noGlasses_’ appended to the beginning of it.
[continued on the next page…]

Homework 10 – Images
Example:
noGlasses(‘spongeBOB.png’)
>> spongeBOB.png >> noGlasses_spongeBOB.png
Notes:
● When iterating through the pixels, make sure you do that for each layer individually as it cannot be done for all layers at once.
● Consider converting the array of the input image from ​uint8 to ​double before performing any mathematical operations on it.
● Do not overwrite numbers in the array of the original image as they might be used more than once to calculate pixel values, instead follow the steps in the function description.