{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Image Processing SS 18 - Assignment - 04\n",
    "\n",
    "### Deadline is 16.5.2016 at 8:00 o'clock\n",
    "\n",
    "Please solve the assignments together with a partner.\n",
    "I will run every notebook. Make sure the code runs through. Select `Kernel` -> `Restart & Run All` to test it.\n",
    "Please strip the output from the cells, either select `Cell` -> `All Output` -> `Clear` or use the `nb_strip_output.py` script / git hook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "# display the plots inside the notebook\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pylab\n",
    "try:\n",
    "    import urllib.request as urllib2\n",
    "except ImportError:\n",
    "    import urllib2\n",
    "\n",
    "import random\n",
    "try:\n",
    "    from StringIO import StringIO as BytesIO\n",
    "except ImportError:\n",
    "    from io import BytesIO\n",
    "    \n",
    "from PIL import Image\n",
    "\n",
    "pylab.rcParams['figure.figsize'] = (12, 12)   # This makes the plot bigger"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 1 - Qualify sharpness and noise - 5 Points\n",
    "\n",
    "Qualify the noise and sharpness in the images. Make a plot images, noise\n",
    "\n",
    "Please download sample picture from [here](http://sipi.usc.edu/database/misc.zip)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/media/sebastian/Daten/nextcloud/Documents/Programmierung/Python/BildverarbeitungSS18/Hausaufgaben'"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the pictures here\n",
    "\n",
    "sample_images = []\n",
    "direc = 'misc/' # directory of the sample pictures relatively to your notebook\n",
    "for number in [1,3,5,6]:\n",
    "    sample_images.append(\n",
    "        np.array(Image.open(direc+'4.2.0'+str(number)+'.tiff'))\n",
    "    )\n",
    "for name in ['house']:\n",
    "    sample_images.append(\n",
    "        np.array(Image.open(direc+name+'.tiff'))\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Container object of 5 artists>"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAsMAAAKvCAYAAACPusJjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAFT1JREFUeJzt3V/IZHd9x/HPt1nFf9D4Z5E0kW5A\nsQRBLUtqCfQiaSFtxORCxNJKKCm50TZWQdfeSO8iFP9clEIwtoGKf1AhYqQlxJRSKGk3mlaTVQw2\naiSalWq1vahN/fVipzRNI/uYnXnG9fN6wcMzZ+acnS8cln1z9sz8Zq0VAABo9DP7HgAAAPZFDAMA\nUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwDAFBLDAMAUEsMAwBQ68hhvtkLXvCCdezYscN8SwAAytx7\n773fXmsdPci+hxrDx44dy8mTJw/zLQEAKDMzXz3ovm6TAACglhgGAKCWGAYAoJYYBgCglhgGAKCW\nGAYAoJYYBgCglhgGAKCWGAYAoJYYBgCglhgGAKCWGAYAoJYYBgCglhgGAKCWGAYAoJYYBgCglhgG\nAKCWGAYAoJYYBgCglhgGAKCWGAYAoJYYBgCglhgGAKCWGAYAoJYYBgCglhgGAKCWGAYAoJYYBgCg\nlhgGAKCWGAYAoNaRfQ8AANt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wXWGf+22Xza5scHfErMzCVJrkny\n/n3P0kIMnx8sfQ3FZuZYklcmuWe/k3BYNv9Nfl+SR5PcudZy7nu8N8nbkvxw34O0EMMAP8Fm5jlJ\nPp7kzWut7+17Hg7HWuu/1lqvyJnVXS+fmZfteyZ2b2ZeneTRtda9+56liRg+Pxxo6Wvgp8vMPC1n\nQviDa61P7HseDt9a67tJ7o7PDbS4IslrZuahnLkl8sqZ+Yv9jvTTTwyfHyx9DWVmZpLcmuTUWuvd\n+56HwzMzR2fmws3jZyb5tSRf3O9UHIa11jvWWpestY7lzL/1n1lr/faex/qpJ4bPA2utx5L8z9LX\np5J81NLXPWbmQ0n+LslLZ+bhmblh3zNxKK5I8oacuTJ03+bnN/Y9FIfioiR3z8w/5czFkDvXWr5i\nC3bECnQAANRyZRgAgFpiGACAWmIYAIBaYhgAgFpiGACAWmIYAIBaYhgAgFpiGACAWv8NIQVXd62O\nGPAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0b553c1a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def qualify_noise(img):\n",
    "    def mu2(img):\n",
    "        result = []\n",
    "        for i in range(img.shape[2]):\n",
    "            result.append(np.average(img[:, :, i]))\n",
    "        return np.array(result) # [mu(r), mu(g), mu(b)]\n",
    "    \"\"\"Qualify the noise based on the std of a gaussian model.\n",
    "       You may find a window that is contant in the images.\n",
    "    \"\"\"\n",
    "    # your code here\n",
    "    WINDOW_SIZE = 128\n",
    "    SHIFT = 128\n",
    "    w, h, d = img.shape\n",
    "    std = []\n",
    "    for ox in range(0, w-WINDOW_SIZE+1, SHIFT):\n",
    "        for oy in range(0, h-WINDOW_SIZE+1, SHIFT):\n",
    "            std_sum = np.std(img[ox:ox+WINDOW_SIZE, oy:oy+WINDOW_SIZE, 0]) + \\\n",
    "                      np.std(img[ox:ox+WINDOW_SIZE, oy:oy+WINDOW_SIZE, 1]) + \\\n",
    "                      np.std(img[ox:ox+WINDOW_SIZE, oy:oy+WINDOW_SIZE, 2])\n",
    "            std.append(std_sum)\n",
    "            \n",
    "    return np.min(std)\n",
    "\n",
    "plt.bar(range(len(sample_images)), [qualify_noise(i) for i in sample_images])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Container object of 5 artists>"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAsMAAAKvCAYAAACPusJjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAFNBJREFUeJzt3U/IZXd9x/HPt5mIgotoHULIaEdQ\nLKFghCFNyabECmkjmoUUpZUsUrJRiFSwY3dCF3GjdtFNMGKg4h9UiBihhBiRgsRONFpjKqYSaSSa\nEQ3qxhL9dTFXmKZJ58nMvc91/Lxe8PCcc+65nC8chufNmXPvmbVWAACg0e/tewAAANgXMQwAQC0x\nDABALTEMAEAtMQwAQC0xDABALTEMAEAtMQwAQC0xDABArSOHebCXvexl6/jx44d5SAAAyjz44IM/\nXmsdPci+hxrDx48fz6lTpw7zkAAAlJmZ7x90X7dJAABQSwwDAFBLDAMAUEsMAwBQSwwDAFBLDAMA\nUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwDAFBL\nDAMAUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwDAFBLDAMAUEsMAwBQSwwD\nAFBLDAMAUOvIvgcA2IXjJ+/Z9wg8w2O337jvEQD+D1eGAQCoJYYBAKglhgEAqCWGAQCoJYYBAKgl\nhgEAqCWGAQCoJYYBA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neQ3j75+JMmnPPq6x8x8PMlXkrxmZh6fmVv2PROH4rokb8+ZK0MPbX7+Yt9DcSiuSHL/zHwzZy6G\n3LvW8hVbsCOeQAcAQC1XhgEAqCWGAQCoJYYBAKglhgEAqCWGAQCoJYYBAKglhgEAqCWGAQCo9T+4\nCz2ha4YL8QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0b55368b38>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def qualify_sharpness(img):\n",
    "    \"\"\"Qualify the sharpness based on the average pixel differences.\"\"\"\n",
    "    # your code here\n",
    "    WINDOW_SIZE = 128\n",
    "    SHIFT = 128\n",
    "    w, h, d = img.shape\n",
    "    std = []\n",
    "    for ox in range(0, w-WINDOW_SIZE+1, SHIFT):\n",
    "        for oy in range(0, h-WINDOW_SIZE+1, SHIFT):\n",
    "            std_sum = np.std(img[ox:ox+WINDOW_SIZE, oy:oy+WINDOW_SIZE, 0]) + \\\n",
    "                      np.std(img[ox:ox+WINDOW_SIZE, oy:oy+WINDOW_SIZE, 1]) + \\\n",
    "                      np.std(img[ox:ox+WINDOW_SIZE, oy:oy+WINDOW_SIZE, 2])\n",
    "            std.append(std_sum)\n",
    "            \n",
    "    return np.std(std)\n",
    "plt.bar(range(len(sample_images)), [qualify_sharpness(i) for i in sample_images])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Does the result match the expectations? If not what processing step can be done?/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 2 - SSIM JPEG Compression - 5 Points"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "def jpeg_enocde(img, quality):\n",
    "    pil_img = Image.fromarray(img)\n",
    "    buffer = BytesIO()\n",
    "    pil_img.save(buffer, \"JPEG\", quality=quality)\n",
    "    return buffer\n",
    "\n",
    "def jpeg_decode(buffer):\n",
    "    img = Image.open(buffer)\n",
    "    return np.array(img)\n",
    "\n",
    "def jpeg_quality_filter(img, quality):\n",
    "    as_jpeg = jpeg_enocde(img, quality)\n",
    "    return jpeg_decode(as_jpeg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "images_for_jpeg = sample_images[2::]\n",
    "len(images_for_jpeg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "images1 = [jpeg_quality_filter(img, 1) for img in images_for_jpeg]\n",
    "images10 = [jpeg_quality_filter(img, 10) for img in images_for_jpeg]\n",
    "images50 = [jpeg_quality_filter(img, 50) for img in images_for_jpeg]\n",
    "images80 = [jpeg_quality_filter(img, 80) for img in images_for_jpeg]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAsYAAAKvCAYAAABpkwknAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAGIxJREFUeJzt3X2MZed90PHvr3bcIBKagpcS+SUb\nwJVqQiFhZYIiQaSmkpNINlJLZSNoU6W1eAkUtUIyL3Ih/JMUqaCCIbVo1bQqSU1A7dI4MgFSRUI4\neNMmIbZxWUyKbQJ20zQlCm1wefhjbmAy2fHcZGZ2dtnPR7ra+/Lo3kePzu757plz58xaKwAAuNJ9\n1UlPAAAALgXCGAAAEsYAAFAJYwAAqIQxAABUwhgAACphDAAAlTAGAIBKGAMAQFVXn9QH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asF3zIzrzjpOV1Otli/Y9sHXxJhvNZ63VrrFRe4/Uz137/w463Nn8/s8x5Pb/58ovq5dv6H\ne6X6ci7j3TzPZbyvUAeu31rrU2ut39g8/EfVH7pIc/v/xTbbKPtYa/3aF37UuHZ+z/wLZubaE57W\nJWVmXtBO1P3kWuufXWCIbfB5HLR+tsHtrLV+tfpAdeuel+yDt7Df+h3nPviSCOMD7L7c9HdUP7N3\nwMx87cx89eb+tdVrqkcv2gwvPS7jfTgHrt+ecxFva+ccPLZ3tvr2zW8GeHX1mV2nTHGAmfldXzgf\ncWZuaeffcjvVjc3a/Ej12FrrB/cZZhvcxzbrZxvc38ycmpmXbO7/luqbq/+wZ5h98D62Wb/j3Adv\ndeW7E/a26v6ZeXP1S9W3Vc3MmerPrLW+q/qG6odn5n+385fzbWutKzaMl8t4H8qW6/cXZ+a26rl2\n1u9NJzbhS9DMvKudb61fOzNPVd/fzhcoWmu9o50rab6hOl99rvrOk5nppWmL9fvW6s/OzHPV/6zu\nsFP9Iq+p/nT17zfnKVb91erGsg1uYZv1sw3u76XVO2fmqnaa5P611s/aB29tm/U7tn2wK98BAECX\nx6kUAABw7IQxAAAkjAEAoBLGAABQCWMAAKiEMQAAVMIYAAAqYQwAAFX9H2PUCTbxjzTZAAAAAElF\nTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0b55220a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAsYAAAKvCAYAAABpkwknAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAGIZJREFUeJzt3X+sZOd90OHPt3bcICU0BS8lsp1s\nA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t8/M3/wuCdzpdr8iPpV7R112s8+uIXnWL+yDx5oZq6ZmY9Wz1QfWGsduP/5DP5y\nW6xfHdFn8BURxjPzL2fmExe5fclRurV3/Pyg/zW8fO1dDeVPV393Zn7/Uc+bq9q/qE6utb6x+kD/\n73/+cDn8Qnv/5v3h6u9VP3PM87kizcyLqn9W/eW11q8f93yeby6xfvbB57DW+q211h9p72rBt87M\nK497Ts8nW6zfkX0GXxFhvNZ6/VrrlRe5/Wz137/4463Nn88c8BpPb/58svr59v6He7X67VzGu3mO\ny3hfpS65fmutT6+1fnPz8B9Vf/Qyze3/F9vsoxxgrfXrX/xR49r7PfMvmJnrj3laV5SZeUF7UfeP\n11r//CJD7IPP4VLrZx/czlrr16oPVrdd8JTP4C0ctH5H+Rl8RYTxJey/3PR3VT974YCZ+dqZ+erN\n/eur11aPXbYZXnlcxvtwLrl+F5yLeHt75+CxvdPVd25+M8Brqs/uO2WKS5iZ3/vF8xFn5tb2/i33\nobqxWZsfrx5fa/3IAcPsgwfYZv3sgwebmRMz85LN/d9RfXP1Hy4Y5jP4ANus31F+Bm915btj9rbq\ngZl5c/XL1bdXzcyp6s+utb6n+obqx2bmf7f3l/Nta62rNoyXy3gfypbr95dm5vbq2fbW703HNuEr\n0My8u71vrV8/M+eqH2zvCxSttd7R3pU031idrT5ffffxzPTKtMX6fVv152bm2ep/Vnf6UP0Sr63+\nTPXvN+cpVv216mVlH9zCNutnHzzYS6t3zcw17TXJA2utn/MZvLVt1u/IPoNd+Q4AAHp+nEoBAABH\nThgDAEDCGAAAKmEMAACVMAYAgEoYAwBAJYwBAKASxgAAUNX/AS7dDeGSTOD3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0b55239668>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAsYAAAKvCAYA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"<matplotlib.figure.Figure at 0x7f0b55308198>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def mu(img):\n",
    "    result = []\n",
    "    for i in range(img.shape[2]):\n",
    "        result.append(np.average(img[:, :, i]))\n",
    "    return np.array(result) # [mu(r), mu(g), mu(b)]\n",
    "\n",
    "def omega(img, img_mu):\n",
    "    return np.sqrt(np.average(np.square(img-img_mu))*img.shape[2])\n",
    "\n",
    "def omega2(img_x, img_x_mu, img_y, img_y_mu):\n",
    "    pixel = img_x.shape[0]*img_x.shape[1]\n",
    "    x = (img_x-img_x_mu).reshape(pixel, img_x.shape[2])\n",
    "    y = (img_y-img_y_mu).reshape(pixel, img_x.shape[2])\n",
    "    sum = 0\n",
    "    for xi, yi in zip(x, y):\n",
    "        sum += xi.dot(yi.T)\n",
    "    return sum/pixel\n",
    "    \n",
    "    #return mu((img_x-img_x_mu).T*(img_y-img_y_mu))**0.5\n",
    "\n",
    "def ssim(x, y):\n",
    "    \"\"\"The SSIM similarity measure. Use the parameters from the paper \n",
    "    as on the second to last slide from the lecture\"\"\"\n",
    "    #print(\"x\", omega(x, mu(x)))\n",
    "    #print(\"y\", omega(y, mu(y)))\n",
    "    #print(\"mu\", mu(x))\n",
    "    #print(\"xy\", omega2(x, mu(x), y, mu(y)))\n",
    "    mu_x = mu(x)\n",
    "    mu_y = mu(y)\n",
    "    o_x = omega(x, mu_x)\n",
    "    o_y = omega(y, mu_y)\n",
    "    o_xy = omega2(x, mu_x, y, mu_y)\n",
    "    c1 = 0.2\n",
    "    c2 = 0.6\n",
    "    return (2*mu_x.dot(mu_y.T)+c1) * (2*o_xy+c2) / (mu_x.dot(mu_x.T)+mu_y.dot(mu_y.T)+c1) / (o_x**2+o_y**2+c2)\n",
    "\n",
    "for i, img in enumerate(images_for_jpeg):\n",
    "    print(i)\n",
    "    compressed_images = [images1[i], images10[i], images50[i], images80[i]]\n",
    "    plt.bar(range(len(compressed_images)),\n",
    "             [ssim(img, comp) for comp in compressed_images])\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    ""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3.0
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}