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
Hide 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
from
matplotlib.image
import
composite_images
from
matplotlib.image
import
composite_images
from
WorkingPyDemo
import
*
from
WorkingPyDemo
import
*
from
scipy.ndimage.filters
import
gaussian_filter
import
paramiko
import
paramiko
from
PIL
import
ImageFilter
def
setup_remote_sftpclient
():
def
setup_remote_sftpclient
():
client
=
paramiko
.
SSHClient
()
client
=
paramiko
.
SSHClient
()
client
.
load_system_host_keys
()
client
.
load_system_host_keys
()
...
@@ -19,46 +21,39 @@ def remove_noise(images, which_sensor):
...
@@ -19,46 +21,39 @@ def remove_noise(images, which_sensor):
if
image_name
[
-
7
:
-
5
]
==
"_"
+
which_sensor
:
if
image_name
[
-
7
:
-
5
]
==
"_"
+
which_sensor
:
same_sensor_images
.
append
(
image_name
)
same_sensor_images
.
append
(
image_name
)
for
i
,
image_name
in
enumerate
(
same_sensor_images
):
for
i
,
image_name
in
enumerate
(
same_sensor_images
):
# print(image_name)
image_object
=
Image
.
open
(
image_name
)
image_object
=
Image
.
open
(
image_name
)
# print(np.array(image_object).shape)
# print(np.array(image_object)[1:] + average_image)
average_image
=
np
.
array
(
image_object
)[
1
:]
+
average_image
average_image
=
np
.
array
(
image_object
)[
1
:]
+
average_image
return
average_image
/
len
(
same_sensor_images
)
return
average_image
/
len
(
same_sensor_images
)
def
remote_
remove_nois
e
(
images
,
which_sensor
):
def
remote_
create_averag
e
(
images
,
which_sensor
):
sftp_client
=
setup_remote_sftpclient
()
sftp_client
=
setup_remote_sftpclient
()
averages
=
[]
averages
=
[]
same_sensor_images
=
[]
same_sensor_images
=
images
which_sensor
=
str
(
which_sensor
)
which_sensor
=
str
(
which_sensor
)
first_image
=
sftp_client
.
open
(
images
[
0
])
small_set_images
=
[]
average_image
=
np
.
array
(
Image
.
open
(
first_image
))[
1
:]
for
i
,
image_name
in
enumerate
(
images
):
if
int
(
which_sensor
)
>
9
:
if
image_name
[
-
7
:
-
5
]
==
which_sensor
:
same_sensor_images
.
append
(
image_name
)
else
:
if
image_name
[
-
7
:
-
5
]
==
"_"
+
which_sensor
:
same_sensor_images
.
append
(
image_name
)
images
=
[]
for
i
,
image_name
in
enumerate
(
same_sensor_images
):
for
i
,
image_name
in
enumerate
(
same_sensor_images
):
# print(image_name)
# print(image_name)
image_object
=
sftp_client
.
open
(
image_name
)
image_object
=
sftp_client
.
open
(
image_name
)
image_object
=
Image
.
open
(
image_object
)
image_object
=
Image
.
open
(
image_object
)
images
.
append
(
np
.
array
(
image_object
)[
1
:])
small_set_
images
.
append
(
np
.
array
(
image_object
)[
1
:])
# print(np.array(image_object).shape)
# print(np.array(image_object).shape)
# print(np.array(image_object)[1:] + average_image)
# print(np.array(image_object)[1:] + average_image)
if
(
i
%
100
==
0
)
and
i
!=
0
:
if
(
i
%
100
==
0
)
and
i
!=
0
:
image_object
=
np
.
mean
(
np
.
array
(
small_set_images
),
axis
=
0
)
image_object
=
np
.
mean
(
np
.
array
(
images
),
axis
=
0
)
# print(image_object.shape)
averages
.
append
(
image_object
)
averages
.
append
(
image_object
)
# print(average_image.shape)
small_set_images
=
[]
images
=
[]
print
(
i
)
image_object
=
np
.
mean
(
np
.
array
(
images
))
if
len
(
small_set_images
)
>
1
:
averages
.
append
(
image_object
)
image_object
=
np
.
mean
(
np
.
array
(
small_set_images
),
axis
=
0
)
averages
.
append
(
image_object
)
sftp_client
.
close
()
sftp_client
.
close
()
return
np
.
mean
(
averages
,
axis
=
0
)
if
len
(
averages
)
>
1
:
return
np
.
mean
(
averages
,
axis
=
0
)
else
:
return
np
.
array
(
averages
[
0
])
def
remote_file_extractor
(
headname
=
"/media/elphel/NVME/lwir16-proc/te0607/scenes/"
):
def
remote_file_extractor
(
headname
=
"/media/elphel/NVME/lwir16-proc/te0607/scenes/"
):
"""Find all the files in the directory
"""Find all the files in the directory
...
@@ -69,18 +64,16 @@ def remote_file_extractor(headname = "/media/elphel/NVME/lwir16-proc/te0607/scen
...
@@ -69,18 +64,16 @@ def remote_file_extractor(headname = "/media/elphel/NVME/lwir16-proc/te0607/scen
Returns:
Returns:
files (list): a list of all the files in the directory
files (list): a list of all the files in the directory
"""
"""
client
=
paramiko
.
SSHClient
()
sftp_client
=
setup_remote_sftpclient
()
client
.
load_system_host_keys
()
client
.
connect
(
"192.168.0.107"
,
username
=
"elphel"
)
sftp_client
=
client
.
open_sftp
()
# sftp_client.listdir("media/elphel/NVME/lwir16-proc/te0607/scenes/")
# sftp_client.listdir("media/elphel/NVME/lwir16-proc/te0607/scenes/")
dirs_in_scenes
=
sftp_client
.
listdir
(
"/media/elphel/NVME/lwir16-proc/te0607/scenes/"
)
dirs_in_scenes
=
sftp_client
.
listdir
(
headname
)
scenes
=
[]
scenes
=
[]
for
i
,
curr_folder
in
enumerate
(
dirs_in_scenes
):
for
i
,
curr_folder
in
enumerate
(
dirs_in_scenes
):
if
"."
not
in
curr_folder
:
if
"."
not
in
curr_folder
:
smaller_dirs
=
sftp_client
.
listdir
(
headname
+
curr_folder
)
smaller_dirs
=
sftp_client
.
listdir
(
headname
+
curr_folder
)
for
small_folder
in
smaller_dirs
:
for
small_folder
in
smaller_dirs
:
scenes
.
append
(
headname
+
curr_folder
+
"/"
+
small_folder
)
scenes
.
append
(
headname
+
curr_folder
+
"/"
+
small_folder
)
sftp_client
.
close
()
return
scenes
return
scenes
def
remote_image_extractor
(
scenes
):
def
remote_image_extractor
(
scenes
):
...
@@ -95,57 +88,106 @@ def remote_image_extractor(scenes):
...
@@ -95,57 +88,106 @@ def remote_image_extractor(scenes):
image_folder
.
append
(
os
.
path
.
join
(
scene
,
file
))
image_folder
.
append
(
os
.
path
.
join
(
scene
,
file
))
sftp_client
.
close
()
sftp_client
.
close
()
return
image_folder
#returns a list of file paths to .tiff files in the specified directory given in file_extractor
return
image_folder
#returns a list of file paths to .tiff files in the specified directory given in file_extractor
def
find_only_in_channel
(
images
,
channel_name
=
"10"
):
def
remove_the_noise
(
new_image
,
average_image
):
same_sensor_images
=
[]
original_image_min
=
np
.
min
(
newimage
)
for
i
,
image_name
in
enumerate
(
images
):
if
int
(
channel_name
)
>
9
:
if
image_name
[
-
7
:
-
5
]
==
channel_name
:
same_sensor_images
.
append
(
image_name
)
else
:
if
image_name
[
-
7
:
-
5
]
==
"_"
+
channel_name
:
same_sensor_images
.
append
(
image_name
)
return
same_sensor_images
def
adjust_to_original
(
new_image
,
average_image
):
original_image_min
=
np
.
min
(
new_image
)
original_image_max
=
np
.
max
(
new_image
)
original_image_max
=
np
.
max
(
new_image
)
adjusted_image
=
new_image
-
average_image
# average_image = average_image - np.mean(average_image)
adjusted_image
=
new_image
-
(
average_image
-
gaussian_filter
(
average_image
,
sigma
=
5
))
# adjusted_image = new_image - (average_image - np.array(Image.fromarray(average_image).convert("L").filter(ImageFilter.GaussianBlur(radius=4))))
adjusted_image
=
adjusted_image
-
np
.
min
(
adjusted_image
)
adjusted_image
=
adjusted_image
-
np
.
min
(
adjusted_image
)
adjusted_image
=
adjusted_image
*
original_image_max
/
np
.
max
(
adjusted_image
)
adjusted_image
=
adjusted_image
*
(
original_image_max
-
original_image_min
)
/
np
.
max
(
adjusted_image
)
adjusted_image
=
adjusted_image
+
original_image_min
adjusted_image
=
adjusted_image
+
original_image_min
return
adjusted_image
return
adjusted_image
.
astype
(
np
.
uint16
)
def
color_adjust
(
visual_array
):
def
color_adjust
(
visual_array
):
min_of_errors
=
np
.
min
(
visual_array
)
min_of_errors
=
np
.
min
(
visual_array
)
adjusted_array
=
visual_array
-
min_of_errors
adjusted_array
=
visual_array
-
min_of_errors
adjusted_array
=
adjusted_array
/
np
.
max
(
adjusted_array
)
adjusted_array
=
adjusted_array
/
np
.
max
(
adjusted_array
)
# print(adjusted_array)
# print(np.max(adjusted_array))
return
adjusted_array
return
adjusted_array
def
save_new_average
(
quantity_of_images
=
1500
,
channel
=
"10"
,
head_dir
=
"/media/elphel/NVME/lwir16-proc/te0607/scenes/"
):
scenes
=
remote_file_extractor
(
head_dir
)
images
=
find_only_in_channel
(
remote_image_extractor
(
scenes
),
channel
)
if
quantity_of_images
!=
"all"
:
# images = np.random.choice(images,quantity_of_images,replace = False)
images
=
images
[:
quantity_of_images
]
average_image
=
remote_create_average
(
images
,
channel
)
# average_image = average_image.astype(int)
average_savable_image
=
Image
.
fromarray
(
average_image
)
average_savable_image
.
save
(
"Average_On_Channel("
+
channel
+
").tiff"
)
def
create_testable_images
(
images
,
selected_channel
,
quantity_of_images
):
sftp_client
=
setup_remote_sftpclient
()
images
=
find_only_in_channel
(
images
,
selected_channel
)
image_locations
=
np
.
random
.
choice
(
len
(
images
),
quantity_of_images
,
replace
=
False
)
# image_locations = np.arange(quantity_of_images) + 10000
selected_images
=
np
.
array
(
images
)[
image_locations
]
# average_image = np.array(Image.open("Average_On_Channel(" + selected_channel + ").tiff"))
images_in_each_direction
=
4
for
i
,
item
in
enumerate
(
selected_images
):
if
image_locations
[
i
]
<
images_in_each_direction
:
average_image
=
remote_create_average
(
images
[
image_locations
[
i
]
-
image_locations
[
i
]:
image_locations
[
i
]
+
images_in_each_direction
+
image_locations
[
i
]],
selected_channel
)
elif
image_locations
[
i
]
>
(
len
(
images
)
-
images_in_each_direction
):
average_image
=
remote_create_average
(
images
[
image_locations
[
i
]
-
images_in_each_direction
-
(
len
(
images
)
-
image_locations
[
i
]):
image_locations
[
i
]
+
(
len
(
images
)
-
image_locations
[
i
])],
selected_channel
)
else
:
average_image
=
remote_create_average
(
images
[
image_locations
[
i
]
-
images_in_each_direction
:
image_locations
[
i
]
+
images_in_each_direction
],
selected_channel
)
image
=
Image
.
open
(
sftp_client
.
open
(
item
))
wherelastslash
=
item
.
rfind
(
"/"
)
image
=
np
.
array
(
image
)[
1
:]
savable_original
=
Image
.
fromarray
(
image
)
savable_original
.
save
(
"averaged_images("
+
selected_channel
+
")/innerfolder/original"
+
item
[
wherelastslash
+
1
:])
altered_image
=
adjust_to_original
(
image
,
average_image
)
altered_image
=
Image
.
fromarray
(
altered_image
)
# altered_image.save("averaged_images(" + selected_channel + ")/innerfolder" + item[wherelastslash:])
# average_image = Image.fromarray(average_image)
sftp_client
.
close
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# save_new_average(15,"11")
scenes
=
remote_file_extractor
(
"/media/elphel/NVME/lwir16-proc/te0607/scenes/"
)
scenes
=
remote_file_extractor
(
"/media/elphel/NVME/lwir16-proc/te0607/scenes/"
)
# images = remote_image_extractor(np.random.choice(scenes,10000,replace = False))
images
=
remote_image_extractor
(
scenes
)
images
=
remote_image_extractor
(
scenes
)
# average_image = remote_remove_noise(images,"10")
images
=
find_only_in_channel
(
images
,
"11"
)
# average_image = np.array(Image.open("Average_On_Channel(" + "11" + ").tiff"))
average_image
=
np
.
array
(
Image
.
open
(
"hopefullyaverage.tiff"
))
create_testable_images
(
images
,
"11"
,
10
)
# plt.imshow(color_adjust(average_image),cmap='gray',vmin = 0, vmax=1)
# average_savable_image = Image.fromarray(average_image)
# plt.show()
# average_savable_image.save("hopefullyaverage.tiff")
# print(np.max(average_image))
# print(np.min(average_image))
# average_image = color_adjust(average_image)
plt
.
imshow
(
color_adjust
(
average_image
),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
1
)
plt
.
show
()
# print(len(images))
# print(len(images))
average_image
=
remote_create_average
(
images
[
10000
-
10
:
10000
+
10
],
"11"
)
plt
.
imshow
(
color_adjust
((
average_image
-
gaussian_filter
(
average_image
,
sigma
=
5
))),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
1
)
plt
.
show
()
sftp_client
=
setup_remote_sftpclient
()
sftp_client
=
setup_remote_sftpclient
()
print
(
len
(
images
))
print
(
len
(
images
))
for
i
,
item
in
enumerate
(
images
[
22000
:
22030
]):
# print(images[10000])
if
item
[
-
7
:
-
5
]
==
"10"
:
test_image
=
sftp_client
.
open
(
images
[
10000
])
print
(
i
)
print
(
item
)
print
(
images
[
22016
])
test_image
=
sftp_client
.
open
(
images
[
22016
])
test_image
=
Image
.
open
(
test_image
)
test_image
=
Image
.
open
(
test_image
)
test_image
=
np
.
array
(
test_image
)[
1
:]
test_image
=
np
.
array
(
test_image
)[
1
:]
newimage
=
Image
.
fromarray
(
test_image
-
average_image
)
# print(test_image)
newimage
.
save
(
"NoInterference.tiff"
)
# plt.imshow(color_adjust(adjust_to_original(test_image,average_image)))
# plt.show()
# newimage = Image.fromarray(test_image - average_image)
# newimage.save("NoInterference.tiff")
plt
.
subplot
(
121
)
plt
.
subplot
(
121
)
plt
.
imshow
(
color_adjust
(
test_image
),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
1
)
plt
.
imshow
(
color_adjust
(
test_image
),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
1
)
plt
.
subplot
(
122
)
plt
.
subplot
(
122
)
plt
.
imshow
(
color_adjust
(
test_image
-
average_image
),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
1
)
plt
.
imshow
(
color_adjust
(
adjust_to_original
(
test_image
,
average_image
)
),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
1
)
plt
.
show
()
plt
.
show
()
sftp_client
.
close
()
# print(np.linalg.inv(np.array([[3,0,-1],[0,3,3],[1,-3,-4]])))
# print(np.linalg.inv(np.array([[3,0,-1],[0,3,3],[1,-3,-4]])))
# print(np.linalg.pinv(np.array([[-1,-1,1], [-1,0,1], [-1,1,1], [0,-1,1]])))
# print(np.linalg.pinv(np.array([[-1,-1,1], [-1,0,1], [-1,1,1], [0,-1,1]])))
\ No newline at end of file
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