Commit de772659 authored by Bryce Hepner's avatar Bryce Hepner

midday save

parent 9a11d800
......@@ -88,17 +88,32 @@ def color_adjust(visual_array):
adjusted_array = np.round(adjusted_array*255/np.max(adjusted_array))
return adjusted_array
if __name__ == "__main__":
scenes = file_extractor(folder_name)
scenes = file_extractor("averaged_images(11)")
images = image_extractor(scenes)
list_dic = np.load("first_dic.npy", allow_pickle="TRUE")
list_dic = np.load("second_dic.npy", allow_pickle="TRUE")
bins = [21,32,48]
encoded_string2 = bytes_to_bitstring(read_from_file(images[1][:-5] + "_Compressed.txt"))
print(images)
encoded_string2 = bytes_to_bitstring(read_from_file(images[0][:-5] + "_Compressed.txt"))
original_array, error_array = produce_error_array(encoded_string2, list_dic, bins, False)
adjusted_errors = color_adjust(abs(error_array))
original_array_adjusted = color_adjust(original_array)
# print(adjusted_errors)
print(error_array)
plt.subplot(121)
plt.imshow(original_array_adjusted,cmap='gray',vmin = 0, vmax=255)
plt.subplot(122)
plt.imshow(adjusted_errors,cmap = 'gray', vmin = 0, vmax=255)
# encoded_string2 = bytes_to_bitstring(read_from_file(images[1][:-5] + "_Compressed.txt"))
# original_array, error_array = produce_error_array(encoded_string2, list_dic, bins, False)
# adjusted_errors = color_adjust(abs(error_array))
# original_array_adjusted = color_adjust(original_array)
# plt.subplot(133)
# plt.imshow(adjusted_errors,cmap = 'gray', vmin = 0, vmax=255)
plt.show()
\ No newline at end of file
......@@ -254,14 +254,284 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.6193594010686757\n"
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
"float32\n",
">u2\n",
"float32\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n",
">u2\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/bryce/git/master/FullTester.ipynb Cell 13'\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/FullTester.ipynb#ch0000011?line=5'>6</a>\u001b[0m \u001b[39mprint\u001b[39m(newimage\u001b[39m.\u001b[39mdtype)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/FullTester.ipynb#ch0000011?line=6'>7</a>\u001b[0m newimage \u001b[39m=\u001b[39m Image\u001b[39m.\u001b[39mfromarray(newimage)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/bryce/git/master/FullTester.ipynb#ch0000011?line=7'>8</a>\u001b[0m newimage\u001b[39m.\u001b[39;49msave(newnamesforlater[i][:\u001b[39m-\u001b[39;49m\u001b[39m4\u001b[39;49m]\u001b[39m+\u001b[39;49m \u001b[39m\"\u001b[39;49m\u001b[39mlzw\u001b[39;49m\u001b[39m\"\u001b[39;49m \u001b[39m+\u001b[39;49m \u001b[39m\"\u001b[39;49m\u001b[39m.tiff\u001b[39;49m\u001b[39m\"\u001b[39;49m, compression\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mtiff_lzw\u001b[39;49m\u001b[39m'\u001b[39;49m, tiffinfo\u001b[39m=\u001b[39;49m{\u001b[39m317\u001b[39;49m: \u001b[39m2\u001b[39;49m})\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/FullTester.ipynb#ch0000011?line=9'>10</a>\u001b[0m lwz_sizes\u001b[39m.\u001b[39mappend(os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mgetsize(newnamesforlater[i][:\u001b[39m-\u001b[39m\u001b[39m4\u001b[39m]\u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mlzw\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m.tiff\u001b[39m\u001b[39m\"\u001b[39m))\n\u001b[1;32m <a href='vscode-notebook-cell:/home/bryce/git/master/FullTester.ipynb#ch0000011?line=10'>11</a>\u001b[0m \u001b[39mprint\u001b[39m(np\u001b[39m.\u001b[39msum(lwz_sizes)\u001b[39m/\u001b[39mnp\u001b[39m.\u001b[39msum(file_sizes_old))\n",
"File \u001b[0;32m~/.local/lib/python3.8/site-packages/PIL/Image.py:2300\u001b[0m, in \u001b[0;36mImage.save\u001b[0;34m(self, fp, format, **params)\u001b[0m\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/Image.py?line=2296'>2297</a>\u001b[0m fp \u001b[39m=\u001b[39m builtins\u001b[39m.\u001b[39mopen(filename, \u001b[39m\"\u001b[39m\u001b[39mw+b\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/Image.py?line=2298'>2299</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/Image.py?line=2299'>2300</a>\u001b[0m save_handler(\u001b[39mself\u001b[39;49m, fp, filename)\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/Image.py?line=2300'>2301</a>\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m:\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/Image.py?line=2301'>2302</a>\u001b[0m \u001b[39mif\u001b[39;00m open_fp:\n",
"File \u001b[0;32m~/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py:1814\u001b[0m, in \u001b[0;36m_save\u001b[0;34m(im, fp, filename)\u001b[0m\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py?line=1810'>1811</a>\u001b[0m e\u001b[39m.\u001b[39msetimage(im\u001b[39m.\u001b[39mim, (\u001b[39m0\u001b[39m, \u001b[39m0\u001b[39m) \u001b[39m+\u001b[39m im\u001b[39m.\u001b[39msize)\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py?line=1811'>1812</a>\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py?line=1812'>1813</a>\u001b[0m \u001b[39m# undone, change to self.decodermaxblock:\u001b[39;00m\n\u001b[0;32m-> <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py?line=1813'>1814</a>\u001b[0m l, s, d \u001b[39m=\u001b[39m e\u001b[39m.\u001b[39;49mencode(\u001b[39m16\u001b[39;49m \u001b[39m*\u001b[39;49m \u001b[39m1024\u001b[39;49m)\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py?line=1814'>1815</a>\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m _fp:\n\u001b[1;32m <a href='file:///home/bryce/.local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py?line=1815'>1816</a>\u001b[0m fp\u001b[39m.\u001b[39mwrite(d)\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
......@@ -271,6 +541,7 @@
" newimage = Image.open(filename)\n",
" newimage = np.array(newimage)\n",
" newimage = newimage[1:]\n",
" print(newimage.dtype)\n",
" newimage = Image.fromarray(newimage)\n",
" newimage.save(newnamesforlater[i][:-4]+ \"lzw\" + \".tiff\", compression='tiff_lzw', tiffinfo={317: 2})\n",
"\n",
......
This diff is collapsed.
......@@ -74,7 +74,7 @@ def predict_pix(tiff_image_path, difference = True):
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_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) #Convert to an array, leaving out the first row because the first row is just housekeeping data
# image_array = image_array.astype(int)
# 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]])
......@@ -514,7 +514,7 @@ def text_to_tiff(filename, list_dic, bins):
if __name__ == "__main__":
scenes = file_extractor(folder_name)
scenes = file_extractor("averaged_images(11)")
images = image_extractor(scenes)
newnamesforlater = []
list_dic, bins = make_dictionary(images, 4, False)
......@@ -522,7 +522,7 @@ if __name__ == "__main__":
file_sizes_old = []
# list_dic = np.load("first_dic.npy", allow_pickle="TRUE")
bins = [21,32,48]
# np.save("first_dic.npy", list_dic)
np.save("second_dic.npy", list_dic)
for i in range(len(images)):
image, new_error, diff = huffman(images[i], 4, False)
......@@ -537,18 +537,18 @@ if __name__ == "__main__":
newnamesforlater.append(newname + "_Compressed.txt")
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(newname + "_Compressed.txt")))
file_sizes_old.append((os.path.getsize(images[i])))
# sleep(5)
# if i % 50 == 0:
# print(i)
# sleep(20)
# print(np.sum(file_sizes_new)/np.sum(file_sizes_old))
# 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))
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")
bins = [21,32,48]
# os.system("ls")
# for i,item in enumerate(newnamesforlater):
# print(item)
# image, new_error, diff = huffman(images[i], 4, False)
......
File added
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