Commit c34f9bd7 authored by Bryce Hepner's avatar Bryce Hepner

modified code so now it calculates total

parent 45e246f4
...@@ -191,7 +191,11 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True): ...@@ -191,7 +191,11 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True):
for _, tiff_image_path in enumerate(tiff_image_path_list): for _, tiff_image_path in enumerate(tiff_image_path_list):
# get the image_array, etc # get the image_array, etc
image_array, diff, error= predict_pix(tiff_image_path, difference) image_array, diff, error= predict_pix(tiff_image_path, difference)
# plt.hist(np.ravel(image_array), bins=30)
# plt.xlabel('Pixel Value')
# plt.ylabel('Frequency')
# plt.title('Histogram of Pixel Values')
# plt.show()
bins = [21,32,48] bins = [21,32,48]
# get the boundary # get the boundary
boundary = np.hstack((image_array[0,:],image_array[-1,:],image_array[1:-1,0],image_array[1:-1,-1])) boundary = np.hstack((image_array[0,:],image_array[-1,:],image_array[1:-1,0],image_array[1:-1,-1]))
...@@ -234,6 +238,11 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True): ...@@ -234,6 +238,11 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True):
mask = diff > bins[-1] mask = diff > bins[-1]
for j in error[mask].astype(int): for j in error[mask].astype(int):
list_of_all_vals[-1].append(str(j)) list_of_all_vals[-1].append(str(j))
# plt.hist([int(i) for i in list_of_all_vals[2]], bins=30)
# plt.xlabel("Error")
# plt.ylabel("Frequency")
# plt.title("Histogram of Errors")
# plt.show()
for item in list_of_all_vals: for item in list_of_all_vals:
freq = dict(Counter(item)) freq = dict(Counter(item))
freq = sorted(freq.items(), key=lambda x: x[1], reverse=True) freq = sorted(freq.items(), key=lambda x: x[1], reverse=True)
...@@ -490,10 +499,11 @@ def bytes_to_bitstring(input_bytearray): ...@@ -490,10 +499,11 @@ def bytes_to_bitstring(input_bytearray):
scenes = file_extractor(folder_name) scenes = file_extractor(folder_name)
newnamesforlater = [] newnamesforlater = []
images = image_extractor(scenes) images = image_extractor(scenes)
# list_dic, bins = make_dictionary(images, 4, False) list_dic, bins = make_dictionary(images, 4, False)
file_size_ratios = [] file_sizes_new = []
file_sizes_old = []
# np.save("first_dic.npy", list_dic) # np.save("first_dic.npy", list_dic)
for i in range(len(images)): for i in range(1):
# image, new_error, diff = huffman(images[i], 4, False) # image, new_error, diff = huffman(images[i], 4, False)
# encoded_string = encoder(new_error, list_dic, diff, bins) # encoded_string = encoder(new_error, list_dic, diff, bins)
# inletters = bitstring_to_bytes(encoded_string) # inletters = bitstring_to_bytes(encoded_string)
...@@ -504,7 +514,10 @@ for i in range(len(images)): ...@@ -504,7 +514,10 @@ for i in range(len(images)):
newnamesforlater.append(newname + "_Compressed.txt") newnamesforlater.append(newname + "_Compressed.txt")
# with open(newname + "_Compressed.txt", 'wb') as f: # with open(newname + "_Compressed.txt", 'wb') as f:
# f.write(inletters) # f.write(inletters)
file_size_ratios.append((os.path.getsize(newname + "_Compressed.txt"))/os.path.getsize(images[i])) file_sizes_new.append((os.path.getsize(newname + "_Compressed.txt")))
file_sizes_old.append((os.path.getsize(images[i])))
file_sizes_new.append(os.path.getsize("first_dic.npy"))
# print(np.sum(file_sizes_new)/np.sum(file_sizes_old))
# list_dic = np.load("first_dic.npy", allow_pickle="TRUE") # list_dic = np.load("first_dic.npy", allow_pickle="TRUE")
# for i,item in enumerate(newnamesforlater[0:10]): # for i,item in enumerate(newnamesforlater[0:10]):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment