Parcourir la source

Visualization scripts updated

Jérôme BUISINE il y a 5 ans
Parent
commit
b9f38d55fd

+ 33 - 1
README.md

@@ -13,6 +13,36 @@ Noise list :
 - salt_pepper
 - white
 
+
+## Generate all data
+
+### Step 1.
+
+First of all you need to generate all noise of each images in **/generated** folder.
+
+```
+bash generate_all_noise.sh
+```
+
+### Step 2.
+
+Once you had generate all noisy images from synthesis scenes, you need to extract features (SVD singular values) using different metrics.
+
+```
+python generate_all_data.py --metric all --step 40 --color 0
+python generate_all_data.py --metric all --step 40 --color 1
+```
+
+### Step 3.
+
+You can display curves of each noise for each scene :
+
+```
+bash generate_noise_all_curves.sh
+```
+
+This will give you some information about SVD singular values obtained from noise applied synthesis images. All these curves are available into **curves_pictures** folder after running script.
+
 ## Scripts
 
 ### noise_computation.py
@@ -28,6 +58,7 @@ Parameters :
 - **image** : source path of the image we want to add noise
 - **n** : level of noise to use
 - **identical** : same noise or not for each chanel in case of RGB image
+- **step** : interval of identifier between each image kept
 - **output** : output image name wanted
 - **all** : generate all level noise from 1 to **n**
 - **p** : optional parameter only used for salt and pepper noise
@@ -44,11 +75,12 @@ python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric
 Parameters :
 - **prefix** : specify the folder of image for specific noise 
 - **metric** : metric choice to compute in order to extract SVD data
+- **n** : limit identifier to use for image scene 
 - **mode** : level of normalization ['svd', 'svdn', 'svdne']
 - **interval** : features to display from singular values vector
 - **step** : interval of noise to keep for display 
 - **norm** : normalization between only values kept from interval
+- **color** : specify if we use 3 chanels with different noise or with same noise
 - **ylim** : ylim to use in order to display curves
 
 
-

+ 11 - 8
generate_noise_all_curves.sh

