Question: Problem 1 . Fade to Black and White Here the file namess you will use for the code are florida - keys - 8 0
Problem Fade to Black and White Here the file namess you will use for the code are floridakeysjpgDownload floridakeysjpg
GrandTetonjpg code in python
The animationtransition.py program discussed in class and posted on the
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
blackandwhite BW version and back to original. An animation video of that transition is posted on
the homework page to give you the idea of how it should look like.
CAUTION: To get any credit do not cut corners, such as calling npimread with a grayscale option, or
generating a BW version of the color image and then using that as image with no changes to the
code. Follow the requirements or expect a low grade.
Details:
a Write a function convertbwimg that takes an image ndarray with shape heightwidth, and
dtype npuint and returns the BW actually grayscale version of that image, also with shape
heightwidth, and the same dtype.
The color image pixel is represented by a shape array of npuint integers: red green, blue where
these numbers are in the range A color with equal values for red, green, and blue is a
grayscale color.
We use a trivial conversion of a pixel from rgb to BW: the BW pixel color is the average of the r g
b values. So for each pixel rgb in the original color image we compute the BW image pixel a a a
where a is the npuint average of the red, green, and blue values.
Understand that we represent a BW image with pixels that have all values for its colors ie red, green,
and blue equal to the average of red, green, and blue. Its worth repeating that to avoid confusion.
Hence, the BW image will have the same shape height width, as the original color image.
The convertbw function MUST use broadcasting and numpys functions to compute the BW
image. Do NOT use nested for loops to compute the average for each individual pixel. If any loop is
used in this function, no credit is given for part a
HINTS: the tricky part is converting from a hw BW array to a hw array, where in the latter all
elements along the rd axis are repeated times. One can use the npdstack function to stack arrays
on the rd dimension, or the npnewaxis object, as in arr:: npnewaxis to create an array with a new
axis dimension or reshape. Look these up
b Modify the imagegen function so that it takes just one image file name and the steps as
parameters and then it uses the BW version of the original image to yield ndarray objects that are
intermediate images between the color version and the BW version, just like in the original py file.
c Modify the remainder of the program accordingly in order to animate image transition from color to
BW
Insert the Python file into the hdoc file.
No screenshot is needed.
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
