|
@@ -13,6 +13,7 @@ import random
|
|
import time
|
|
import time
|
|
import json
|
|
import json
|
|
|
|
|
|
|
|
+from utils.data_type_module import get_svd_data
|
|
from PIL import Image
|
|
from PIL import Image
|
|
from ipfml import image_processing
|
|
from ipfml import image_processing
|
|
from ipfml import metrics
|
|
from ipfml import metrics
|
|
@@ -33,6 +34,7 @@ zones = np.arange(16)
|
|
seuil_expe_filename = 'seuilExpe'
|
|
seuil_expe_filename = 'seuilExpe'
|
|
|
|
|
|
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']
|
|
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']
|
|
|
|
+picture_step = 10
|
|
|
|
|
|
def generate_data_svd(data_type, mode):
|
|
def generate_data_svd(data_type, mode):
|
|
"""
|
|
"""
|
|
@@ -46,7 +48,7 @@ def generate_data_svd(data_type, mode):
|
|
scenes = [s for s in scenes if min_max_filename not in s]
|
|
scenes = [s for s in scenes if min_max_filename not in s]
|
|
|
|
|
|
# keep in memory min and max data found from data_type
|
|
# keep in memory min and max data found from data_type
|
|
- min_val_found = 100000000000
|
|
|
|
|
|
+ min_val_found = sys.maxsize
|
|
max_val_found = 0
|
|
max_val_found = 0
|
|
|
|
|
|
data_min_max_filename = os.path.join(path, data_type + min_max_filename)
|
|
data_min_max_filename = os.path.join(path, data_type + min_max_filename)
|
|
@@ -95,167 +97,108 @@ def generate_data_svd(data_type, mode):
|
|
|
|
|
|
while(current_counter_index <= end_counter_index):
|
|
while(current_counter_index <= end_counter_index):
|
|
|
|
|
|
- current_counter_index_str = str(current_counter_index)
|
|
|
|
|
|
+ if current_counter_index % picture_step == 0:
|
|
|
|
+ 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
|
|
|
|
|
|
+ while len(start_index_image) > len(current_counter_index_str):
|
|
|
|
+ current_counter_index_str = "0" + current_counter_index_str
|
|
|
|
|
|
- img_path = os.path.join(scene_path, prefix_image_name + current_counter_index_str + ".png")
|
|
|
|
|
|
+ img_path = os.path.join(scene_path, prefix_image_name + current_counter_index_str + ".png")
|
|
|
|
|
|
- current_img = Image.open(img_path)
|
|
|
|
- img_blocks = image_processing.divide_in_blocks(current_img, (200, 200))
|
|
|
|
|
|
+ current_img = Image.open(img_path)
|
|
|
|
+ img_blocks = image_processing.divide_in_blocks(current_img, (200, 200))
|
|
|
|
|
|
- for id_block, block in enumerate(img_blocks):
|
|
|
|
|
|
+ for id_block, block in enumerate(img_blocks):
|
|
|
|
|
|
- ###########################
|
|
|
|
- # Metric computation part #
|
|
|
|
- ###########################
|
|
|
|
|
|
+ ###########################
|
|
|
|
+ # Metric computation part #
|
|
|
|
+ ###########################
|
|
|
|
|
|
- # get data from mode
|
|
|
|
- # Here you can add the way you compute data
|
|
|
|
- if data_type == 'lab':
|
|
|
|
|
|
+ data = get_svd_data(data_type, block)
|
|
|
|
|
|
- block_file_path = '/tmp/lab_img.png'
|
|
|
|
- block.save(block_file_path)
|
|
|
|
- data = image_processing.get_LAB_L_SVD_s(Image.open(block_file_path))
|
|
|
|
|
|
+ ##################
|
|
|
|
+ # Data mode part #
|
|
|
|
+ ##################
|
|
|
|
|
|
- if data_type == 'mscn_revisited':
|
|
|
|
|
|
+ # modify data depending mode
|
|
|
|
+ if mode == 'svdne':
|
|
|
|
|
|
- img_mscn_revisited = image_processing.rgb_to_mscn(block)
|
|
|
|
|
|
+ # 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())
|
|
|
|
|
|
- # save tmp as img
|
|
|
|
- img_output = Image.fromarray(img_mscn_revisited.astype('uint8'), 'L')
|
|
|
|
- mscn_revisited_file_path = '/tmp/mscn_revisited_img.png'
|
|
|
|
- img_output.save(mscn_revisited_file_path)
|
|
|
|
- img_block = Image.open(mscn_revisited_file_path)
|
|
|
|
|
|
+ data = image_processing.normalize_arr_with_range(data, min_val, max_val)
|
|
|
|
|
|
- # extract from temp image
|
|
|
|
- data = metrics.get_SVD_s(img_block)
|
|
|
|
|
|
+ if mode == 'svdn':
|
|
|
|
+ data = image_processing.normalize_arr(data)
|
|
|
|
|
|
- if data_type == 'mscn':
|
|
|
|
|
|
+ # save min and max found from dataset in order to normalize data using whole data known
|
|
|
|
+ if mode == 'svd':
|
|
|
|
|
|
- img_gray = np.array(color.rgb2gray(np.asarray(block))*255, 'uint8')
|
|
|
|
- img_mscn = image_processing.calculate_mscn_coefficients(img_gray, 7)
|
|
|
|
- img_mscn_norm = image_processing.normalize_2D_arr(img_mscn)
|
|
|
|
|
|
+ current_min = data.min()
|
|
|
|
+ current_max = data.max()
|
|
|
|
|
|
- img_mscn_gray = np.array(img_mscn_norm*255, 'uint8')
|
|
|
|
|
|
+ if current_min < min_val_found:
|
|
|
|
+ min_val_found = current_min
|
|
|
|
|
|
- data = metrics.get_SVD_s(img_mscn_gray)
|
|
|
|
|
|
+ if current_max > max_val_found:
|
|
|
|
+ max_val_found = current_max
|
|
|
|
|
|
- if data_type == 'low_bits_6':
|
|
|
|
|
|
+ # now write data into current writer
|
|
|
|
+ current_file = svd_output_files[id_block]
|
|
|
|
|
|
- low_bits_6 = image_processing.rgb_to_LAB_L_low_bits(block, 63)
|
|
|
|
|
|
+ # add of index
|
|
|
|
+ current_file.write(current_counter_index_str + ';')
|
|
|
|
|
|
- # extract from temp image
|
|
|
|
- data = metrics.get_SVD_s(low_bits_6)
|
|
|
|
|
|
+ for val in data:
|
|
|
|
+ current_file.write(str(val) + ";")
|
|
|
|
|
|
- if data_type == 'low_bits_5':
|
|
|
|
-
|
|
|
|
- low_bits_5 = image_processing.rgb_to_LAB_L_low_bits(block, 31)
|
|
|
|
-
|
|
|
|
- # extract from temp image
|
|
|
|
- data = metrics.get_SVD_s(low_bits_5)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if data_type == 'low_bits_4':
|
|
|
|
-
|
|
|
|
- low_bits_4 = image_processing.rgb_to_LAB_L_low_bits(block)
|
|
|
|
-
|
|
|
|
- # extract from temp image
|
|
|
|
- data = metrics.get_SVD_s(low_bits_4)
|
|
|
|
-
|
|
|
|
- if data_type == 'low_bits_3':
|
|
|
|
-
|
|
|
|
- low_bits_3 = image_processing.rgb_to_LAB_L_low_bits(block, 7)
|
|
|
|
-
|
|
|
|
- # extract from temp image
|
|
|
|
- data = metrics.get_SVD_s(low_bits_3)
|
|
|
|
-
|
|
|
|
- if data_type == 'low_bits_2':
|
|
|
|
-
|
|
|
|
- low_bits_2 = image_processing.rgb_to_LAB_L_low_bits(block, 3)
|
|
|
|
-
|
|
|
|
- # extract from temp image
|
|
|
|
- data = metrics.get_SVD_s(low_bits_2)
|
|
|
|
-
|
|
|
|
- if data_type == 'low_bits_4_shifted_2':
|
|
|
|
-
|
|
|
|
- data = metrics.get_SVD_s(image_processing.rgb_to_LAB_L_bits(block, (3, 6)))
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- ##################
|
|
|
|
- # Data mode part #
|
|
|
|
- ##################
|
|
|
|
-
|
|
|
|
- # modify data depending mode
|
|
|
|
- if 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 mode == 'svdn':
|
|
|
|
- data = image_processing.normalize_arr(data)
|
|
|
|
-
|
|
|
|
- # save min and max found from dataset in order to normalize data using whole data known
|
|
|
|
- if mode == 'svd':
|
|
|
|
-
|
|
|
|
- current_min = data.min()
|
|
|
|
- current_max = data.max()
|
|
|
|
-
|
|
|
|
- if current_min < min_val_found:
|
|
|
|
- min_val_found = current_min
|
|
|
|
-
|
|
|
|
- if current_max > max_val_found:
|
|
|
|
- max_val_found = current_max
|
|
|
|
-
|
|
|
|
- # now write data into current writer
|
|
|
|
- current_file = svd_output_files[id_block]
|
|
|
|
-
|
|
|
|
- # add of index
|
|
|
|
- current_file.write(current_counter_index_str + ';')
|
|
|
|
-
|
|
|
|
- for val in data:
|
|
|
|
- current_file.write(str(val) + ";")
|
|
|
|
-
|
|
|
|
- current_file.write('\n')
|
|
|
|
|
|
+ current_file.write('\n')
|
|
|
|
|
|
start_index_image_int = int(start_index_image)
|
|
start_index_image_int = int(start_index_image)
|
|
print(data_type + "_" + mode + "_" + folder_scene + " - " + "{0:.2f}".format((current_counter_index - start_index_image_int) / (end_counter_index - start_index_image_int)* 100.) + "%")
|
|
print(data_type + "_" + mode + "_" + folder_scene + " - " + "{0:.2f}".format((current_counter_index - start_index_image_int) / (end_counter_index - start_index_image_int)* 100.) + "%")
|
|
|
|
+ sys.stdout.write("\033[F")
|
|
|
|
+
|
|
current_counter_index += step_counter
|
|
current_counter_index += step_counter
|
|
|
|
|
|
for f in svd_output_files:
|
|
for f in svd_output_files:
|
|
f.close()
|
|
f.close()
|
|
|
|
|
|
|
|
+ print('\n')
|
|
|
|
+
|
|
# save current information about min file found
|
|
# save current information about min file found
|
|
if mode == 'svd':
|
|
if mode == 'svd':
|
|
with open(data_min_max_filename, 'w') as f:
|
|
with open(data_min_max_filename, 'w') as f:
|
|
f.write(str(min_val_found) + '\n')
|
|
f.write(str(min_val_found) + '\n')
|
|
f.write(str(max_val_found) + '\n')
|
|
f.write(str(max_val_found) + '\n')
|
|
|
|
|
|
- print("End of data generation")
|
|
|
|
|
|
+ print("%s : end of data generation\n" % _mode)
|
|
|
|
|
|
|
|
|
|
def main():
|
|
def main():
|
|
|
|
|
|
|
|
+ # default value of p_step
|
|
|
|
+ p_step = 10
|
|
|
|
+
|
|
if len(sys.argv) <= 1:
|
|
if len(sys.argv) <= 1:
|
|
print('Run with default parameters...')
|
|
print('Run with default parameters...')
|
|
print('python generate_all_data.py --metric all')
|
|
print('python generate_all_data.py --metric all')
|
|
print('python generate_all_data.py --metric lab')
|
|
print('python generate_all_data.py --metric lab')
|
|
|
|
+ print('python generate_all_data.py --metric lab --step 10')
|
|
sys.exit(2)
|
|
sys.exit(2)
|
|
try:
|
|
try:
|
|
- opts, args = getopt.getopt(sys.argv[1:], "hm", ["help=", "metric="])
|
|
|
|
|
|
+ opts, args = getopt.getopt(sys.argv[1:], "hms", ["help=", "metric=", "step="])
|
|
except getopt.GetoptError:
|
|
except getopt.GetoptError:
|
|
# print help information and exit:
|
|
# print help information and exit:
|
|
- print('python generate_all_data.py --metric all')
|
|
|
|
|
|
+ print('python generate_all_data.py --metric all --step 10')
|
|
sys.exit(2)
|
|
sys.exit(2)
|
|
for o, a in opts:
|
|
for o, a in opts:
|
|
if o == "-h":
|
|
if o == "-h":
|
|
- print('python generate_all_data.py --metric all')
|
|
|
|
|
|
+ print('python generate_all_data.py --metric all --step 10')
|
|
sys.exit()
|
|
sys.exit()
|
|
|
|
+ elif o in ("-s", "--step"):
|
|
|
|
+ p_step = int(a)
|
|
elif o in ("-m", "--metric"):
|
|
elif o in ("-m", "--metric"):
|
|
p_metric = a
|
|
p_metric = a
|
|
|
|
|
|
@@ -264,6 +207,12 @@ def main():
|
|
else:
|
|
else:
|
|
assert False, "unhandled option"
|
|
assert False, "unhandled option"
|
|
|
|
|
|
|
|
+ global picture_step
|
|
|
|
+ picture_step = p_step
|
|
|
|
+
|
|
|
|
+ if picture_step % 10 != 0:
|
|
|
|
+ assert False, "Picture step variable needs to be divided by ten"
|
|
|
|
+
|
|
# generate all or specific metric data
|
|
# generate all or specific metric data
|
|
if p_metric == 'all':
|
|
if p_metric == 'all':
|
|
for m in metric_choices:
|
|
for m in metric_choices:
|