Question: Useing Jython Environment for Students (JES), Version 5.0 Please but pic for the Inputs and the outputs. Two of the most common operations to perform
Useing Jython Environment for Students (JES), Version 5.0
Please but pic for the Inputs and the outputs.
Two of the most common operations to perform on an image are horizontal and vertical flips, which involve spinning the image around the opposing axis. For this lab we will perform a horizontal flip, an example of which is below. You can see that Lenas image was rotated about the vertical axis that runs at the midway point of the image.
Now, how to achieve this effect? Take a moment to think about how you would try to solve it.
Tracking pixels
Another way to think of it is that the pixels are mirrored through the central axis, which leads to a possible described here. Think of the image as being split into halves. Lets consider a simple 4x4 picture to the right; the pixels are colored randomly and have numbers assigned to them. The number labels represent the pairs of pixels in opposite halves that you will have to swap their colors. So, if you look at the two pixels labeled A, after your program runs the left A should be green and the right one red. This is why I said we can think of the flip as a mirror through the central axis. The real question is how do I access the correct pixels? Take advantage of the mirroring: if you get a pixel in one half (say the left) then you should be able to figure out the coordinates for the corresponding one in the other half. The red A is at (0,0) and the green A is at (3, 0), which is (width-1, 0). The Bs will be (1,0) and (2,0). As you can see, the y-values never change, but the x-values do. So, what is the relationship between x-values on the left and right side? Try to write the right B coordinates of (2,0) as an arithmetic expression using the width and x-coordinate of the left pixel, sort of like I did with turning (3,0) into (width-1, 0). Trying this on a larger image, say 6x6, may make the relationship more obvious. Figure it out and you are most of the way to a solution since you will now have a formula for getting the right-side pixel based on the lefts coordinates. To code it, you will begin with a loop (hint: nested for loop). Orient this loop's x and y ranges around getting pixels in the left half of the image. Inside, you will need to get two different pixels: the related ones in each half of the picture. Once you know the pixels, you then will swap (use the pattern we learned about) their colors and viola you have a horizontally flipped image.
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
Get step-by-step solutions from verified subject matter experts
