{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 7 Image Stitching\n", "\n", "This section of the notebook continues the image stiching problem. Be sure to have a `figures` folder in the same directory as the notebook. The `figures` folder should contain the files:\n", "\n", " Berkeley_banner_1.jpg\n", " Berkeley_banner_2.jpg\n", " stacked_pieces.jpg\n", " lefthalfpic.jpg\n", " righthalfpic.jpg\n", " \n", "Note: This structure is present in the provided HW2 zip file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the next block of code before proceeding\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "tags": [ "worksheet-0" ] }, "outputs": [], "source": [ "import numpy as np\n", "import numpy.matlib\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import Axes3D\n", "from numpy import pi, cos, exp, sin\n", "import matplotlib.image as mpimg\n", "import matplotlib.transforms as mtransforms\n", "\n", "\n", "%matplotlib inline\n", "\n", "#loading images\n", "image1=mpimg.imread('figures/Berkeley_banner_1.jpg')\n", "image1=image1/255.0\n", "image2=mpimg.imread('figures/Berkeley_banner_2.jpg')\n", "image2=image2/255.0\n", "image_stack=mpimg.imread('figures/stacked_pieces.jpg')\n", "image_stack=image_stack/255.0\n", "\n", "\n", "image1_marked=mpimg.imread('figures/lefthalfpic.jpg')\n", "image1_marked=image1_marked/255.0\n", "image2_marked=mpimg.imread('figures/righthalfpic.jpg')\n", "image2_marked=image2_marked/255.0\n", "\n", "def euclidean_transform_2to1(transform_mat,translation,image,position,LL,UL):\n", " new_position=np.round(transform_mat.dot(position)+translation)\n", " new_position=new_position.astype(int)\n", "\n", " \n", " if (new_position>=LL).all() and (new_position=LL).all() and (new_position 0.995 and image1[row,col,1] > 0.995 and image1[row,col,2] > 0.995:\n", " temp = euclidean_transform_2to1(matrix_transform,translation,image2,position,LL,UL)\n", " image_rec[row,col,:] = temp\n", " else:\n", " image_rec[row,col,:] = image1[row,col,:]\n", " \n", "\n", "plt.figure(figsize=(20,20))\n", "plt.imshow(image_rec)\n", "plt.axis('on')\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" }, "name": "graphs_for_SOE.ipynb" }, "nbformat": 4, "nbformat_minor": 0 }