Modify that program so that it displays an animation of a transition from the original color...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 7 page to give you the idea of how it should look like. CAUTION: To get any credit do not cut 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. Follow the requirements or expect a low grade. Details: 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. We use a trivial 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. The convert_bw function MUST use broadcasting and numpy's functions to compute the B/W 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 (h,w) B/W array to a (h,w,3) array, where in the latter all elements along the 3rd axis are repeated 3 times. One can use the np.dstack() function to stack arrays on the 3rd dimension, or the np.newaxis object, as in arr[:,:, np.newaxis], to create an array with a new axis (dimension), or reshape. Look these up. b) Modify the image_gen() function so that it takes just one image file name and the steps as parameters and then it uses the B/W version of the original image to yield ndarray objects that are intermediate images between the color version and the B/W 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 B/W. 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 7 page to give you the idea of how it should look like. CAUTION: To get any credit do not cut 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. Follow the requirements or expect a low grade. Details: 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. We use a trivial 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. The convert_bw function MUST use broadcasting and numpy's functions to compute the B/W 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 (h,w) B/W array to a (h,w,3) array, where in the latter all elements along the 3rd axis are repeated 3 times. One can use the np.dstack() function to stack arrays on the 3rd dimension, or the np.newaxis object, as in arr[:,:, np.newaxis], to create an array with a new axis (dimension), or reshape. Look these up. b) Modify the image_gen() function so that it takes just one image file name and the steps as parameters and then it uses the B/W version of the original image to yield ndarray objects that are intermediate images between the color version and the B/W 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 B/W.
Expert Answer:
Answer rating: 100% (QA)
Solution To achieve the requested functionality youll need to make some modifications to your Python ... View the full answer
Related Book For
Operating Systems Internals And Design Principles
ISBN: 9781292214290
9th Global Edition
Authors: Stallings William
Posted Date:
Students also viewed these programming questions
-
1. What is a data structure? 2. Why do we need data structures? 3. List some common data structures. 4. How data structures are classified? 5. Differentiate linear and non-linear data structure.
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
After its move in 1990 to La Junta, Colorado, and its new initiatives, the DeBourgh Manufacturing Company began an upward climb of record sales. Suppose the figures shown here are the DeBourgh...
-
The rectangular member OAB, shown in the figure, is held horizontal by the round hooked bar AC. The modulus of elasticity of both parts is 10 Mpsi. Use superposition to find the deflection at B due...
-
On April 1, Holly Dahl established Holiday Travel Agency Ltd. The following transactions were completed during the month. 1. Shareholders invested 12,000 cash in the business in exchange for ordinary...
-
During a tension test, the wooden specimen is subjected to an average normal stress of 2 ksi. Determine the axial force P applied to the specimen. Also, find the average shear stress developed along...
-
On June 30, the end of the first month of operations, Volker Energy Company prepared the following income statement, based on the absorption costing concept: If the fixed manufacturing costs were...
-
How does the use of dynamic process simulation differ from steady-state simulation, particularly in terms of modeling process transients and evaluating system robustness to disturbances ?
-
8 91426 10 11 (CCM) builds furniture for a range of commercial customers. They build furniture used in hotels and department stores, on cruise liners, ferries and passenger aircraft. One of their...
-
A vertical ellipse has its vertices at (2,9) and (2,1) and touch point (0.4,2.6). Find the centre of this ellipse. Hence, write the equation of this ellipse in standard form and state the foci of...
-
Bramble Corporation issues $570,000 of 9% bonds, due in 11 years, with interest payable semiannually. At the time of issue, the market rate for such bonds is 10%. Click here to view factor tables....
-
Retirement pension plans, also called "defined benefits" plans, traditionally are set as a fixed income per year at retirement. What are some characteristics of a pension plan? Select all that apply:...
-
Crane Company reported the following selected information at March 3 1 . 2 0 2 2 Total current assets $ 2 2 7 , 1 5 0 Total assets 4 3 8 , 0 0 0 Total current liabilities 2 9 5 , 0 0 0 Total...
-
Hillary Corporation has its own cafeteria with the following annual costs:Food$200,000 Labour150.000 Overhead220,000 Total$575.000 The overhead is 40% fixed. Of the fixed overhead, $50,000 is the...
-
On January 1, 2025, ABC Company, a calendar-year company, issued $2,000,000 of notes payable, of which $500,000 is due on January 1 for each of the next four years. What is the proper balance sheet...
-
Consider a spinless particle of mass m bound by a one-dimensional harmonic potential of spring constant k (equivalently, we can say that the natural frequency of the oscillator is an = k/m). Suppose...
-
To help you become familiar with the accounting standards, this case is designed to take you to the FASBs Web site and have you access various publications. Access the FASBs Web site at...
-
Consider a variation of the dining philosophers problem where the number of philosophers is even. Can you devise a deadlock-free solution to the problem? Assume that all other requirements are like...
-
What is starvation with respect to concurrency control by mutual exclusion?
-
Describe the round-robin scheduling technique.
-
Home Inc. (a US company) has a wholly-owned subsidiary, S, which it acquired on 1 January X0. The balance sheets of S as at 1 January X0 and 31 December X0 are as set out in Figure 15.1 in foreign...
-
An entitys functional currency is: A. The currency of its parents country. B. The currency of its own country. C. The currency in which the financial statements are presented. D. The currency of the...
-
Entity X based in one country (currency $) bought goods from Entity Y in another country (currency :) for :300,000 on 1 May 20X1. The spot rate on that date was $1 = :1. As at 31 December 20X1, the...
Study smarter with the SolutionInn App