Help with PYTHONJYTHON project With this project i need to b

Help with PYTHON/JYTHON project.

With this project i need to be able to mirror a picture diagonally, but from a start and end point set by a user.

The pics will show the previous/after effect for clarification.

Input pic

Now here is the out pics.

Now i understand the way to do where it mirrors on the x/y axis as shown below: (lines shown as clarification as well)

But with the \"swan\" pics, the start point is not the same as the bike.

Also, i need the program to accept square and rectangle images, but i believe this kind of thing can only be done with square pictures?

So to summarise:

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

Thank you.

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

Help with PYTHON/JYTHON project. With this project i need to be able to mirror a picture diagonally, but from a start and end point set by a user. The pics will
Help with PYTHON/JYTHON project. With this project i need to be able to mirror a picture diagonally, but from a start and end point set by a user. The pics will

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site