$30
All problems are to be solved using Python.
You should avoid using loops in your code unless you are explicitly permitted to do so.
Submit your homework electronically by following the two steps listed below:Upload a pdf file with your write-up on Gradescope. This should include your answers to each question and relevant code snippet. Make sure the report mentions your full name and PID. You must use the Gradescope page selection tool to indicate the relevant pages of your report for each problem; failure to do so may result in no points. Finally, carefully read and include the following sentences at the top of your report:
Reports missing any of the above elements may receive no credit.
Upload a zip file with all of your scripts and files on Gradescope. Name this file: ECE 253 hw1 lastname studentid.zip. This should include all files necessary to run your code out of the box.
Problem 1. Basics
3
4
Input A = 63
6
12
9
25
13
32
8
5
4
23
77
6
1 0
3 0
9 and B = 0
0 1
1 0
1
1
0
1
1
0
1
0
0
0
1
0
1 .
1
0
Point-wise multiply A with B and set it to C.
Calculate the inner product of the 2nd and 3rd row of C.
Find the minimum and maximum values and their corresponding row and column indices in matrix C. If there are multiple min/max values, you must list all their indices.
In your report include all the outputs generated by your code.
Problem 2. Simple image manipulation
Download any color image from the Internet or use one of the given images. Read this image and call it A.
Transform the color image to gray-scale. Verify the values are between 0 and 255. If not, please normalize your image from 0 to 255. Call this image B.
Add 15 to each value of image B. Set all pixel values greater than 255 to 255. Call this image C.
Flip image B along both the horizontal and vertical axis. Call this image D.
Calculate the median of all values in image B. Next, threshold image B by the median value you just calculated i.e. set all values greater than median to 0 and set all values less than or equal to the median to 1. Name this binary image E.
Include all images A-E in your report. Try to fit at least 4 images in a page.
Problem 3. Histograms
Histograms[1] are a great statistical tool to analyze the distribution of intensity values in an image. In this problem, you have to write a Python function with the following specifications:
Write a function named compute norm rgb histogram that computes the RGB color histogram.
Use 32 bins for each color channel (i.e. Red, Green and Blue), spaced equally between 0 and 255. This should result in a 32-length vector for each channel.
One input (RGB/color image) and one output (1 x 96 vector).
Normalize the histogram of each color channel (so that it sums to 1), then concatenate the three histograms together (in the order R, G, B) to make a combined histogram of length 3x32 = 96.
Do not use Python inbuilt histogram function. You may use loops if necessary.
Call the function and plot the final combined, normalized histogram for the image jpg. Make sure the plot is labeled correctly. Show your plot in the report.
Problem 4. Chroma Keying
Chroma keying is used for extracting the foreground from images, with the background typically being a green screen. In this problem, you have been provided 2 images: travolta.jpg and dog.jpg. Write a script to extract the foreground from either image and overlay the foreground on a different background of your choice. In your report you should include for each of the images:
A binary image showing the foreground mask, i.e., all foreground pixels set to 1 and all background pixels set to 0.
An image with the background pixels set to 0 and the foreground pixels set to their original values.
An image with the foreground overlayed on a background of your choice.
Problem 5. Upsampling and downsampling
Sampling is a technique that enables you to resize the image to desired resolution. Different interpolation techniques can be used for sampling. In this question, you will perform experiments on different interpolation methods for upsampling and downsampling (Hint: you can use resize function for both upsampling and downsampling).
List (and describe in a short paragraph) 3 interpolation methods.
Select 3 color images and downsample using the different methods with the 3 ratios below.
What differences do you observe? Which interpolation method do you think works best?
Dowsampling ratio: 0.3, 0.5, 0.7
Please include the images in the report. Crop small regions to compare if necessary. You should have 27 images (3 images ∗ 3 methods ∗ 3 ratios).
Repeat the previous step, but this time use upsampling with the ratios below. What differences do you observe? What interpolation method works best?Upsampling ratio: 1.5, 1.7, 2
Please include the images in the report. Crop small regions to compare if necessary.
Using 3 color images, downsample the images with scale 0.1 and upsample back to the original size, using all combinations of the three chosen interpolation methods. Which interpolation combination do you think works best to reconstruct the original image?
[1] You can read more about Histograms here.