@@ -7,14 +7,17 @@ for file in "images"/*; do
 
     image=${ADDR[1]%".png"}
 
-    for metric in {"lab","mscn","mscn_revisited","low_bits_2","low_bits_3","low_bits_4", "low_bits_5","low_bits_6","low_bits_4_shifted_2"}; do
-        for noise in {"cauchy","gaussian","laplace","log_normal","mut_white","white","salt_pepper"}; do
-            for mode in {"svdn","svdne"}; do
-                 python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 200" --step 40 --norm 0 --ylim "0, 0.05"
-                 python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 200" --step 40 --norm 1 --ylim "0, 0.1"
-                 python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 200" --step 40 --norm 0 --color 1 --ylim "0, 0.05"
-                 python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 200" --step 40 --norm 1 --color 1 --ylim "0, 0.1"
+    if [[ "$image" != "calibration" ]]; then
+
+        for metric in {"lab","mscn_revisited","low_bits_2","low_bits_3","low_bits_4", "low_bits_5","low_bits_6","low_bits_4_shifted_2"}; do
+            for noise in {"cauchy","gaussian","laplace","log_normal","mut_white","white","salt_pepper"}; do
+                for mode in {"svdn","svdne"}; do
+                     python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 800" --step 40 --norm 0 --ylim "0, 0.05"
+                     python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 800" --step 40 --norm 1 --ylim "0, 0.1"
+                     python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 800" --step 40 --norm 0 --color 1 --ylim "0, 0.05"
+                     python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode ${mode} --interval "0, 800" --step 40 --norm 1 --color 1 --ylim "0, 0.1"
+                done
             done
-        done
     done
+    fi
 done

+ 1 - 1
modules/utils/config.py

@@ -28,7 +28,7 @@ maxwell_scenes_indices          = ['A', 'D', 'G', 'H']
 normalization_choices           = ['svd', 'svdn', 'svdne']
 zones_indices                   = np.arange(16)
 
-metric_choices_labels           = ['lab', 'mscn', 'mscn_revisited', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6','low_bits_4_shifted_2']
+metric_choices_labels           = ['lab', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6','low_bits_4_shifted_2']
 
 # noise information
 noise_labels                    = ['cauchy', 'gaussian', 'laplace', 'log_normal', 'mut_white', 'salt_pepper', 'white']

+ 7 - 2
modules/utils/data_type.py

@@ -2,6 +2,7 @@ from ipfml import processing, metrics
 from PIL import Image
 from skimage import color
 
+import random
 import numpy as np
 
 def get_svd_data(data_type, block):
@@ -11,17 +12,21 @@ def get_svd_data(data_type, block):
 
     if data_type == 'lab':
 
-        block_file_path = '/tmp/lab_img.png'
+        nb = random.randint(0, 10)
+
+        block_file_path = '/tmp/' + str(nb) + '_lab_img.png'
         block.save(block_file_path)
         data = processing.get_LAB_L_SVD_s(Image.open(block_file_path))
 
     if data_type == 'mscn_revisited':
 
+        nb = random.randint(0, 10)
+
         img_mscn_revisited = processing.rgb_to_mscn(block)
 
         # save tmp as img
         img_output = Image.fromarray(img_mscn_revisited.astype('uint8'), 'L')
-        mscn_revisited_file_path = '/tmp/mscn_revisited_img.png'
+        mscn_revisited_file_path = '/tmp/' + str(nb) + '_mscn_revisited_img.png'
         img_output.save(mscn_revisited_file_path)
         img_block = Image.open(mscn_revisited_file_path)
 

+ 0 - 1
noise_computation.py

@@ -88,7 +88,6 @@ def main():
 
         for i in range(1, p_n):
 
-            print(i)
             if i % p_step == 0:
                 p_filename = split_output[0] + "_" + str(i) + "." + filename_ext
 

+ 25 - 21
noise_svd_visualization.py

@@ -16,6 +16,8 @@ metric_choices        = cfg.metric_choices_labels
 normalization_choices = cfg.normalization_choices
 pictures_folder       = cfg.pictures_output_folder
 
+step_picture          = 10
+
 def main():
 
     # default values
@@ -28,17 +30,17 @@ def main():
     min_value_svd = sys.maxsize
 
     if len(sys.argv) <= 1:
-        print('python noise_svd_visualization.py --prefix generated/noise/prefix --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --color 1 --norm 1 --ylim "0, 1"')
+        print('python noise_svd_visualization.py --prefix generated/prefix/noise --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --color 1 --norm 1 --ylim "0, 1"')
         sys.exit(2)
     try:
         opts, args = getopt.getopt(sys.argv[1:], "h:p:m:m:n:i:s:c:n:y", ["help=", "prefix=", "metric=", "mode=", "n=", "interval=", "step=", "color=", "norm=", "ylim="])
     except getopt.GetoptError:
         # print help information and exit:
-        print('python noise_svd_visualization.py --prefix generated/noise/prefix --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --color 1 --norm 1 --ylim "0, 1"')
+        print('python noise_svd_visualization.py --prefix generated/prefix/noise --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --color 1 --norm 1 --ylim "0, 1"')
         sys.exit(2)
     for o, a in opts:
         if o == "-h":
-            print('python noise_svd_visualization.py --prefix generated/noise/prefix --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --color 1 --norm 1 --ylim "0, 1"')
+            print('python noise_svd_visualization.py --prefix generated/prefix/noise --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --color 1 --norm 1 --ylim "0, 1"')
             sys.exit()
         elif o in ("-p", "--prefix"):
             p_path = a
@@ -71,12 +73,12 @@ def main():
 
 
     p_prefix = p_path.split('/')[1].replace('_', '')
-    noise_name = p_path.split('/')[2].replace('_', '')
+    noise_name = p_path.split('/')[2]
 
     if p_color:
-        file_path = p_path + "/" + p_prefix + "_{}_color." + filename_ext
+        file_path = p_path + "/" + p_prefix + "_" + noise_name + "_color_{}." + filename_ext
     else:
-        file_path = p_path + "/" + p_prefix + "_{}." + filename_ext
+        file_path = p_path + "/" + p_prefix + "_" + noise_name + "_{}." + filename_ext
 
     begin, end = p_interval
     all_svd_data = []
@@ -87,32 +89,34 @@ def main():
     # get all data from images
     for i in range(1, p_n):
 
-        image_path = file_path.format(str(i))
-        img = Image.open(image_path)
+        if i % step_picture == 0:
+
+            image_path = file_path.format(str(i))
+            img = Image.open(image_path)
 
-        svd_values = dt.get_svd_data(p_metric, img)
+            svd_values = dt.get_svd_data(p_metric, img)
 
-        if p_norm:
-            svd_values = svd_values[begin:end]
+            if p_norm:
+                svd_values = svd_values[begin:end]
 
-        all_svd_data.append(svd_values)
+            all_svd_data.append(svd_values)
 
-        # update min max values
-        min_value = svd_values.min()
-        max_value = svd_values.max()
+            # update min max values
+            min_value = svd_values.min()
+            max_value = svd_values.max()
 
-        if min_value < min_value_svd:
-            min_value_svd = min_value
+            if min_value < min_value_svd:
+                min_value_svd = min_value
 
-        if max_value > min_value_svd:
-            max_value_svd = max_value
+            if max_value > min_value_svd:
+                max_value_svd = max_value
 
         print('%.2f%%' % ((i + 1) / p_n * 100))
         sys.stdout.write("\033[F")
 
     for id, data in enumerate(all_svd_data):
 
-        if id % p_step == 0:
+        if (id * step_picture) % p_step == 0:
 
             current_data = data
             if p_mode == 'svdn':
@@ -122,7 +126,7 @@ def main():
                 current_data = processing.normalize_arr_with_range(current_data, min_value_svd, max_value_svd)
 
             svd_data.append(current_data)
-            image_indices.append(id)
+            image_indices.append(str(id * step_picture))
 
     # display all data using matplotlib (configure plt)