<jupyter_start><jupyter_text>SVD analysis on zones of Synthesis Images   Utils functions definition<jupyter_code>def compute_images_path(dict_data):
    scene = dict_data['name']
    prefix = dict_data['prefix']
    indices = dict_data['indices']
    
    images_path = []
    for index in indices:
        path = os.path.join(data_folder, os.path.join(scene, prefix + index + ".png"))
        print(path)
        images_path.append(path)
    return images_path
def get_images_zones(dict_data, images_path):
    
    zones_indices = dict_data['zones']
    zones_img = []
    
    for path in images_path:
        img = Image.open(path)
        zones = processing.divide_in_blocks(img, (200, 200))
        
        zones_list = []
        
        for id_zone in zones_indices:
            zones_list.append(zones[id_zone])
            
        zones_img.append(zones_list)
        
    return zones_img
def display_sv_data(dict_data, zones_data, interval, _norm=False):
    
    scene_name = dict_data['name']
    image_indices = dict_data['indices']
    zones_indices = dict_data['zones']
    colors = ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9']
    
    plt.figure(figsize=(25, 20))
    
    sv_data = []
    begin, end = interval
    for id_img, zones in enumerate(zones_data):
        
        for id_zone, zone in enumerate(zones):
            U, s, V = processing.get_LAB_L_SVD(zone)
        
            data = s[begin:end]
            
            if _norm:
                data = utils.normalize_arr(data)
                
            plt.plot(data, 
                     color=colors[id_zone], 
                     label='Zone ' + str(zones_indices[id_zone]) + ' of ' + scene_name + '_' + str(image_indices[id_img]))
            
    plt.legend(fontsize=18)
    plt.show()
# Useful function

def get_highest_values(arr, n):
    return np.array(arr).argsort()[-n:][::-1]

def get_lowest_values(arr, n):
    return np.array(arr).argsort()[::-1][-n:][::-1]
def get_entropy(arr):
    arr = np.array(arr)
    eigen_values = []
    sum_eigen_values = (arr * arr).sum()
    print(sum_eigen_values)

    for id, val in enumerate(arr):
        eigen_values.append(val * val)
        #print(id, " : ", val)

    v = []

    for val in eigen_values:
        v.append(val / sum_eigen_values)

    entropy = 0

    for val in v:
        if val > 0:
            entropy += val * math.log(val)

    entropy *= -1

    entropy /= math.log(len(v))
    
    return entropy


def get_entropy_without_i(arr, i):
    
    arr = np.array([v for index, v in enumerate(arr) if index != i])

    return get_entropy(arr)

def get_entropy_contribution_of_i(arr, i):

    return get_entropy(arr) - get_entropy_without_i(arr, i)<jupyter_output><empty_output><jupyter_text>Scenes zones data<jupyter_code># start 00020 - ref 00900 - step 10
dict_appart = {'name': 'Appart1opt02', 
               'prefix': 'appartAopt_', 
               'indices': ["00020", "00200", "00900"],
               'zones': [3, 6]}

# start 00050 - ref 01200 - step 10
dict_cuisine = {'name': 'Cuisine01', 
               'prefix': 'cuisine01_', 
               'indices': ["00050", "00400", "01200"],
               'zones': [3, 6]}

# start 00020 - ref 00950 - step 10
dict_sdb_c = {'name': 'SdbCentre', 
               'prefix': 'SdB2_', 
               'indices': ["00020", "00400", "00950"],
               'zones': [3, 6]}

# start 00020 - ref 00950 - step 10
dict_sdb_d = {'name': 'SdbDroite', 
               'prefix': 'SdB2_D_', 
               'indices': ["00020", "00400", "00950"],
               'zones': [2, 3, 10, 13]}
current_dict = dict_appart
interval = (30, 200)
images_path = compute_images_path(current_dict)
zones_data = get_images_zones(current_dict, images_path)
first_image = zones_data[0][0]
# first_image = metrics.get_LAB_L(first_image)

# print(first_image[0:2, 0:2])
# Image.fromarray(first_image).show()

# first_image = np.asarray(Image.fromarray(first_image).convert('L'))
#first_image.show()

entropy_contribution_data = []

sv = processing.get_LAB_L_SVD_s(first_image)
# sv = utils.normalize_arr(sv)
#entropy = get_entropy(sv)

#for i in range(200):
entropy_contribution_data.append(get_entropy_without_i(sv, 0))
print(0, ": ", get_entropy_without_i(sv, 0))
sub_blocks = processing.divide_in_blocks(first_image, (2,2))
sub_block = np.asarray(sub_blocks[0])
sub_block

sv_values = processing.get_LAB_L_SVD_s(sub_block)
print(sub_block)
print(sv_values)
get_highest_values(entropy_contribution_data, 100)
get_lowest_values(entropy_contribution_data, 100)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1367893705075147, 'fraction_numerical': 0.03986059681986495, 'mean_word_length': 2.8107883817427384, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '121691', 'license': 'MIT', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1635, 'n_words': 317, 'path': 'analysis/svd_entropy_analysis_convergence.ipynb', 'repo_name': 'prise-3d/Thesis-NoiseDetection-metrics', 'size': '4591'}