Commit c7c32277 authored by Bryce Hepner's avatar Bryce Hepner

testing on gaussian blur, not good

parent 96e5883b
from audioop import mul
from matplotlib.image import composite_images
from WorkingPyDemo import * from WorkingPyDemo import *
from scipy.ndimage.filters import gaussian_filter from scipy.ndimage.filters import gaussian_filter
import paramiko import paramiko
from PIL import ImageFilter from PIL import ImageFilter
from scipy.signal import convolve2d
from scipy.stats import multivariate_normal
from skimage.restoration import wiener
def setup_remote_sftpclient(): def setup_remote_sftpclient():
client = paramiko.SSHClient() client = paramiko.SSHClient()
client.load_system_host_keys() client.load_system_host_keys()
...@@ -175,14 +177,14 @@ def save_new_gauss(): ...@@ -175,14 +177,14 @@ def save_new_gauss():
creates gaussian kernel with side length `l` and a sigma of `sig` creates gaussian kernel with side length `l` and a sigma of `sig`
""" """
# x,y = np.mgrid[-1:1:.003125, -1:1:.003125] # x,y = np.mgrid[-1:1:.003125, -1:1:.003125]
x,y = np.mgrid[-1:1:.003911, -1:1:.003911] x,y = np.mgrid[-1:1:.44, -1:1:.44]
# print(x.shape) print(x.shape)
pos = np.dstack((x,y)) pos = np.dstack((x,y))
# grid = np.zeros((l,l)) # grid = np.zeros((l,l))
# gauss = np.exp(-0.5 * np.square(ax) / np.square(sig)) # gauss = np.exp(-0.5 * np.square(ax) / np.square(sig))
from scipy.stats import multivariate_normal
# normal_grid = multivariate_normal.pdf(grid, mean = [0]*l, cov = [5]*l) # normal_grid = multivariate_normal.pdf(grid, mean = [0]*l, cov = [5]*l)
normal_grid = multivariate_normal([0, 0], [[2.0, 0.3], [0.3, 0.5]]).pdf(pos) normal_grid = multivariate_normal([0, 0], [[1.1, 5], [2, 1]]).pdf(pos)
normal_grid = normal_grid/np.sum(normal_grid) normal_grid = normal_grid/np.sum(normal_grid)
end_image = Image.fromarray(normal_grid) end_image = Image.fromarray(normal_grid)
# fig2 = plt.figure() # fig2 = plt.figure()
...@@ -191,43 +193,18 @@ def save_new_gauss(): ...@@ -191,43 +193,18 @@ def save_new_gauss():
# plt.show() # plt.show()
# print(np.sum(np.array(end_image))) # print(np.sum(np.array(end_image)))
end_image.save("gaussian_kernel.tiff") end_image.save("gaussian_kernel.tiff")
def little_inverter(initial_matrix):
n = initial_matrix.shape[0]
initial_matrix = np.hstack((initial_matrix,np.zeros_like(initial_matrix)))
print(initial_matrix.shape)
initial_matrix = initial_matrix.tolist()
for i in range(n):
for j in range(n):
if i == j:
initial_matrix[i][j+n] = 1
# Applying Guass Jordan Elimination
for i in range(n):
if initial_matrix[i][i] == 0.0:
sys.exit('Divide by zero detected!')
for j in range(n):
if i != j:
ratio = initial_matrix[j][i]/initial_matrix[i][i]
for k in range(2*n):
initial_matrix[j][k] = initial_matrix[j][k] - ratio * initial_matrix[i][k]
# Row operation to make principal diagonal element to 1
for i in range(n):
divisor = initial_matrix[i][i]
for j in range(2*n):
initial_matrix[i][j] = initial_matrix[i][j]/divisor
return np.array(initial_matrix)[:,n:]
if __name__ == "__main__": if __name__ == "__main__":
# save_new_average(350,"11") # save_new_average(350,"11")
save_new_gauss() # save_new_gauss()
gaussian_kernel = np.array(Image.open("gaussian_kernel.tiff")) gaussian_kernel = np.array(Image.open("gaussian_kernel.tiff"))
# gaussian_kernel = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
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(scenes) images = remote_image_extractor(scenes)
images = find_only_in_channel(images, "11") images = find_only_in_channel(images, "11")
# average_image = np.array(Image.open("Average_On_Channel(" + "11" + ").tiff")) # average_image = np.array(Image.open("Average_On_Channel(" + "11" + ").tiff"))
# create_testable_images(images,"11",6) # create_testable_images(images,"11",3)
# plt.imshow(color_adjust(average_image),cmap='gray',vmin = 0, vmax=1) # plt.imshow(color_adjust(average_image),cmap='gray',vmin = 0, vmax=1)
# plt.show() # plt.show()
...@@ -238,15 +215,32 @@ if __name__ == "__main__": ...@@ -238,15 +215,32 @@ if __name__ == "__main__":
sftp_client = setup_remote_sftpclient() sftp_client = setup_remote_sftpclient()
# print(len(images)) # print(len(images))
# print(images[10000]) # print(images[10000])
test_image = sftp_client.open(images[4700]) test_image = sftp_client.open(images[10000])
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:]
# print(test_image) # print(test_image)
plt.subplot(121)
plt.imshow(color_adjust(adjust_to_original(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.subplot(122)
little_more_blurred = gaussian_kernel@adjust_to_original(test_image,average_image) # plt.show()
print(little_inverter(gaussian_kernel)@gaussian_kernel) # print(gaussian_kernel)
plt.imshow(color_adjust(little_inverter(gaussian_kernel)@little_more_blurred),cmap='gray',vmin = 0, vmax=1) little_more_blurred = convolve2d(np.pad(test_image,2, mode = 'edge'),gaussian_kernel, "valid")
# print(little_more_blurred)
print(little_more_blurred.shape)
# print(little_inverter(gaussian_kernel)@gaussian_kernel)
altered_image = Image.fromarray(little_more_blurred.astype(np.uint16))
altered_image.save("averaged_images(" + "11" + ")/innerfolder" + "/testable.tiff")
plt.imshow(color_adjust(little_more_blurred[3:-3,3:-3]),cmap='gray',vmin = 0, vmax=1)
# plt.show()
# renewed_array =
# H = fft(kernel)
# deconvolved = np.real(ifft(fft(signal)*np.conj(H)/(H*np.conj(H) + lambd**2)))
back_to_normal = wiener(little_more_blurred,gaussian_kernel,.02,clip=False)
# print(back_to_normal)
# print(back_to_normal.shape)
# plt.imshow(color_adjust(back_to_normal), cmap='gray',vmin = 0, vmax=1)
plt.show() plt.show()
# newimage = Image.fromarray(test_image - average_image) # newimage = Image.fromarray(test_image - average_image)
# newimage.save("NoInterference.tiff") # newimage.save("NoInterference.tiff")
......
...@@ -11,6 +11,7 @@ import numpy.linalg as la ...@@ -11,6 +11,7 @@ import numpy.linalg as la
from time import time from time import time
from time import sleep from time import sleep
import tifffile as tiff import tifffile as tiff
folder_name = "images" folder_name = "images"
outputlocation = "" outputlocation = ""
...@@ -514,7 +515,7 @@ def text_to_tiff(filename, list_dic, bins): ...@@ -514,7 +515,7 @@ def text_to_tiff(filename, list_dic, bins):
if __name__ == "__main__": if __name__ == "__main__":
scenes = file_extractor("original_images(11)") 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)
......
No preview for this file type
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