Question: 5. (20%) A beginner MATLAB programmer wrote the code below to darken a grayscale image by reducing the intensity of each pixel by half. Please

 5. (20%) A beginner MATLAB programmer wrote the code below to

5. (20%) A beginner MATLAB programmer wrote the code below to darken a grayscale image by reducing the intensity of each pixel by half. Please retype and run their code and answer the following questions: a. Does the script work as expected? b. Will it still work if you remove the uint8 typecasting in line 3? Why (not)? c. What is the main problem with this code? Be specific! d. Rewrite the code to improve its efficiency while keeping it readable. Hint: vectorize for loops! e. Compare the performance of the original code against the modified version you wrote, using tic and toc. 1 2 3 4 5 6 7 8 9 10 I = imread('coins.png'); [height width] = size(I); J = uint8(zeros(size(I))); for i=1:height for j=1:width J(i,j) = 0.5* I(i,j); end end imshow(I) figure, imshow(J) 5. (20%) A beginner MATLAB programmer wrote the code below to darken a grayscale image by reducing the intensity of each pixel by half. Please retype and run their code and answer the following questions: a. Does the script work as expected? b. Will it still work if you remove the uint8 typecasting in line 3? Why (not)? c. What is the main problem with this code? Be specific! d. Rewrite the code to improve its efficiency while keeping it readable. Hint: vectorize for loops! e. Compare the performance of the original code against the modified version you wrote, using tic and toc. 1 2 3 4 5 6 7 8 9 10 I = imread('coins.png'); [height width] = size(I); J = uint8(zeros(size(I))); for i=1:height for j=1:width J(i,j) = 0.5* I(i,j); end end imshow(I) figure, imshow(J)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!