Commit 03e500ca authored by Bryce Hepner's avatar Bryce Hepner

Small changes for testing, revert behind if bad

parent 5015fe54
...@@ -74,7 +74,8 @@ def predict_pix(tiff_image_path, difference = True): ...@@ -74,7 +74,8 @@ def predict_pix(tiff_image_path, difference = True):
A ndarray(3 X 3): system of equation A ndarray(3 X 3): system of equation
""" """
image_obj = Image.open(tiff_image_path) #Open the image and read it as an Image object image_obj = Image.open(tiff_image_path) #Open the image and read it as an Image object
image_array = np.array(image_obj)[1:,:].astype(int) #Convert to an array, leaving out the first row because the first row is just housekeeping data # image_array = np.array(image_obj)[1:].astype(int) #Convert to an array, leaving out the first row because the first row is just housekeeping data
image_array = np.array(image_obj).astype(int)
# image_array = image_array.astype(int) # image_array = image_array.astype(int)
# A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation # A = np.array([[3,0,-1],[0,3,3],[1,-3,-4]]) # the matrix for system of equation
Ainv = np.array([[0.5,-0.5,-0.5],[-0.5,1.83333333,1.5],[0.5,-1.5,-1.5]]) Ainv = np.array([[0.5,-0.5,-0.5],[-0.5,1.83333333,1.5],[0.5,-1.5,-1.5]])
...@@ -517,45 +518,50 @@ if __name__ == "__main__": ...@@ -517,45 +518,50 @@ if __name__ == "__main__":
scenes = file_extractor(folder_name) scenes = file_extractor(folder_name)
images = image_extractor(scenes) images = image_extractor(scenes)
newnamesforlater = [] newnamesforlater = []
# list_dic, bins = make_dictionary(images[0:1], 4, False) list_dic, bins = make_dictionary(images[19:20], 4, False)
file_sizes_new = [] file_sizes_new = []
file_sizes_old = [] file_sizes_old = []
list_dic = np.load("first_dic.npy", allow_pickle="TRUE") # list_dic = np.load("first_dic.npy", allow_pickle="TRUE")
bins = [21,32,48] bins = [21,32,48]
for i,item in enumerate(images):
if "NoI" in item:
print(item)
print(i)
# np.save("first_dic.npy", list_dic) # np.save("first_dic.npy", list_dic)
for i in range(len(images[0:5])): for i in range(19,len(images[0:20])):
# image, new_error, diff = huffman(images[i], 4, False)
# encoded_string = encoder(new_error, list_dic, diff, bins) image, new_error, diff = huffman(images[i], 4, False)
# inletters = bitstring_to_bytes(encoded_string) encoded_string = encoder(new_error, list_dic, diff, bins)
inletters = bitstring_to_bytes(encoded_string)
if images[i][-5:] == ".tiff": if images[i][-5:] == ".tiff":
newname = images[i][:-5] newname = images[i][:-5]
else: else:
newname = images[i][:-4] newname = images[i][:-4]
print(newname)
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_sizes_new.append((os.path.getsize(newname + "_Compressed.txt"))) file_sizes_new.append((os.path.getsize(newname + "_Compressed.txt")))
file_sizes_old.append((os.path.getsize(images[i]))) file_sizes_old.append((os.path.getsize(images[i])))
# sleep(5) # sleep(5)
# if i % 50 == 0: # if i % 50 == 0:
# print(i) # print(i)
# sleep(20) # sleep(20)
print(np.sum(file_sizes_new)/np.sum(file_sizes_old))
file_sizes_new.append(os.path.getsize("first_dic.npy")) file_sizes_new.append(os.path.getsize("first_dic.npy"))
print(np.sum(file_sizes_new)/np.sum(file_sizes_old)) 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")
bins = [21,32,48] bins = [21,32,48]
for i,item in enumerate(newnamesforlater): # for i,item in enumerate(newnamesforlater):
print(item) # print(item)
image, new_error, diff = huffman(images[i], 4, False) # image, new_error, diff = huffman(images[i], 4, False)
encoded_string2 = bytes_to_bitstring(read_from_file(item)) # encoded_string2 = bytes_to_bitstring(read_from_file(item))
starttime = time() # starttime = time()
reconstruct_image = decoder(encoded_string2, list_dic, bins, False) # reconstruct_image = decoder(encoded_string2, list_dic, bins, False)
print(np.allclose(image, reconstruct_image)) # print(np.allclose(image, reconstruct_image))
print(time() - starttime) # print(time() - starttime)
# text_to_tiff("images/1626033496_437803/1626033496_437803_3._Compressed.txt", list_dic, bins) # 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 = Image.open("images/1626033496_437803/1626033496_437803_3.tiff")
# original_image = np.array(original_image)[1:] # original_image = np.array(original_image)[1:]
......
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