Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Programming: Problem 4. Fade to Black and White The animation-transition.py program discussed in class (Module 7) and posted on the Module 7 Canvas page
Python Programming:
Problem 4. Fade to Black and White The animation-transition.py program discussed in class (Module 7) and posted on the Module 7 Canvas page animates a smooth transition from one image to another and back. Modify that program so that it displays an animation of a transition from the original color image to its black-and-white (B/W) version and back to original. An animation video of that transition is posted on the homework 5 page to give you the idea of how it should look like CAUTION: To get any credit do not corners, such as calling np.imread with a grayscale option, or generating a B/W version of the color image and then using that as image 2 with no changes to the code. It's silly, but students do this sort of thing and hope to get a good grade. Follow the requirements exactly or expect a low grade Requirements: a) Write a function convert bw(img) that takes an image ndarray with shape (height,width,3) and dtype np.uint8 and returns the B/W (actually, grayscale) version of that image, also with shape (height,width,3) and the same dtype The color image pixel is represented by a shape (3,) array of np.uint8 integers: [red, green, blue], where these numbers are in the range 0, 1, 2,..., 255. A color with equal values for red, green, and blue is a grayscale color. Use this simple conversion of a pixel from [r,g,b] to B/W: the B/W pixel color is the average of the r, g, b values. So, for each pixel [r,g,b] in the original color image we compute the B/W image pixel [a, a, a] where a is the np.uint8 average of the red, green, and blue values. Understand that we represent a B/W image with pixels that have all values for its colors (i.e. red, green, and blue) equal to the average of red, green, and blue. It's worth repeating that to avoid confusion. Hence, the B/W image will have the same shape (height, width, 3) as the original color image Problem 4. Fade to Black and White The animation-transition.py program discussed in class (Module 7) and posted on the Module 7 Canvas page animates a smooth transition from one image to another and back. Modify that program so that it displays an animation of a transition from the original color image to its black-and-white (B/W) version and back to original. An animation video of that transition is posted on the homework 5 page to give you the idea of how it should look like CAUTION: To get any credit do not corners, such as calling np.imread with a grayscale option, or generating a B/W version of the color image and then using that as image 2 with no changes to the code. It's silly, but students do this sort of thing and hope to get a good grade. Follow the requirements exactly or expect a low grade Requirements: a) Write a function convert bw(img) that takes an image ndarray with shape (height,width,3) and dtype np.uint8 and returns the B/W (actually, grayscale) version of that image, also with shape (height,width,3) and the same dtype The color image pixel is represented by a shape (3,) array of np.uint8 integers: [red, green, blue], where these numbers are in the range 0, 1, 2,..., 255. A color with equal values for red, green, and blue is a grayscale color. Use this simple conversion of a pixel from [r,g,b] to B/W: the B/W pixel color is the average of the r, g, b values. So, for each pixel [r,g,b] in the original color image we compute the B/W image pixel [a, a, a] where a is the np.uint8 average of the red, green, and blue values. Understand that we represent a B/W image with pixels that have all values for its colors (i.e. red, green, and blue) equal to the average of red, green, and blue. It's worth repeating that to avoid confusion. Hence, the B/W image will have the same shape (height, width, 3) as the original color imageStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started