...
 
Commits (4)
......@@ -468,13 +468,13 @@
" o_len = 0\n",
" # the bits for the compressed image\n",
" c_len = 0\n",
" # initializing the varible \n",
" # initializing the variable \n",
" \n",
" #this was unused\n",
" # im = np.reshape(image,(512, 640))\n",
" \n",
" real_boundary = np.hstack((image_array[0,:],image_array[-1,:],image_array[1:-1,0],image_array[1:-1,-1]))\n",
" #Bryce's notes: Why are they all reshaped?\n",
"\n",
" original_core = image_array[1:-1,1:-1].reshape(-1)\n",
" diff = diff.reshape(-1)\n",
" error = new_error[1:-1,1:-1].reshape(-1)\n",
......
This diff is collapsed.
......@@ -205,7 +205,7 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True):
# plt.title('Histogram of Pixel Values')
# plt.show()
bins = [29,44,67]
bins = [21,32,48]
# get the boundary
boundary = np.hstack((image_array[0,:],image_array[-1,:],image_array[1:-1,0],image_array[1:-1,-1]))
......@@ -290,7 +290,7 @@ def huffman(tiff_image_path, num_bins=4, difference = True):
# get the image_as_array, etc
image_as_array, diff, error= predict_pix(tiff_image_path, difference)
bins = [29,44,67]
bins = [21,32,48]
# get the boundary
boundary = np.hstack((image_as_array[0,:],image_as_array[-1,:],image_as_array[1:-1,0],image_as_array[1:-1,-1]))
......@@ -548,16 +548,16 @@ if __name__ == "__main__":
scenes = file_extractor("images")
images = image_extractor(scenes)
newnamesforlater = []
list_dic, bins = make_dictionary(images, 4, True)
list_dic, bins = make_dictionary(images, 4, False)
file_sizes_new = []
file_sizes_old = []
# list_dic = np.load("first_dict.npy", allow_pickle="True")
bins = [29,44,67]
bins = [21,32,48]
#otherbins = [21,32,48]
np.save("first_dict.npy", list_dic)
for i in np.random.choice(len(images), 10):
for i in range(3):
image, new_error, diff = huffman(images[i], 4, True)
image, new_error, diff = huffman(images[i], 4, False)
encoded_string = encoder(new_error, list_dic, diff, bins)
inletters = bitstring_to_bytes(encoded_string)
......@@ -578,16 +578,16 @@ if __name__ == "__main__":
file_sizes_new.append(os.path.getsize("first_dict.npy"))
print(np.sum(file_sizes_new)/np.sum(file_sizes_old))
# list_dic = np.load("first_dict.npy", allow_pickle="TRUE")
bins = [29,44,67]
# for i,item in enumerate(newnamesforlater):
# print(item)
# image, new_error, diff = huffman(images[i], 4, False)
# encoded_string2 = bytes_to_bitstring(read_from_file(item))
# starttime = time()
# reconstruct_image = decoder(encoded_string2, list_dic, bins, False)
# print(np.allclose(image, reconstruct_image))
# print(time() - starttime)
bins = [21,32,48]
for i,item in enumerate(newnamesforlater):
# print(item)
image, new_error, diff = huffman(images[i], 4, False)
encoded_string2 = bytes_to_bitstring(read_from_file(item))
starttime = time()
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:]
......
No preview for this file type