Lanah Marie and Katie Sclafani

Project 3

Project Description

Our project took a 2D image of a coin and warped and animated it in a way that makes it look like the object is spinning. With the code written, we could make any image spin in this fashion. We took this spinning image and “Seamlessly Cloned” it onto another image, making it a part of that scenery.

Purpose of Project

The purpose of our project is to create a fun tribute to the late CEO of Nintendo, Satoru Iwata. We also wanted to take advantage of our location in Barcelona. So, we combined the two and had a Mario themed output with a Barcelona background.

Original Pictures

Original Image Original Image Original Image

Spinning Coin animation

Spinning Coin

Complete Animation with Seamless Cloning

Final Image

Procedure

Our first input is a single 2D image. We used the points at the four corners of the image in order to “rotate” the photo with warping. First, we wrote a rotatePoint() function which took in an origin point’s x and y values, a theta by which to rotate the points, and a radius of how large this circle of rotation would be. We used the formula of a circle from there to see where the point would have to be moved in the rotation by multiplying the radius by the sine or cosine of whatever the theta value was and then adding or subtracting that value from either the origin’s x or y value. We then returned these x and y values of the new position of the point.

We then made the function rotateImage(), which actually takes in the entire 2D image. We used the rotatePoint() function on the four corners of the image a number of times, rotating them fully around an axis somewhere in the middle of the image. As the function gave us new point positions, we would store those values into a tuple and then put those tuples into an np.array. Using an array of the original points of the original image as well as this new array of new rotated points, we would find how much we would need to transform the image using getPerspectiveTransform() and then use this output to warp the image with warpPerspective(). We went through this process twenty-four times by using a for loop. Twenty-four turns of the image was enough to make it look like it was spinning a full 360 degrees. We accomplished this full rotation by updating an angle variable that served as the theta value. At each iteration, we added a fixed value to this angle variable, and the increasing value was what made the image “spin.”

In order to seamlessly clone a source image onto a destination image, we had to create a mask around the source image which would then be used to tell the function which part of the source image we wanted to be placed onto the destination image. Using the function cv2.seamlessClone(), the source image was overlaid onto the destination image with it looking as if it were part of the original image. The function does this combining the colors of the source image and the destination image at the point at which to place the source image. The function seamlessClone() takes in five parameters: the source image, the destination image, the mask, the point on the destination image where the center of the source image will be placed, and the type of clone. For this project, we used the MIXED_CLONE. This type of clone uses alpha blending to weave the source image into the destination image. We seamlessly cloned three coins and a picture of Mario and Luigi into a picture of Barcelonian buildings.

In the end, we took all of these images and animated them by putting them into an animated gif. We made this gif by using the images2gif.py (found at https://gist.github.com/jonschoning/7216290), inputting a list of the images.

Image Sources: bcn.jpg was taken by Katie Sclafani, mario.jpg was taken from: http://nintendo.wikia.com/wiki/File:Mario_luigi_jump.jpg, coin.jpg was taken from: http://my-mario-list.wikia.com/wiki/File:Coin.png