Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
image-compression
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
image-compression
Commits
de772659
Commit
de772659
authored
Jul 01, 2022
by
Bryce Hepner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
midday save
parent
9a11d800
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
401 additions
and
73 deletions
+401
-73
ErrorImageCreator.py
ErrorImageCreator.py
+18
-3
FullTester.ipynb
FullTester.ipynb
+273
-2
Remove_Noise.py
Remove_Noise.py
+101
-59
WorkingPyDemo.py
WorkingPyDemo.py
+9
-9
second_dic.npy
second_dic.npy
+0
-0
No files found.
ErrorImageCreator.py
View file @
de772659
...
@@ -88,17 +88,32 @@ def color_adjust(visual_array):
...
@@ -88,17 +88,32 @@ def color_adjust(visual_array):
adjusted_array
=
np
.
round
(
adjusted_array
*
255
/
np
.
max
(
adjusted_array
))
adjusted_array
=
np
.
round
(
adjusted_array
*
255
/
np
.
max
(
adjusted_array
))
return
adjusted_array
return
adjusted_array
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
scenes
=
file_extractor
(
folder_name
)
scenes
=
file_extractor
(
"averaged_images(11)"
)
images
=
image_extractor
(
scenes
)
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
]
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
)
original_array
,
error_array
=
produce_error_array
(
encoded_string2
,
list_dic
,
bins
,
False
)
adjusted_errors
=
color_adjust
(
abs
(
error_array
))
adjusted_errors
=
color_adjust
(
abs
(
error_array
))
original_array_adjusted
=
color_adjust
(
original_array
)
original_array_adjusted
=
color_adjust
(
original_array
)
# print(adjusted_errors)
# print(adjusted_errors)
print
(
error_array
)
plt
.
subplot
(
121
)
plt
.
subplot
(
121
)
plt
.
imshow
(
original_array_adjusted
,
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
255
)
plt
.
imshow
(
original_array_adjusted
,
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
255
)
plt
.
subplot
(
122
)
plt
.
subplot
(
122
)
plt
.
imshow
(
adjusted_errors
,
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
255
)
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
()
plt
.
show
()
\ No newline at end of file
FullTester.ipynb
View file @
de772659
...
@@ -254,14 +254,284 @@
...
@@ -254,14 +254,284 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
4
3,
"execution_count":
1
3,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"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 @@
...
@@ -271,6 +541,7 @@
" newimage = Image.open(filename)\n",
" newimage = Image.open(filename)\n",
" newimage = np.array(newimage)\n",
" newimage = np.array(newimage)\n",
" newimage = newimage[1:]\n",
" newimage = newimage[1:]\n",
" print(newimage.dtype)\n",
" newimage = Image.fromarray(newimage)\n",
" newimage = Image.fromarray(newimage)\n",
" newimage.save(newnamesforlater[i][:-4]+ \"lzw\" + \".tiff\", compression='tiff_lzw', tiffinfo={317: 2})\n",
" newimage.save(newnamesforlater[i][:-4]+ \"lzw\" + \".tiff\", compression='tiff_lzw', tiffinfo={317: 2})\n",
"\n",
"\n",
...
...
Remove_Noise.py
View file @
de772659
This diff is collapsed.
Click to expand it.
WorkingPyDemo.py
View file @
de772659
...
@@ -74,7 +74,7 @@ def predict_pix(tiff_image_path, difference = True):
...
@@ -74,7 +74,7 @@ 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
)
.
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)
# 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
]])
...
@@ -514,7 +514,7 @@ def text_to_tiff(filename, list_dic, bins):
...
@@ -514,7 +514,7 @@ def text_to_tiff(filename, list_dic, bins):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
scenes
=
file_extractor
(
folder_name
)
scenes
=
file_extractor
(
"averaged_images(11)"
)
images
=
image_extractor
(
scenes
)
images
=
image_extractor
(
scenes
)
newnamesforlater
=
[]
newnamesforlater
=
[]
list_dic
,
bins
=
make_dictionary
(
images
,
4
,
False
)
list_dic
,
bins
=
make_dictionary
(
images
,
4
,
False
)
...
@@ -522,7 +522,7 @@ if __name__ == "__main__":
...
@@ -522,7 +522,7 @@ if __name__ == "__main__":
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
]
# np.save("first
_dic.npy", list_dic)
np
.
save
(
"second
_dic.npy"
,
list_dic
)
for
i
in
range
(
len
(
images
)):
for
i
in
range
(
len
(
images
)):
image
,
new_error
,
diff
=
huffman
(
images
[
i
],
4
,
False
)
image
,
new_error
,
diff
=
huffman
(
images
[
i
],
4
,
False
)
...
@@ -537,18 +537,18 @@ if __name__ == "__main__":
...
@@ -537,18 +537,18 @@ if __name__ == "__main__":
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))
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
]
# os.system("ls")
# 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)
...
...
second_dic.npy
0 → 100644
View file @
de772659
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment