{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipfml.processing.segmentation import divide_in_blocks\n",
    "from ipfml.processing import transform\n",
    "from ipfml.filters import convolution as conv\n",
    "from ipfml.filters import kernels\n",
    "from ipfml import utils\n",
    "from ipfml.iqa import fr\n",
    "\n",
    "from PIL import Image\n",
    "from scipy import signal\n",
    "from skimage import color\n",
    "import scipy.stats as stats\n",
    "import seaborn as sns\n",
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from numpy.linalg import svd\n",
    "import os\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from digital_image_processing.edge_detection.canny import canny\n",
    "from digital_image_processing.filters.sobel_filter import sobel_filter\n",
    "import seaborn as sns\n",
    "\n",
    "sns.set_context(\"paper\")\n",
    "sns.set(rc={'figure.figsize':(10, 7)})\n",
    "\n",
    "import plotly.figure_factory as ff\n",
    "import plotly\n",
    "from plotly.offline import iplot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_folder = \"../dataset\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Edge detection analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utils functions definition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def compute_images_path(dict_data):\n",
    "    \n",
    "    scene = dict_data['name']\n",
    "    prefix = dict_data['prefix']\n",
    "    indices = dict_data['indices']\n",
    "    \n",
    "    images_path = []\n",
    "    for index in indices:\n",
    "        path = os.path.join(data_folder, os.path.join(scene, prefix + index + \".png\"))\n",
    "        print(path)\n",
    "        images_path.append(path)\n",
    "    return images_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_images_zones(dict_data, images_path):\n",
    "    \n",
    "    id_zone = dict_data['zone']\n",
    "    \n",
    "    zones_img = []\n",
    "    for path in images_path:\n",
    "        img = Image.open(path)\n",
    "        zones = divide_in_blocks(img, (200, 200))\n",
    "        zones_img.append(zones[id_zone])\n",
    "        \n",
    "    return zones_img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def display_zones(dict_scene, zones, rows, columns):\n",
    "\n",
    "    fig=plt.figure(figsize=(30, 20))\n",
    "    \n",
    "    indices = dict_scene['indices']\n",
    "    \n",
    "    for i, img in enumerate(zones):\n",
    "        \n",
    "        ax1 = fig.add_subplot(rows, columns, (i+1))\n",
    "        ax1.title.set_text(indices[i])\n",
    "\n",
    "        # Turn off tick labels\n",
    "        ax1.set_yticklabels([])\n",
    "        ax1.set_xticklabels([])\n",
    "                   \n",
    "        plt.imshow(img, cmap='gray', vmin=0, vmax=255)\n",
    "    \n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def remove_pixel(img, limit):\n",
    "    \n",
    "    width, height = img.shape\n",
    "    \n",
    "    output = np.zeros((width, height))\n",
    "    \n",
    "    for i in range(width):\n",
    "        for j in range(height):\n",
    "            \n",
    "            if img[i,j] <= limit:\n",
    "                output[i,j] = img[i,j]\n",
    "                \n",
    "    return output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Scenes information data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# start 00020 - ref 00900 - step 10\n",
    "dict_appart = {'name': 'Appart1opt02', \n",
    "               'prefix': 'appartAopt_', \n",
    "               'indices': [\"00050\", \"00100\", \"00200\", \"00300\", \"00400\", \"00500\", \"00700\", \"00900\"],\n",
    "               'zone': 9}\n",
    "\n",
    "# start 00050 - ref 01200 - step 10\n",
    "dict_cuisine = {'name': 'Cuisine01', \n",
    "               'prefix': 'cuisine01_', \n",
    "               'indices': [\"00050\", \"00100\", \"00200\", \"00300\", \"00400\", \"00600\", \"00700\",\"00900\", \"01200\"],\n",
    "               'zone': 6}\n",
    "\n",
    "# start 00020 - ref 00950 - step 10\n",
    "dict_sdb_c = {'name': 'SdbCentre', \n",
    "               'prefix': 'SdB2_', \n",
    "               'indices': [\"00020\", \"00400\", \"00950\"],\n",
    "               'zone': 3}\n",
    "\n",
    "# start 00020 - ref 00950 - step 10\n",
    "dict_sdb_d = {'name': 'SdbDroite', \n",
    "               'prefix': 'SdB2_D_', \n",
    "               'indices': [\"00020\", \"00400\", \"00950\"],\n",
    "               'zone': 3}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Definition of parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "../dataset/Appart1opt02/appartAopt_00050.png\n",
      "../dataset/Appart1opt02/appartAopt_00100.png\n",
      "../dataset/Appart1opt02/appartAopt_00200.png\n",
      "../dataset/Appart1opt02/appartAopt_00300.png\n",
      "../dataset/Appart1opt02/appartAopt_00400.png\n",
      "../dataset/Appart1opt02/appartAopt_00500.png\n",
      "../dataset/Appart1opt02/appartAopt_00700.png\n",
      "../dataset/Appart1opt02/appartAopt_00900.png\n",
      "../dataset/Cuisine01/cuisine01_00050.png\n",
      "../dataset/Cuisine01/cuisine01_00100.png\n",
      "../dataset/Cuisine01/cuisine01_00200.png\n",
      "../dataset/Cuisine01/cuisine01_00300.png\n",
      "../dataset/Cuisine01/cuisine01_00400.png\n",
      "../dataset/Cuisine01/cuisine01_00600.png\n",
      "../dataset/Cuisine01/cuisine01_00700.png\n",
      "../dataset/Cuisine01/cuisine01_00900.png\n",
      "../dataset/Cuisine01/cuisine01_01200.png\n"
     ]
    }
   ],
   "source": [
    "images_path_appart = compute_images_path(dict_appart)\n",
    "images_path_cuisine = compute_images_path(dict_cuisine)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "zones_appart = get_images_zones(dict_appart, images_path_appart)\n",
    "zones_cuisine = get_images_zones(dict_cuisine, images_path_cuisine)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Study of Canny filter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "zone = np.array(zones_appart[0])\n",
    "zone_l = transform.get_LAB_L(zone)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbd3e2cf8>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 13964 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "canny_img = canny(zone_l)\n",
    "plt.imshow(canny_img,cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f0cbd3316a0>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 16948 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "canny_img_dist = canny_img.reshape((40000))\n",
    "sns.distplot(canny_img_dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sobel filter analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "zone = np.array(zones_appart[0])\n",
    "zone_l = transform.get_LAB_L(zone)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbd1eaeb8>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 92780 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "plt.imshow(sobel_grad, cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbd1d5c18>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 31500 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_theta, cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Study of sobel distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f0cbc1892e8>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 19764 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad_dist = sobel_grad.reshape((40000))\n",
    "sns.distplot(sobel_grad_dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Following this distribution we will set to 0 all pixels values which are over [30, 50, 100]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using 50 as limit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbc08a5c0>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 85872 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad_50 = remove_pixel(sobel_grad, 50)\n",
    "plt.imshow(sobel_grad_50, cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbc065e48>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 103532 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_grad_50, cmap='gray', vmin=0, vmax=50)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using 100 as limit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbbfc99e8>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 91896 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad_100 = remove_pixel(sobel_grad, 100)\n",
    "plt.imshow(sobel_grad_100, cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbbf2d7b8>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 106056 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_grad_100, cmap='gray', vmin=0, vmax=100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using 30 as limit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbbf0ec18>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 81340 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad_30 = remove_pixel(sobel_grad, 30)\n",
    "plt.imshow(sobel_grad_30, cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbbe7a0f0>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 90692 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_grad_30, cmap='gray', vmin=0, vmax=30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0cbbe58390>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 90692 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# try using normalization\n",
    "sobel_grad_30_norm = utils.normalize_2D_arr(sobel_grad_30)\n",
    "plt.imshow(sobel_grad_30_norm, cmap='gray', vmin=0, vmax=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Generalization of sobel use"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Apply sobel filter on different level of noise in images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_zones = []\n",
    "for zone in zones_appart:\n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "    sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "    sobel_grad_30 = remove_pixel(sobel_grad, 30)\n",
    "    sobel_grad_30_norm = utils.normalize_2D_arr(sobel_grad_30)\n",
    "    sobel_grad_30_norm = np.array(sobel_grad_30_norm*255, 'uint8')\n",
    "    sobel_zones.append(sobel_grad_30_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 612552 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, sobel_zones, 2, 4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It seems the filter care attention of present noise into the scene. Let's compute SSIM between most sobel filter obtained from most noisy image and others."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Difference between (00050, 00050) => 1.0\n",
      "Difference between (00050, 00100) => 0.4162070608072902\n",
      "Difference between (00050, 00200) => 0.2931616134838471\n",
      "Difference between (00050, 00300) => 0.24738271340201531\n",
      "Difference between (00050, 00400) => 0.2329356379108702\n",
      "Difference between (00050, 00500) => 0.22003614321511586\n",
      "Difference between (00050, 00700) => 0.20418593796824586\n",
      "Difference between (00050, 00900) => 0.2009585396654271\n"
     ]
    }
   ],
   "source": [
    "selected_sobel_zone = sobel_zones[0]\n",
    "indices = dict_appart['indices']\n",
    "\n",
    "for i, sobel_zone in enumerate(sobel_zones):\n",
    "    score = fr.ssim(selected_sobel_zone, sobel_zone)\n",
    "    print(\"Difference between (\" + str(indices[0]) + \", \" + str(indices[i]) + \") => \" + str(score))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Study of pixel distribution of image without edges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "zone = np.array(zones_appart[0])\n",
    "zone_l = transform.get_LAB_L(zone)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "sobel_grad_30 = remove_pixel(sobel_grad, 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f0cb82b8da0>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 19960 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad_30_dist = sobel_grad_30.reshape((200*200))\n",
    "sns.set(rc={'figure.figsize':(10, 7)})\n",
    "sns.distplot(sobel_grad_30_dist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we see that pixel value of 0 used is mainly used because of the suppression of edge. We remove now 0 value from this distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f0cb81f4588>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 23684 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sobel_grad_30_dist_without_0 = [x for x in sobel_grad_30.reshape((200*200)) if x != 0]\n",
    "sns.set(rc={'figure.figsize':(10, 7)})\n",
    "sns.distplot(sobel_grad_30_dist_without_0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Study of distribution for each level of noise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f0cb823b748>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 198872 characters]\n",
      "text/plain": [
       "<Figure size 1440x1080 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set(rc={'figure.figsize':(20, 15)})\n",
    "\n",
    "sobel_zones_data = []\n",
    "indices = dict_appart['indices']\n",
    "\n",
    "for zone in zones_appart:\n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "    sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "    sobel_grad_30 = remove_pixel(sobel_grad, 30)\n",
    "    sobel_grad_30_dist_without_0 = [x for x in sobel_grad_30.reshape((200*200)) if x != 0]\n",
    "    sobel_zones_data.append(sobel_grad_30_dist_without_0)\n",
    "    sns.distplot(sobel_grad_30_dist_without_0, rug=True, hist=False)\n",
    "    \n",
    "plt.legend(labels=indices)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Distrubtion information give us information of pixels value variation. It seems for this zone that converged pixels value are in [0, 10] interval."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Fill edge pixels using known distribution of image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "def distribution_from_data(data):\n",
    "    \n",
    "    occurences = np.array([data.count(x) for x in set(data)])\n",
    "    max_occurences = sum(occurences)\n",
    "    \n",
    "    return occurences / max_occurences"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_random_value(distribution):\n",
    "    rand = random.uniform(0, 1)\n",
    "    prob_sum = 0.\n",
    "    \n",
    "    for id, prob in enumerate(distribution):\n",
    "        \n",
    "        prob_sum += prob\n",
    "        \n",
    "        if prob_sum >= rand:\n",
    "            return id\n",
    "        \n",
    "    return len(distribution) - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "zone = np.array(zones_appart[0])\n",
    "zone_l = transform.get_LAB_L(zone)\n",
    "sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "sobel_grad_30 = remove_pixel(sobel_grad, 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_grad_30_dist_without_0 = [x for x in sobel_grad_30.reshape((200*200)) if x != 0]    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "distribution = distribution_from_data(sobel_grad_30_dist_without_0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Now we can check the new distribution function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "min_value = int(min(sobel_grad_30_dist_without_0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "values = [get_random_value(distribution) + min_value for i in range(10000)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f0caae7b518>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 27812 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set(rc={'figure.figsize':(10, 7)})\n",
    "sns.distplot(values)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Fill the image "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "def fill_image_with_rand_value(img, func, value_to_replace):\n",
    "    \n",
    "    width, height = img.shape\n",
    "    \n",
    "    output = np.zeros((width, height))\n",
    "    \n",
    "    for i in range(width):\n",
    "        for j in range(height):\n",
    "            \n",
    "            if img[i,j] == value_to_replace:\n",
    "                output[i, j] = func()\n",
    "            else:\n",
    "                output[i, j] = img[i, j]\n",
    "                \n",
    "    return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = lambda: get_random_value(distribution) + min_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0caace3668>"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 95548 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "img_reconstructed = fill_image_with_rand_value(sobel_grad_30, l, 0)\n",
    "plt.imshow(img_reconstructed, cmap='gray', vmin=0, vmax=30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0caacbe8d0>"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 90692 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_grad_30, cmap='gray', vmin=0, vmax=30)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Statistical analysis of each zone"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_stats(dict_info, zones):\n",
    "    \n",
    "    indices = dict_info[\"indices\"]\n",
    "    \n",
    "    for id, zone in enumerate(zones):\n",
    "        std = np.std(zone)\n",
    "        mean = np.mean(zone)\n",
    "        \n",
    "        print(\"For zone with \" + indices[id])\n",
    "        print(\"-- Std: \", std)\n",
    "        print(\"-- Mean: \", mean)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Without reconstruction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_norm_images = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone = np.array(zone)\n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "    sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "    sobel_grad_30 = remove_pixel(sobel_grad, 30)\n",
    "    \n",
    "    sobel_grad_30_norm = utils.normalize_2D_arr(sobel_grad_30)\n",
    "    sobel_grad_30_norm = np.array(sobel_grad_30_norm*255, 'uint8')\n",
    "    \n",
    "    sobel_norm_images.append(sobel_grad_30_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 612552 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, sobel_norm_images, 2, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For zone with 00050\n",
      "-- Std:  66.58386088865679\n",
      "-- Mean:  90.6946\n",
      "For zone with 00100\n",
      "-- Std:  58.84156604229701\n",
      "-- Mean:  76.0413\n",
      "For zone with 00200\n",
      "-- Std:  52.60290912751404\n",
      "-- Mean:  60.56365\n",
      "For zone with 00300\n",
      "-- Std:  51.08855011628707\n",
      "-- Mean:  54.887875\n",
      "For zone with 00400\n",
      "-- Std:  50.61911357382703\n",
      "-- Mean:  51.479\n",
      "For zone with 00500\n",
      "-- Std:  50.60663240771287\n",
      "-- Mean:  49.447025\n",
      "For zone with 00700\n",
      "-- Std:  50.550519138228196\n",
      "-- Mean:  46.715325\n",
      "For zone with 00900\n",
      "-- Std:  50.34580462004754\n",
      "-- Mean:  45.1654\n"
     ]
    }
   ],
   "source": [
    "get_stats(dict_appart, sobel_norm_images)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Without reconstruction (fill 0 value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "reconstructed_images = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone = np.array(zone)\n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "    sobel_grad, sobel_theta = sobel_filter(zone_l)\n",
    "    sobel_grad_30 = remove_pixel(sobel_grad, 30)\n",
    "    sobel_grad_30_dist_without_0 = [x for x in sobel_grad_30.reshape((200*200)) if x != 0]  \n",
    "    distribution = distribution_from_data(sobel_grad_30_dist_without_0)\n",
    "    min_value = int(min(sobel_grad_30_dist_without_0))\n",
    "    l = lambda: get_random_value(distribution) + min_value\n",
    "    img_reconstructed = fill_image_with_rand_value(sobel_grad_30, l, 0)\n",
    "    \n",
    "    img_reconstructed_norm = utils.normalize_2D_arr(img_reconstructed)\n",
    "    img_reconstructed_norm = np.array(img_reconstructed_norm*255, 'uint8')\n",
    "    \n",
    "    reconstructed_images.append(img_reconstructed_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 722044 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, reconstructed_images, 2, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For zone with 00050\n",
      "-- Std:  60.42833473304866\n",
      "-- Mean:  103.015375\n",
      "For zone with 00100\n",
      "-- Std:  55.429901886887734\n",
      "-- Mean:  84.0709\n",
      "For zone with 00200\n",
      "-- Std:  51.53426794580476\n",
      "-- Mean:  65.1777\n",
      "For zone with 00300\n",
      "-- Std:  50.972662142932066\n",
      "-- Mean:  58.39625\n",
      "For zone with 00400\n",
      "-- Std:  51.25330828502683\n",
      "-- Mean:  54.5272\n",
      "For zone with 00500\n",
      "-- Std:  51.620526141351945\n",
      "-- Mean:  52.3283\n",
      "For zone with 00700\n",
      "-- Std:  52.10343594118818\n",
      "-- Mean:  49.34715\n",
      "For zone with 00900\n",
      "-- Std:  52.17897489976207\n",
      "-- Mean:  47.7221\n"
     ]
    }
   ],
   "source": [
    "get_stats(dict_appart, reconstructed_images)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Using OpenCV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.set(rc={'figure.figsize':(10, 7)})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "selected_zone = zones_appart[0]\n",
    "zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=3)\n",
    "sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')  # magnitude"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0c863c7a90>"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 73284 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_mag, cmap='gray', vmin=0, vmax=255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_mag_30 = remove_pixel(sobel_mag, 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0c86386be0>"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 70528 characters]\n",
      "text/plain": [
       "<Figure size 720x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(sobel_mag_30, cmap='gray', vmin=0, vmax=30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_norm_images = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "    sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=3)\n",
    "    sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=3)\n",
    "    \n",
    "    sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')  # magnitude\n",
    "    sobel_mag_30 = remove_pixel(sobel_mag, 30)\n",
    "\n",
    "    sobel_grad_30_norm = utils.normalize_2D_arr(sobel_mag_30)\n",
    "    sobel_grad_30_norm = np.array(sobel_grad_30_norm*255, 'uint8')\n",
    "    \n",
    "    sobel_norm_images.append(sobel_grad_30_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 578284 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, sobel_norm_images, 2, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_norm_images_k5 = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "    sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=5)\n",
    "    sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=5)\n",
    "    \n",
    "    sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')\n",
    "    sobel_mag_30 = remove_pixel(sobel_mag, 30)\n",
    "\n",
    "    sobel_grad_30_norm = utils.normalize_2D_arr(sobel_mag_30)\n",
    "    sobel_grad_30_norm = np.array(sobel_grad_30_norm*255, 'uint8')\n",
    "    \n",
    "    sobel_norm_images_k5.append(sobel_grad_30_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 385136 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, sobel_norm_images_k5, 2, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "sobel_norm_images_k7 = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "    sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=7)\n",
    "    sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=7)\n",
    "    \n",
    "    sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')\n",
    "    sobel_mag_30 = remove_pixel(sobel_mag, 30)\n",
    "\n",
    "    sobel_grad_30_norm = utils.normalize_2D_arr(sobel_mag_30)\n",
    "    sobel_grad_30_norm = np.array(sobel_grad_30_norm*255, 'uint8')\n",
    "    \n",
    "    sobel_norm_images_k7.append(sobel_grad_30_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 262356 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, sobel_norm_images_k7, 2, 4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Reconstruction of images using OpenCV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f0c85b899b0>"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 178064 characters]\n",
      "text/plain": [
       "<Figure size 1440x1080 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.set(rc={'figure.figsize':(20, 15)})\n",
    "\n",
    "sobel_zones_data = []\n",
    "indices = dict_appart['indices']\n",
    "\n",
    "for zone in zones_appart:\n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "    sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=3)\n",
    "    sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=3)\n",
    "    \n",
    "    sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')\n",
    "    \n",
    "    sobel_mag_30 = remove_pixel(sobel_mag, 30)\n",
    "    \n",
    "    sobel_grad_30_dist_without_0 = [x for x in sobel_mag_30.reshape((200*200)) if x != 0]  \n",
    "    sobel_zones_data.append(sobel_grad_30_dist_without_0)\n",
    "    sns.distplot(sobel_grad_30_dist_without_0, rug=True, hist=False)\n",
    "    \n",
    "plt.legend(labels=indices)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "reconstructed_sobel_norm_images_k3 = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "    sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=3)\n",
    "    sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=3)\n",
    "    \n",
    "    sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')  # magnitude\n",
    "    \n",
    "    sobel_mag_30 = remove_pixel(sobel_mag, 30)\n",
    "    \n",
    "    sobel_grad_30_dist_without_0 = [x for x in sobel_mag_30.reshape((200*200)) if x != 0]  \n",
    "    distribution = distribution_from_data(sobel_grad_30_dist_without_0)\n",
    "    min_value = int(min(sobel_grad_30_dist_without_0))\n",
    "    l = lambda: get_random_value(distribution) + min_value\n",
    "    img_reconstructed = fill_image_with_rand_value(sobel_mag_30, l, 0)\n",
    "    \n",
    "    img_reconstructed_norm = utils.normalize_2D_arr(img_reconstructed)\n",
    "    img_reconstructed_norm = np.array(img_reconstructed_norm*255, 'uint8')\n",
    "    reconstructed_sobel_norm_images_k3.append(img_reconstructed_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 676516 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, reconstructed_sobel_norm_images_k3, 2, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "reconstructed_sobel_norm_images_k5 = []\n",
    "\n",
    "for zone in zones_appart:\n",
    "    \n",
    "    zone_l = transform.get_LAB_L(zone)\n",
    "\n",
    "    sobelx = cv2.Sobel(zone_l, cv2.CV_64F, 1, 0, ksize=5)\n",
    "    sobely = cv2.Sobel(zone_l, cv2.CV_64F, 0, 1,ksize=5)\n",
    "    \n",
    "    sobel_mag = np.array(np.hypot(sobelx, sobely), 'uint8')  # magnitude\n",
    "    \n",
    "    sobel_mag_30 = remove_pixel(sobel_mag, 30)\n",
    "    sobel_grad_30_dist_without_0 = [x for x in sobel_mag_30.reshape((200*200)) if x != 0]  \n",
    "    distribution = distribution_from_data(sobel_grad_30_dist_without_0)\n",
    "    min_value = int(min(sobel_grad_30_dist_without_0))\n",
    "    l = lambda: get_random_value(distribution) + min_value\n",
    "    img_reconstructed = fill_image_with_rand_value(sobel_mag_30, l, 0)\n",
    "    \n",
    "    img_reconstructed_norm = utils.normalize_2D_arr(img_reconstructed)\n",
    "    img_reconstructed_norm = np.array(img_reconstructed_norm*255, 'uint8')\n",
    "    reconstructed_sobel_norm_images_k5.append(img_reconstructed_norm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 846376 characters]\n",
      "text/plain": [
       "<Figure size 2160x1440 with 8 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display_zones(dict_appart, reconstructed_sobel_norm_images_k5, 2, 4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "thesis-venv",
   "language": "python",
   "name": "thesis-venv"
  },
  "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.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
