Question: Useing Jython Environment for Students (JES), Version 5.0 Please but pic for the Inputs and the outputs. For this assignment, you take two pictures of

Useing Jython Environment for Students (JES), Version 5.0

Please but pic for the Inputs and the outputs.

For this assignment, you take two pictures of the same width and height and blend them together in varying amounts as you go across the result picture. As you scan across the result from left to right, you will see the picture gradually fade from the left picture (summer) to that of the right (winter).

Lets think of the algorithm. You will need to construct a new image that is the same size as the two originals to hold the result of the mixing. The RGB values of each pixel in the new image are weighted averages of the RGB values of the pixels in the originals. For example, when you start out on the left side of the result image, the color of the pixel is 100% from the first image and 0% from the second image. As you move rightward the proportion will change gradually, so that when you get a quarter of the way across it will consist of 75% from the first image and 25% from the second image. In the middle of the image it will be 50%-50%. And so on. Remember that during this process you are looking at corresponding pixels so you will color pixel (58, 271) in the result based on the pixels that reside at the same coordinates in the originals. Generally: As you move across a row, x increases from 0 to w1 (where w is the width of the image) and the amount of the second image that gets mixed into the first would be given by:

mixingLevel = x / float(w-1)

mixingLevel will be a number between 0 and 1 and thus 1mixingLevel tells you how much of the color comes from the first image's pixel. So for example if r1 and r2 are the red levels from the two original pictures, then the red level at the corresponding pixel in the new image will be mixingLevel*r2 + (1mixingLevel)*r1 . Try it out on scratch paper with a tiny (5x5) image to make sure this makes sense.

The Algorithm

You are going to write this program as two functions: a main to "drive" the program along and gradientBlend that will take two pictures and return a new picture that is a blend of the two. Make sure to make use of Python code to deal with width and height, don't hardcode values like 400x400!

main:

Ask the user for two identically sized pictures.

Display the two pictures

If the two pictures are not of the same dimensions

Display an error message

Use return on a line by itself to exit the program immediately

Call gradientBlend, passing the two pictures and saving the returned picture

Display the result

gradientBlend (takes two parameters, both pictures):

Create a new empty picture sized the same as the parameter pictures

this picture will serve as the result image

Loop over the height (y values):

Loop over the width (x values):

Let the variable mixingLevel be x/float(w-1)

Get the pixels from the three pictures using x and y

Get the red values from the original images

Calculate new red value (discussed above)

Set the result image's red level

Do similar for the green and blue bands

Return the blended picture

Write the code in Jython and test your program. Remember to include comments in the code!

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!