Picture mirror JYTHON program help Need the code to be writt

Picture mirror JYTHON program help.

Need the code to be written in jython for this project.

In the textbook, you have seen how vertical, horizontal and diagonal mirrors can be placed on an image to get a part of the image mirrored. In this assignment you will create a function named arbitraryMirror() that allows the user to place a mirror at an arbitrary angle as shown in the examples below:

In the following examples, the user has specified the start and end coordinates of the mirroring line shown in green. The line is shown for illustration purposes only and must not be there in your output.

Restrictions: The user must be allowed to choose the start and end points of the mirror (line) along the edges of the image. If the user enters any other coordinates, they must be prompted to re-enter. Your code must work with an image of rectangular and square images of any valid size.

again, code must be in JYTHON.

Solution

def arbitraryMirror(picture):

file = pickAFile()

pic = makePicture(file)

print “Enter pixel values (x0,y0)”

x=x0

y=y0

pixel1 = getPixel(pic, x, y)
print \"x0-value:\", x0
print \"y0-value:\", y0

print \"The value of the pixel at (x0, y0) is: \", pixel1

print “Enter pixel values (x1,y1)”

x=x1

y=y1

pixel2 = getPixel(pic, x, y)

print \"x1-value:\", x1
print \"y1-value:\", y1

h = getHeight(pic)

    w = getWidth(pic)

    if (height != width):

        printNow(\"Error: The input image is not squared. Found [\" + \\

                                     str(width) + \" x \" + str(height) + \"] !\")

        return None

# (x0, y0) and (x1, y1) are two points on the mirroring line

# dx, dy, L is the vector and length

dx = x1 - x0

dy= y1 - y0

L = (dx**2 + dy**2) ** 0.5

# Tangent (tx, ty) and normal (nx, ny) basis unit vectors

tx = dx / L

ty=dy / L

nx = -dy / L

ny=dx / L

# For each pixel

for y in range(h):

    for x in range(w):

        # Map to tangent/normal space

        n = (x+0.5 - x0)*nx + (y+0.5 - y0)*ny

        t = (x+0.5 - x0)*tx + (y+0.5 - y0)*ty

        # If we are in the positive half-space

        if n >= 0:

            # Compute mirrored point in XY space

           

            xx = int(x0 + t*tx - n*nx + 0.5)

            yy = int(y0 + t*ty - n*ny + 0.5)

            # If valid coordinates the copy to destination

# the mirroring is done by copying one pixel at a time from (xx, yy)to (x, y) which diplays the final image computed using the mirroring formula.

            if 0 <= xx < w and 0 <= yy < h:

                img[y][x] = img[yy][xx]

              #image has been flipped

Picture mirror JYTHON program help. Need the code to be written in jython for this project. In the textbook, you have seen how vertical, horizontal and diagonal
Picture mirror JYTHON program help. Need the code to be written in jython for this project. In the textbook, you have seen how vertical, horizontal and diagonal

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site