{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import cv2\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.datasets import load_sample_image\n",
    "import numpy as np\n",
    "import dautil as dl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "img = load_sample_image('china.jpg')\n",
    "dl.plotting.img_show(plt.gca(), img)\n",
    "plt.title('Original')\n",
    "Z = img.reshape((-1, 3))\n",
    "\n",
    "np.random.seed(59)\n",
    "noise = np.random.random(Z.shape) < 0.99\n",
    "\n",
    "noisy = (Z * noise).reshape((img.shape))\n",
    "\n",
    "plt.figure()\n",
    "plt.title('Noisy')\n",
    "dl.plotting.img_show(plt.gca(), noisy)\n",
    "\n",
    "cleaned = cv2.fastNlMeansDenoisingColored(noisy, None, 10, 10, 7, 21)\n",
    "plt.figure()\n",
    "plt.title('Cleaned')\n",
    "dl.plotting.img_show(plt.gca(), cleaned)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
