Question: Problem 5 . Write a function that accepts the name of an image file and an integer s . Use your function from Problem 3
Problem Write a function that accepts the name of an image file and an integer Use
your function from Problem to compute the best ranks approximation of the image. Plot
the original image and the approximation in separate subplots. In the figure title, report the
difference in number of entries required to store the original image and the approximation use
pltsuptitle
Your function should be able to handle both grayscale and color images. Read the image
in and check its dimensions to see if it is color or not. Grayscale images can be approximated
directly since they are represented by dimensional arrays. For color images, let and
be the matrices for the red, green, and blue layers of the image, respectively. Calculate the low
rank approximations and separately, then put them together in a new dimensional
array of the same shape as the original image.
Hint: npdstack may be useful for putting the color layers back together.
Finally, it is possible for the lowrank approximations to have values slightly outside the
valid range of RGB values. Set any values outside of the interval to the closer of the two
boundary values.
Hint: fancy indexing or npclip may be useful here.
To check, compressing hubblegray.jpg with a rank approximation should appear
similar to Figure and save matrix entries.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
