|
@@ -0,0 +1,303 @@
|
|
|
|
+{
|
|
|
|
+ "cells": [
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 1,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "from ipfml import processing\n",
|
|
|
|
+ "from ipfml import utils\n",
|
|
|
|
+ "from ipfml import metrics\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",
|
|
|
|
+ "import os"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 2,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "data_folder = \"../fichiersSVD_light\""
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "markdown",
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "source": [
|
|
|
|
+ "# SVD analysis on zones of Synthesis Images "
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "markdown",
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "source": [
|
|
|
|
+ "## Utils functions definition"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 3,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "def compute_images_path(dict_data):\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": 4,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "def get_images_zones(dict_data, images_path):\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " zones_indices = dict_data['zones']\n",
|
|
|
|
+ " zones_img = []\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " for path in images_path:\n",
|
|
|
|
+ " img = Image.open(path)\n",
|
|
|
|
+ " zones = processing.divide_in_blocks(img, (200, 200))\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " zones_list = []\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " for id_zone in zones_indices:\n",
|
|
|
|
+ " zones_list.append(zones[id_zone])\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " zones_img.append(zones_list)\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " return zones_img"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 16,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "def display_sv_data(dict_data, zones_data, interval, _norm=False):\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " scene_name = dict_data['name']\n",
|
|
|
|
+ " image_indices = dict_data['indices']\n",
|
|
|
|
+ " zones_indices = dict_data['zones']\n",
|
|
|
|
+ " colors = ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9']\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " plt.figure(figsize=(25, 20))\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " sv_data = []\n",
|
|
|
|
+ " begin, end = interval\n",
|
|
|
|
+ " for id_img, zones in enumerate(zones_data):\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " for id_zone, zone in enumerate(zones):\n",
|
|
|
|
+ " U, s, V = processing.get_LAB_L_SVD(zone)\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " data = s[begin:end]\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " if _norm:\n",
|
|
|
|
+ " data = utils.normalize_arr(data)\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " plt.plot(data, \n",
|
|
|
|
+ " color=colors[id_zone], \n",
|
|
|
|
+ " label='Zone ' + str(zones_indices[id_zone]) + ' of ' + scene_name + '_' + str(image_indices[id_img]))\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " plt.legend(fontsize=18)\n",
|
|
|
|
+ " plt.show()"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 17,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "# Useful function\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "def get_highest_values(arr, n):\n",
|
|
|
|
+ " return np.array(arr).argsort()[-n:][::-1]\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "def get_lowest_values(arr, n):\n",
|
|
|
|
+ " return np.array(arr).argsort()[::-1][-n:][::-1]"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "markdown",
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "source": [
|
|
|
|
+ "## Scenes zones data"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 6,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "# start 00020 - ref 00900 - step 10\n",
|
|
|
|
+ "dict_appart = {'name': 'Appart1opt02', \n",
|
|
|
|
+ " 'prefix': 'appartAopt_', \n",
|
|
|
|
+ " 'indices': [\"00020\", \"00200\", \"00900\"],\n",
|
|
|
|
+ " 'zones': [3, 6]}\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "# start 00050 - ref 01200 - step 10\n",
|
|
|
|
+ "dict_cuisine = {'name': 'Cuisine01', \n",
|
|
|
|
+ " 'prefix': 'cuisine01_', \n",
|
|
|
|
+ " 'indices': [\"00050\", \"00400\", \"01200\"],\n",
|
|
|
|
+ " 'zones': [3, 6]}\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "# start 00020 - ref 00950 - step 10\n",
|
|
|
|
+ "dict_sdb_c = {'name': 'SdbCentre', \n",
|
|
|
|
+ " 'prefix': 'SdB2_', \n",
|
|
|
|
+ " 'indices': [\"00020\", \"00400\", \"00950\"],\n",
|
|
|
|
+ " 'zones': [3, 6]}\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "# start 00020 - ref 00950 - step 10\n",
|
|
|
|
+ "dict_sdb_d = {'name': 'SdbDroite', \n",
|
|
|
|
+ " 'prefix': 'SdB2_D_', \n",
|
|
|
|
+ " 'indices': [\"00020\", \"00400\", \"00950\"],\n",
|
|
|
|
+ " 'zones': [2, 3, 10, 13]}"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 7,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "current_dict = dict_sdb_d\n",
|
|
|
|
+ "interval = (30, 200)"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 8,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [
|
|
|
|
+ {
|
|
|
|
+ "name": "stdout",
|
|
|
|
+ "output_type": "stream",
|
|
|
|
+ "text": [
|
|
|
|
+ "../fichiersSVD_light/SdbDroite/SdB2_D_00020.png\n",
|
|
|
|
+ "../fichiersSVD_light/SdbDroite/SdB2_D_00400.png\n",
|
|
|
|
+ "../fichiersSVD_light/SdbDroite/SdB2_D_00950.png\n"
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "source": [
|
|
|
|
+ "images_path = compute_images_path(current_dict)\n",
|
|
|
|
+ "zones_data = get_images_zones(current_dict, images_path)"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 28,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "first_image = zones_data[0][1]\n",
|
|
|
|
+ "entropy_contribution_data = []\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "sv = processing.get_LAB_L_SVD_s(zone)\n",
|
|
|
|
+ "sv = utils.normalize_arr(sv)\n",
|
|
|
|
+ "entropy = utils.get_entropy(sv)\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "for i in range(200):\n",
|
|
|
|
+ " entropy_without_column = utils.get_entropy_without_i(sv, i)\n",
|
|
|
|
+ " entropy_contribution_column = entropy - entropy_without_column\n",
|
|
|
|
+ " entropy_contribution_data.append(entropy_contribution_column)"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 29,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [
|
|
|
|
+ {
|
|
|
|
+ "data": {
|
|
|
|
+ "text/plain": [
|
|
|
|
+ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,\n",
|
|
|
|
+ " 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n",
|
|
|
|
+ " 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\n",
|
|
|
|
+ " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,\n",
|
|
|
|
+ " 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,\n",
|
|
|
|
+ " 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,\n",
|
|
|
|
+ " 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,\n",
|
|
|
|
+ " 92, 93, 94, 95, 96, 97, 98, 99, 100])"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ "execution_count": 29,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "output_type": "execute_result"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "source": [
|
|
|
|
+ "get_highest_values(entropy_contribution_data, 100)"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 30,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [
|
|
|
|
+ {
|
|
|
|
+ "data": {
|
|
|
|
+ "text/plain": [
|
|
|
|
+ "array([ 0, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188,\n",
|
|
|
|
+ " 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175,\n",
|
|
|
|
+ " 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162,\n",
|
|
|
|
+ " 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149,\n",
|
|
|
|
+ " 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136,\n",
|
|
|
|
+ " 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123,\n",
|
|
|
|
+ " 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110,\n",
|
|
|
|
+ " 109, 108, 107, 106, 105, 104, 103, 102, 101])"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ "execution_count": 30,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "output_type": "execute_result"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "source": [
|
|
|
|
+ "get_lowest_values(entropy_contribution_data, 100)"
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "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
|
|
|
|
+}
|