Parcourir la source

Update of documentation; Update of noise displayed

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

+ 52 - 1
README.md

@@ -1,3 +1,54 @@
 # NoiseAnalysis
 
-Analysis of different noise using SVD compression
+## Description
+
+Analysis of different noises using singular values vector obtained from SVD compression.
+
+Noise list :
+- cauchy
+- gaussian
+- laplace
+- log_normal
+- mut_white
+- salt_pepper
+- white
+
+## Scripts
+
+### noise_computation.py
+
+This script is used to compute all noise for each image in the **images** folder.
+
+```
+python noise_computation.py --noise salt_pepper --image path/to/image.png --n 1000 --identical 1 --output image_salt_pepper.png --all 1 --p 0.1
+```
+
+Parameters :
+- **noise** : specify the noise to use (one available from the list above)
+- **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
+- **output** : output image name wanted
+- **all** : generate all level noise from 1 to **n**
+- **p** : optional parameter only used for salt and pepper noise
+
+
+### noise_svd_visualization.py
+
+This script is used to display noise for each level of noise of image.
+
+```
+python noise_svd_visualization.py  --prefix generated/${image}/${noise} --metric lab --n 1000 --mode svdne --interval "0, 200" --step 40 --norm 0 --ylim "0, 0.05"
+```
+
+Parameters :
+- **prefix** : specify the folder of image for specific noise 
+- **metric** : metric choice to compute in order to extract SVD data
+- **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
+- **ylim** : ylim to use in order to display curves
+
+
+

+ 0 - 24
generate_all.sh

@@ -1,24 +0,0 @@
-for noise in {"cauchy","gaussian","laplace","log_normal","mut_white","white"}; do
-
-    for identical in {"0","1"}; do
-
-        if [ ${identical} == "1" ]; then
-            python noise_computation.py --noise ${noise} --image images/calibration.png --n 1000 --identical ${identical} --output ${noise}.png --all 1 &
-        else
-            python noise_computation.py --noise ${noise} --image images/calibration.png --n 1000 --identical ${identical} --output ${noise}_color.png --all 1 &
-        fi
-
-    done
-done
-
-
-# specifig for salt and pepper noise
-for identical in {"0","1"}; do
-    if [ ${identical} == "1" ]; then
-        python noise_computation.py --noise salt_pepper --image images/calibration.png --n 1000 --identical ${identical} --output salt_pepper_B.png --all 1 --p 0.1 &
-        python noise_computation.py --noise salt_pepper --image images/calibration.png --n 1000 --identical ${identical} --output salt_pepper_A.png --all 1 --p 0.01 &
-    else
-        python noise_computation.py --noise salt_pepper --image images/calibration.png --n 1000 --identical ${identical} --output salt_pepper_A_color.png --all 1 --p 0.01 &
-        python noise_computation.py --noise salt_pepper --image images/calibration.png --n 1000 --identical ${identical} --output salt_pepper_B_color.png --all 1 --p 0.1 &
-    fi
-done

+ 32 - 0
generate_all_noise.sh

