Sfoglia il codice sorgente

Add of svd curve information by zone using interval

Jérôme BUISINE 6 anni fa
parent
commit
6fe3acf45f

+ 1 - 1
generate_all_data.py

@@ -173,7 +173,7 @@ def generate_data_svd(data_type, mode):
             f.write(str(min_val_found) + '\n')
             f.write(str(max_val_found) + '\n')
 
-    print("%s : end of data generation\n" % _mode)
+    print("%s : end of data generation\n" % mode)
 
 
 def main():

+ 1 - 1
utils/data_type_module.py

@@ -1,9 +1,9 @@
 from ipfml import image_processing, metrics
 from PIL import Image
+from skimage import color
 
 import numpy as np
 
-
 def get_svd_data(data_type, block):
     """
     Method which returns the data type expected

+ 0 - 206
utils/display_svd_values.py

@@ -1,206 +0,0 @@
-from ipfml import image_processing
-from PIL import Image
-import numpy as np
-from ipfml import metrics
-from skimage import color
-
-import cv2
-
-low_bits_2_svd_values = []
-
-low_bits_3_svd_values = []
-
-low_bits_4_svd_values = []
-
-low_bits_5_svd_values = []
-
-low_bits_6_svd_values = []
-
-mscn_revisited_svd_values = []
-
-mscn_svd_values = []
-
-lab_svd_values = []
-
-def open_and_display(path):
-    img = Image.open(path)
-
-    block_used = np.array(img)
-
-    img_mscn = image_processing.rgb_to_mscn(block_used)
-
-    #img_mscn_norm = image_processing.normalize_2D_arr(img_mscn)
-
-    #print(img_mscn)
-    img_output = img_mscn.astype('uint8')
-
-    print('-------------------------')
-
-    # MSCN part computation
-    mscn_s = metrics.get_SVD_s(img_output)
-
-    mscn_s = [m / mscn_s[0] for m in mscn_s]
-
-    mscn_revisited_svd_values.append(mscn_s)
-
-    # LAB part computation
-    path_block_img = '/tmp/lab_img.png'
-
-    img_used_pil = Image.fromarray(block_used.astype('uint8'), 'RGB')
-    img_used_pil.save(path_block_img)
-
-    lab_s = image_processing.get_LAB_L_SVD_s(Image.open(path_block_img))
-
-    lab_s = [l / lab_s[0] for l in lab_s]
-    lab_svd_values.append(lab_s)
-
-    # computation of low bits parts 2 bits
-    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 3)
-
-    low_bits_svd = metrics.get_SVD_s(low_bits_block)
-
-    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
-
-    low_bits_2_svd_values.append(low_bits_svd)
-
-    # computation of low bits parts 3 bits
-    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 7)
-
-    low_bits_svd = metrics.get_SVD_s(low_bits_block)
-
-    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
-
-    low_bits_3_svd_values.append(low_bits_svd)
-
-    # computation of low bits parts 4 bits
-    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used)
-
-    low_bits_svd = metrics.get_SVD_s(low_bits_block)
-
-    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
-
-    low_bits_4_svd_values.append(low_bits_svd)
-
-    # computation of low bits parts 5 bits
-    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 31)
-
-    low_bits_svd = metrics.get_SVD_s(low_bits_block)
-
-    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
-
-    low_bits_5_svd_values.append(low_bits_svd)
-
-    # computation of low bits parts 6 bits
-    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 63)
-
-    low_bits_svd = metrics.get_SVD_s(low_bits_block)
-
-    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
-
-    low_bits_6_svd_values.append(low_bits_svd)
-
-
-
-    # Other MSCN
-    img_grey = np.array(color.rgb2gray(np.asarray(block_used))*255, 'uint8')
-
-
-    img_mscn_in_grey = np.array(image_processing.normalize_2D_arr(image_processing.calculate_mscn_coefficients(img_grey, 7))*255, 'uint8')
-    svd_s_values = metrics.get_SVD_s(img_mscn_in_grey)
-
-    svd_s_values = [s / svd_s_values[0] for s in svd_s_values]
-    mscn_svd_values.append(svd_s_values)
-
-
-
-
-#path_noisy = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Appart1opt02/appartAopt_00020.png'
-#path_threshold = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Appart1opt02/appartAopt_00300.png'
-#path_ref = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Appart1opt02/appartAopt_00900.png'
-
-path_noisy = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00050.png'
-path_threshold = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00400.png'
-path_ref = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_01200.png'
-
-
-path_list = [path_noisy, path_threshold, path_ref]
-
-for p in path_list:
-    open_and_display(p)
-
-import matplotlib.pyplot as plt
-
-# SVD
-# make a little extra space between the subplots
-
-plt.plot(lab_svd_values[0], label='Noisy')
-plt.plot(lab_svd_values[1], label='Threshold')
-plt.plot(lab_svd_values[2], label='Reference')
-plt.ylabel('LAB SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(mscn_svd_values[0], label='Noisy')
-plt.plot(mscn_svd_values[1], label='Threshold')
-plt.plot(mscn_svd_values[2], label='Reference')
-plt.ylabel('MSCN SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(mscn_revisited_svd_values[0], label='Noisy')
-plt.plot(mscn_revisited_svd_values[1], label='Threshold')
-plt.plot(mscn_revisited_svd_values[2], label='Reference')
-plt.ylabel('Revisited MSCN SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(low_bits_2_svd_values[0], label='Noisy')
-plt.plot(low_bits_2_svd_values[1], label='Threshold')
-plt.plot(low_bits_2_svd_values[2], label='Reference')
-plt.ylabel('Low 2 bits SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(low_bits_3_svd_values[0], label='Noisy')
-plt.plot(low_bits_3_svd_values[1], label='Threshold')
-plt.plot(low_bits_3_svd_values[2], label='Reference')
-plt.ylabel('Low 3 bits SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(low_bits_4_svd_values[0], label='Noisy')
-plt.plot(low_bits_4_svd_values[1], label='Threshold')
-plt.plot(low_bits_4_svd_values[2], label='Reference')
-plt.ylabel('Low 4 bits SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(low_bits_5_svd_values[0], label='Noisy')
-plt.plot(low_bits_5_svd_values[1], label='Threshold')
-plt.plot(low_bits_5_svd_values[2], label='Reference')
-plt.ylabel('Low 5 bits SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()
-
-plt.plot(low_bits_6_svd_values[0], label='Noisy')
-plt.plot(low_bits_6_svd_values[1], label='Threshold')
-plt.plot(low_bits_6_svd_values[2], label='Reference')
-plt.ylabel('Low 6 bits SVD')
-plt.xlabel('Vector features')
-plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
-plt.ylim(0, 0.1)
-plt.show()

+ 223 - 0
utils/display_svd_zone_scene.py

@@ -0,0 +1,223 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Sep 14 21:02:42 2018
+
+@author: jbuisine
+"""
+
+from __future__ import print_function
+import sys, os, getopt
+import numpy as np
+import random
+import time
+import json
+
+from PIL import Image
+from ipfml import image_processing
+from ipfml import metrics
+from skimage import color
+
+import matplotlib.pyplot as plt
+
+from data_type_module import get_svd_data
+
+config_filename   = "config"
+zone_folder       = "zone"
+min_max_filename  = "_min_max_values"
+
+# define all scenes values
+scenes_list = ['Appart1opt02', 'Bureau1', 'Cendrier', 'Cuisine01', 'EchecsBas', 'PNDVuePlongeante', 'SdbCentre', 'SdbDroite', 'Selles']
+metric_choices = ['lab', 'mscn', 'mscn_revisited', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6','low_bits_4_shifted_2']
+scenes_indexes = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
+choices = ['svd', 'svdn', 'svdne']
+path = './../fichiersSVD_light'
+zones = np.arange(16)
+seuil_expe_filename = 'seuilExpe'
+
+max_nb_bits = 8
+
+def display_svd_values(p_scene, p_interval, p_zone, p_metric, p_mode):
+    """
+    @brief Method which gives information about svd curves from zone of picture
+    @param p_scene, scene expected to show svd values
+    @param p_interval, interval [begin, end] of samples or minutes from render generation engine
+    @param p_zone, zone's identifier of picture
+    @param p_metric, metric computed to show
+    @param p_mode, normalization's mode
+    @return nothing
+    """
+
+    scenes = os.listdir(path)
+    # remove min max file from scenes folder
+    scenes = [s for s in scenes if min_max_filename not in s]
+
+    begin, end = p_interval
+    data_min_max_filename = os.path.join(path, p_metric + min_max_filename)
+
+    # go ahead each scenes
+    for id_scene, folder_scene in enumerate(scenes):
+
+        if p_scene == folder_scene:
+            print(folder_scene)
+            scene_path = os.path.join(path, folder_scene)
+
+            config_file_path = os.path.join(scene_path, config_filename)
+
+            with open(config_file_path, "r") as config_file:
+                last_image_name = config_file.readline().strip()
+                prefix_image_name = config_file.readline().strip()
+                start_index_image = config_file.readline().strip()
+                end_index_image = config_file.readline().strip()
+                step_counter = int(config_file.readline().strip())
+
+            # construct each zones folder name
+            zones_folder = []
+
+            # get zones list info
+            for index in zones:
+                index_str = str(index)
+                if len(index_str) < 2:
+                    index_str = "0" + index_str
+
+                current_zone = "zone"+index_str
+                zones_folder.append(current_zone)
+
+            zones_images_data = []
+            images_indexes = []
+
+            zone_folder = zones_folder[p_zone]
+
+            zone_path = os.path.join(scene_path, zone_folder)
+
+            current_counter_index = int(start_index_image)
+            end_counter_index = int(end_index_image)
+
+            # get threshold information
+            path_seuil = os.path.join(zone_path, seuil_expe_filename)
+
+            # open treshold path and get this information
+            with open(path_seuil, "r") as seuil_file:
+                seuil_learned = int(seuil_file.readline().strip())
+
+            threshold_image_found = False
+
+            while(current_counter_index <= end_counter_index):
+
+                current_counter_index_str = str(current_counter_index)
+
+                while len(start_index_image) > len(current_counter_index_str):
+                    current_counter_index_str = "0" + current_counter_index_str
+
+
+                if current_counter_index >= begin and current_counter_index <= end:
+                    images_indexes.append(current_counter_index_str)
+
+                if seuil_learned < int(current_counter_index) and not threshold_image_found:
+
+                    threshold_image_found = True
+                    threshold_image_zone = current_counter_index_str
+
+                current_counter_index += step_counter
+
+            # all indexes of picture to plot
+            print(images_indexes)
+
+            for index in images_indexes:
+
+                img_path = os.path.join(scene_path, prefix_image_name + str(index) + ".png")
+
+                current_img = Image.open(img_path)
+                img_blocks = image_processing.divide_in_blocks(current_img, (200, 200))
+
+                # getting expected block id
+                block = img_blocks[p_zone]
+
+                # get data from mode
+                # Here you can add the way you compute data
+                data = get_svd_data(p_metric, block)
+
+                ##################
+                # Data mode part #
+                ##################
+
+                if p_mode == 'svdne':
+
+                    # getting max and min information from min_max_filename
+                    with open(data_min_max_filename, 'r') as f:
+                        min_val = float(f.readline())
+                        max_val = float(f.readline())
+
+                    data = image_processing.normalize_arr_with_range(data, min_val, max_val)
+
+                if p_mode == 'svdn':
+                    data = image_processing.normalize_arr(data)
+
+                zones_images_data.append(data)
+
+            plt.title(p_scene + ' scene interval information ['+ str(begin) +', '+ str(end) +'], ' + p_metric + ' metric, ' + p_mode, fontsize=20)
+            plt.ylabel('Image samples or time (minutes) generation', fontsize=14)
+            plt.xlabel('Vector features', fontsize=16)
+
+            for id, data in enumerate(zones_images_data):
+
+                p_label = p_scene + "_" + images_indexes[0]
+
+                if images_indexes[id] == threshold_image_zone:
+                    plt.plot(data, label=p_label, lw=4)
+                else:
+                    plt.plot(data, label=p_label)
+
+            plt.legend(bbox_to_anchor=(0.5, 1), loc=2, borderaxespad=0.2, fontsize=14)
+            plt.ylim(0, 0.1)
+
+            plt.show()
+
+def main():
+
+    if len(sys.argv) <= 1:
+        print('Run with default parameters...')
+        print('python display_svd_zone_scene.py --scene A --interval "0,200" --zone 3 --metric lab --mode svdne')
+        sys.exit(2)
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hs:i:z:l:m", ["help=", "scene=", "interval=", "zone=", "metric=", "mode="])
+    except getopt.GetoptError:
+        # print help information and exit:
+        print('python display_svd_zone_scene.py --scene A --interval "0,200" --zone 3 --metric lab --mode svdne')
+        sys.exit(2)
+    for o, a in opts:
+        if o == "-h":
+            print('python display_svd_zone_scene.py --scene A --interval "0,200" --zone 3 --metric lab --mode svdne')
+            sys.exit()
+        elif o in ("-s", "--scene"):
+            p_scene = a
+
+            if p_scene not in scenes_indexes:
+                assert False, "Invalid scene choice"
+            else:
+                p_scene = scenes_list[scenes_indexes.index(p_scene)]
+        elif o in ("-i", "--interval"):
+            p_interval = list(map(int, a.split(',')))
+
+        elif o in ("-z", "--zone"):
+            p_zone = int(a)
+
+        elif o in ("-m", "--metric"):
+            p_metric = a
+
+            if p_metric not in metric_choices:
+                assert False, "Invalid metric choice"
+
+        elif o in ("-m", "--mode"):
+            p_mode = a
+
+            if p_mode not in choices:
+                assert False, "Invalid normalization choice, expected ['svd', 'svdn', 'svdne']"
+
+        else:
+            assert False, "unhandled option"
+
+    display_svd_values(p_scene, p_interval, p_zone, p_metric, p_mode)
+
+if __name__== "__main__":
+    main()

+ 0 - 37
utils/show_mscn.py

@@ -1,37 +0,0 @@
-from ipfml import image_processing
-from PIL import Image
-import numpy as np
-from ipfml import metrics
-from skimage import color
-
-import cv2
-
-path_noisy = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00050.png'
-path_threshold = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_00400.png'
-path_ref = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection_In_SynthesisImages/fichiersSVD_light/Cuisine01/cuisine01_01200.png'
-
-path_list = [path_noisy, path_threshold, path_ref]
-labels = ['noisy', 'threshold', 'reference']
-
-for id, p in enumerate(path_list):
-
-    img = Image.open(p)
-    img.show()
-
-    # Revisited MSCN
-    current_img_mscn = image_processing.rgb_to_mscn(img)
-    current_img_output = current_img_mscn.astype('uint8')
-    img_mscn_pil = Image.fromarray(current_img_output.astype('uint8'), 'L')
-    img_mscn_pil.show()
-    img_mscn_pil.save('/home/jbuisine/Downloads/' + labels[id] + '_revisited.png')
-
-
-    # MSCN
-    img_grey = np.array(color.rgb2gray(np.asarray(img))*255, 'uint8')
-
-    img_mscn_in_grey = np.array(image_processing.normalize_2D_arr(image_processing.calculate_mscn_coefficients(img_grey, 7))*255, 'uint8')
-
-    img_mscn_pil = Image.fromarray(img_mscn_in_grey.astype('uint8'), 'L')
-    img_mscn_pil.show()
-    img_mscn_pil.save('/home/jbuisine/Downloads/' + labels[id] + '_mscn.png')
-

+ 2 - 0
utils/show_simulation_curves.py

@@ -4,6 +4,8 @@ import pandas as pd
 import matplotlib.pyplot as plt
 import os, sys
 
+from utils.data_type_module import get_svd_data
+
 label_freq = 6
 folder_path = "Curve_simulations"