8
8
import threading
9
9
import queue
10
10
import matplotlib .pyplot as plt
11
- from dct_module import compare_dct2_algorithms
11
+ from dct_module import compare_dct2_algorithms , dct2_manual
12
12
13
13
def load_image ():
14
14
file_path = filedialog .askopenfilename (filetypes = [("BMP files" , "*.bmp" )])
@@ -28,6 +28,10 @@ def load_image():
28
28
try :
29
29
F = int (f_entry .get () or 10 )
30
30
d = int (d_entry .get () or 7 )
31
+
32
+ if d > 2 * F - 2 :
33
+ messagebox .showerror ("Error" , f"Invalid value for d. It should be at most 2F-2 ({ 2 * F - 2 } )." )
34
+ return
31
35
except ValueError :
32
36
messagebox .showerror ("Error" , "Invalid F or d value" )
33
37
return
@@ -37,8 +41,8 @@ def load_image():
37
41
if compressed_file_path :
38
42
compressed_size = os .path .getsize (compressed_file_path )
39
43
compression_ratio = 100 * (original_size - compressed_size ) / original_size
40
- compression_label .configure (text = f"Dimensione originale: { original_size } bytes = { round (original_size / (1024 * 1024 ), 2 ) } MB\n "
41
- f"Dimensione compressa: { compressed_size } bytes = { round (compressed_size / (1024 * 1024 ), 2 ) } MB\n "
44
+ compression_label .configure (text = f"Dimensione originale: { original_size } bytes = { round (original_size / (1024 * 1024 ), 4 ) } MB\n "
45
+ f"Dimensione compressa: { compressed_size } bytes = { round (compressed_size / (1024 * 1024 ), 4 ) } MB\n "
42
46
f"Compressione: { compression_ratio :.2f} %" )
43
47
44
48
compressed_image = Image .open (compressed_file_path )
@@ -103,9 +107,13 @@ def test_dct2():
103
107
], dtype = np .float32 )
104
108
105
109
result_dct2 = dct2 (test_matrix )
110
+ result_manualdct2 = dct2_manual (test_matrix )
106
111
107
112
print ("Result of dct2:" )
108
113
print (result_dct2 )
114
+ print ("Result of the implemented dct2 :" )
115
+ print (result_manualdct2 )
116
+
109
117
110
118
def dct2 (matrix ):
111
119
return dct (dct (matrix .T , norm = 'ortho' ).T , norm = 'ortho' )
@@ -129,10 +137,17 @@ def dct2(matrix):
129
137
resolution_label = ctk .CTkLabel (dct_frame , text = "" )
130
138
resolution_label .pack (pady = 10 )
131
139
140
+ f_label = ctk .CTkLabel (dct_frame , text = "Valore di F:" )
141
+ f_label .pack (pady = 5 )
132
142
f_entry = ctk .CTkEntry (dct_frame )
133
143
f_entry .insert (0 , "10" )
144
+ f_entry .pack (pady = 5 )
145
+
146
+ d_label = ctk .CTkLabel (dct_frame , text = "Valore di d:" )
147
+ d_label .pack (pady = 5 )
134
148
d_entry = ctk .CTkEntry (dct_frame )
135
149
d_entry .insert (0 , "7" )
150
+ d_entry .pack (pady = 5 )
136
151
137
152
load_button = ctk .CTkButton (dct_frame , text = "Load .bmp image" , command = load_image )
138
153
file_label = ctk .CTkLabel (dct_frame , text = "Nessun file selezionato" )
@@ -143,8 +158,6 @@ def dct2(matrix):
143
158
144
159
img_label = ctk .CTkLabel (image_frame , text = "" )
145
160
compressed_img_label = ctk .CTkLabel (image_frame , text = "" )
146
- f_entry .pack (pady = 10 )
147
- d_entry .pack (pady = 10 )
148
161
load_button .pack (pady = 10 )
149
162
file_label .pack (pady = 10 )
150
163
compression_label .pack (pady = 10 )
0 commit comments