Loading RunningInParallel.py +2 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ if __name__ == "__main__": def save_an_image(filename): """ Takes in the filename and writes the compressed image """ newnamesforlater = [] list_dic = np.load("first_dic.npy", allow_pickle=True) Loading @@ -47,6 +47,6 @@ if __name__ == "__main__": newname = filename[:-4] encoded_string2 = bytes_to_bitstring(read_from_file(newname + "_Compressed.txt")) reconstruct_image = decoder(encoded_string2, list_dic, bins, False) dview.map_sync(save_an_image, images[200:]) dview.map_sync(save_an_image, images[160:200]) # dview.map_sync(decode_an_image, images[0:6]) print(time() - starttime) No newline at end of file WorkingPyDemo.py +7 −10 Original line number Diff line number Diff line Loading @@ -506,25 +506,23 @@ if __name__ == "__main__": scenes = file_extractor(folder_name) images = image_extractor(scenes) newnamesforlater = [] # print(len(images)) # list_dic, bins = make_dictionary(images, 4, False) file_sizes_new = [] file_sizes_old = [] # np.save("first_dic.npy", list_dic) for i in range(200,len(images)): # image, new_error, diff = huffman(images[i], 4, False) # encoded_string = encoder(new_error, list_dic, diff, bins) # inletters = bitstring_to_bytes(encoded_string) for i in range(len(images)): image, new_error, diff = huffman(images[i], 4, False) encoded_string = encoder(new_error, list_dic, diff, bins) inletters = bitstring_to_bytes(encoded_string) if images[i][-5:] == ".tiff": newname = images[i][:-5] else: newname = images[i][:-4] # print(newname) newnamesforlater.append(newname + "_Compressed.txt") # with open(newname + "_Compressed.txt", 'wb') as f: # f.write(inletters) with open(newname + "_Compressed.txt", 'wb') as f: f.write(inletters) 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")) Loading @@ -537,7 +535,6 @@ print(np.sum(file_sizes_new)/np.sum(file_sizes_old)) # encoded_string2 = bytes_to_bitstring(read_from_file(item)) # reconstruct_image = decoder(encoded_string2, list_dic, bins, False) # print(np.allclose(image, reconstruct_image)) # print(time()-starttime) # text_to_tiff("images/1626033496_437803/1626033496_437803_3._Compressed.txt", list_dic, bins) # original_image = Image.open("images/1626033496_437803/1626033496_437803_3.tiff") # original_image = np.array(original_image)[1:] Loading Loading
RunningInParallel.py +2 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ if __name__ == "__main__": def save_an_image(filename): """ Takes in the filename and writes the compressed image """ newnamesforlater = [] list_dic = np.load("first_dic.npy", allow_pickle=True) Loading @@ -47,6 +47,6 @@ if __name__ == "__main__": newname = filename[:-4] encoded_string2 = bytes_to_bitstring(read_from_file(newname + "_Compressed.txt")) reconstruct_image = decoder(encoded_string2, list_dic, bins, False) dview.map_sync(save_an_image, images[200:]) dview.map_sync(save_an_image, images[160:200]) # dview.map_sync(decode_an_image, images[0:6]) print(time() - starttime) No newline at end of file
WorkingPyDemo.py +7 −10 Original line number Diff line number Diff line Loading @@ -506,25 +506,23 @@ if __name__ == "__main__": scenes = file_extractor(folder_name) images = image_extractor(scenes) newnamesforlater = [] # print(len(images)) # list_dic, bins = make_dictionary(images, 4, False) file_sizes_new = [] file_sizes_old = [] # np.save("first_dic.npy", list_dic) for i in range(200,len(images)): # image, new_error, diff = huffman(images[i], 4, False) # encoded_string = encoder(new_error, list_dic, diff, bins) # inletters = bitstring_to_bytes(encoded_string) for i in range(len(images)): image, new_error, diff = huffman(images[i], 4, False) encoded_string = encoder(new_error, list_dic, diff, bins) inletters = bitstring_to_bytes(encoded_string) if images[i][-5:] == ".tiff": newname = images[i][:-5] else: newname = images[i][:-4] # print(newname) newnamesforlater.append(newname + "_Compressed.txt") # with open(newname + "_Compressed.txt", 'wb') as f: # f.write(inletters) with open(newname + "_Compressed.txt", 'wb') as f: f.write(inletters) 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")) Loading @@ -537,7 +535,6 @@ print(np.sum(file_sizes_new)/np.sum(file_sizes_old)) # encoded_string2 = bytes_to_bitstring(read_from_file(item)) # reconstruct_image = decoder(encoded_string2, list_dic, bins, False) # print(np.allclose(image, reconstruct_image)) # print(time()-starttime) # text_to_tiff("images/1626033496_437803/1626033496_437803_3._Compressed.txt", list_dic, bins) # original_image = Image.open("images/1626033496_437803/1626033496_437803_3.tiff") # original_image = np.array(original_image)[1:] Loading