@@ -0,0 +1,32 @@
+
+for file in "images"/*; do
+
+    IFS='/' # space is set as delimiter
+    read -ra ADDR <<< "$file" # str is read into an array as tokens separated by IFS
+    IFS=' '
+
+    image=${ADDR[1]}
+
+    for noise in {"cauchy","gaussian","laplace","log_normal","mut_white","white"}; do
+
+        for identical in {"0","1"}; do
+
+            if [ ${identical} == "1" ]; then
+                python noise_computation.py --noise ${noise} --image ${file} --n 1000 --identical ${identical} --output ${image}_${noise}.png --all 1 &
+            else
+                python noise_computation.py --noise ${noise} --image ${file} --n 1000 --identical ${identical} --output ${image}_${noise}_color.png --all 1 &
+            fi
+
+        done
+    done
+
+
+    # specific for salt and pepper noise
+    for identical in {"0","1"}; do
+        if [ ${identical} == "1" ]; then
+            python noise_computation.py --noise salt_pepper --image ${file} --n 1000 --identical ${identical} --output ${image}_salt_pepper.png --all 1 --p 0.1 &
+        else
+            python noise_computation.py --noise salt_pepper --image ${file} --n 1000 --identical ${identical} --output ${image}_salt_pepper_color.png --all 1 --p 0.1 &
+        fi
+    done
+done

+ 19 - 0
generate_noise_all_curves.sh

@@ -0,0 +1,19 @@
+
+for file in "images"/*; do
+
+    IFS='/' # space is set as delimiter
+    read -ra ADDR <<< "$file" # str is read into an array as tokens separated by IFS
+    IFS=' '
+
+    image=${ADDR[1]}
+
+
+    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 1 --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 --ylim --color 1 "0, 0.1"
+        done
+    done
+done

BIN
images/SdB2.png


BIN
images/SdB2_D.png


BIN
images/appartAopt.png


BIN
images/bureau1.png


BIN
images/cendrierIUT2.png


BIN
images/cuisine01.png


BIN
images/echecs.png


BIN
images/pnd.png


BIN
images/selles_envir.png


+ 3 - 1
noise_computation.py

@@ -14,7 +14,9 @@ def generate_noisy_image(p_image, p_n, p_noise, p_identical, p_output, p_param):
     noisy_image = noise.get_noise_result(p_image, p_n, _noise_choice=p_noise, _identical=p_identical, _p=p_param)
     noisy_image = Image.fromarray(noisy_image)
 
-    output_path = os.path.join(generated_folder, p_noise)
+    image_folder = p_image.filename.split('/')[-1].replace('.' + filename_ext, '')
+
+    output_path = os.path.join(os.path.join(generated_folder, image_folder), p_noise)
 
     if not os.path.exists(output_path):
         os.makedirs(output_path)

+ 44 - 17
noise_svd_visualization.py

@@ -18,25 +18,30 @@ pictures_folder       = cfg.pictures_output_folder
 
 def main():
 
+    # default values
     p_step = 1
+    p_color = 0
+    p_norm = 0
+    p_ylim = (0, 1)
+
     max_value_svd = 0
     min_value_svd = sys.maxsize
 
     if len(sys.argv) <= 1:
-        print('python noise_svd_visualization.py --prefix path/with/prefix --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --output filename')
+        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"')
         sys.exit(2)
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "h:p:m:m:n:i:s:o", ["help=", "prefix=", "metric=", "mode=", "n=", "interval=", "step=", "output="])
+        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 path/with/prefix --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --output filename')
+        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"')
         sys.exit(2)
     for o, a in opts:
         if o == "-h":
-            print('python noise_svd_visualization.py --prefix path/with/prefix --metric lab --mode svdn --n 300 --interval "0, 200" --step 30 --output filename')
+            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"')
             sys.exit()
         elif o in ("-p", "--prefix"):
-            p_prefix = a
+            p_path = a
         elif o in ("-m", "--mode"):
             p_mode = a
 
@@ -51,19 +56,27 @@ def main():
 
         elif o in ("-n", "--n"):
             p_n = int(a)
+        elif o in ("-n", "--norm"):
+            p_norm = int(a)
+        elif o in ("-c", "--color"):
+            p_color = int(a)
         elif o in ("-i", "--interval"):
             p_interval = list(map(int, a.split(',')))
         elif o in ("-s", "--step"):
             p_step = int(a)
-        elif o in ("-o", "--output"):
-            p_output = a
+        elif o in ("-y", "--ylim"):
+            p_ylim = list(map(float, a.split(',')))
         else:
             assert False, "unhandled option"
 
 
-    noise_name = p_prefix.split('/')[1].replace('_', '')
+    p_prefix = p_path.split('/')[1].replace('_', '')
+    noise_name = p_path.split('/')[2].replace('_', '')
 
-    file_path = p_prefix + "{}." + filename_ext
+    if p_color:
+        file_path = p_path + "/" + p_prefix + "_{}_color." + filename_ext
+    else:
+        file_path = p_path + "/" + p_prefix + "_{}." + filename_ext
 
     begin, end = p_interval
     all_svd_data = []
@@ -78,7 +91,10 @@ def main():
         img = Image.open(image_path)
 
         svd_values = dt.get_svd_data(p_metric, img)
-        svd_values = svd_values[begin:end]
+
+        if p_norm:
+            svd_values = svd_values[begin:end]
+
         all_svd_data.append(svd_values)
 
         # update min max values
@@ -94,7 +110,6 @@ def main():
         print('%.2f%%' % ((i + 1) / p_n * 100))
         sys.stdout.write("\033[F")
 
-    print("Generation of output figure...")
     for id, data in enumerate(all_svd_data):
 
         if id % p_step == 0:
@@ -109,9 +124,11 @@ def main():
             svd_data.append(current_data)
             image_indices.append(id)
 
-    # display all data using matplotlib
+    # display all data using matplotlib (configure plt)
+
+    plt.rcParams['figure.figsize'] = (25, 18)
 
-    plt.title(noise_name  + ' noise, interval information ['+ str(begin) +', '+ str(end) +'], ' + p_metric + ' metric, step ' + str(p_step), fontsize=20)
+    plt.title(p_prefix  + ' noise, interval information ['+ str(begin) +', '+ str(end) +'], ' + p_metric + ' metric, step ' + str(p_step) + ' normalization ' + p_mode, fontsize=20)
     plt.ylabel('Importance of noise [1, 999]', fontsize=14)
     plt.xlabel('Vector features', fontsize=16)
 
@@ -121,16 +138,26 @@ def main():
         plt.plot(data, label=p_label)
 
     plt.legend(bbox_to_anchor=(0.8, 1), loc=2, borderaxespad=0.2, fontsize=14)
-    plt.ylim(0, 0.1)
-    plt.show()
 
-    output_filename = noise_name + "1_to_" + str(p_n) + "_B" + str(begin) + "_E" + str(end) + "_" + p_metric + "_S" + str(p_step) + "_" + p_mode
+    if not p_norm:
+        plt.xlim(begin, end)
+
+    # adapt ylim
+    y_begin, y_end = p_ylim
+    plt.ylim(y_begin, y_end)
+
+    output_filename = p_prefix + "_" + noise_name + "_1_to_" + str(p_n) + "_B" + str(begin) + "_E" + str(end) + "_" + p_metric + "_S" + str(p_step) + "_norm" + str(p_norm )+  "_" + p_mode
+
+    if p_color:
+        output_filename = output_filename + '_color'
+
+    print("Generation of output figure... %s" % output_filename)
     output_path = os.path.join(pictures_folder, output_filename)
 
     if not os.path.exists(pictures_folder):
         os.makedirs(pictures_folder)
 
-    plt.savefig(output_path)
+    plt.savefig(output_path, dpi=(200))