Skip to content

Commit

Permalink
added depth maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Shee-Ra committed Nov 8, 2020
1 parent 80b0ab3 commit 6a557ea
Show file tree
Hide file tree
Showing 30 changed files with 451 additions and 0 deletions.
Binary file added 5_Depth_maps/__pycache__/get_depth.cpython-36.pyc
Binary file not shown.
Binary file added 5_Depth_maps/data/block_left.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5_Depth_maps/data/block_right.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5_Depth_maps/data/cal_image_left_1900.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_left_1920.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_left_1940.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_left_1960.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_left_1980.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_left_2000.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_right_1900.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_right_1920.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_right_1940.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_right_1960.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_right_1980.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/cal_image_right_2000.tiff
Binary file not shown.
Binary file added 5_Depth_maps/data/giraffe_left.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5_Depth_maps/data/giraffe_right.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 5_Depth_maps/data/rubiks_left.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5_Depth_maps/data/rubiks_right.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5_Depth_maps/docs/Worksheet4.pdf
Binary file not shown.
65 changes: 65 additions & 0 deletions 5_Depth_maps/get_depth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from src.functions_2D import *
from PIL import Image
import numpy as np
import time
import logging
from scipy import signal
from scipy import ndimage, misc
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as colors
from scipy.ndimage import gaussian_filter
import numpy.ma as ma

def main(win=30,
o=0.50,
pad=0,
wss=False,
my_lag=True):
filenames=os.listdir('5_Depth_maps/data/')
jpgs = [x for x in filenames if '.jpg' in x]
file_pairs = []

for x in jpgs:
name = x.split('_')[0]
if x.split('_')[1] == 'left.jpg':
file_pairs.append(('5_Depth_maps/data/'+x, '5_Depth_maps/data/'+name+'_right.jpg'))

ims = ['giraffe', 'block', 'rubiks']
for k, p in enumerate(file_pairs):
left, right = load_image_pairs(p)
log.debug('image pair loaded')

try:
# if True:
lags_mapped_to_2D = GetDepthMap(left,
right,
windowsize=win,
overlap=o,
padding=pad,
windowsearch=wss,
use_my_lag_function=my_lag)

# save file
filename=f'5_Depth_maps/data/results/{ims[k]}_mylagfnc_{my_lag}_window_{int(win)}px_overlap_{int(o*100)}pc_padding_{int(pad)}sq.pdf'
cmap = plt.cm.jet
image = cmap(lags_mapped_to_2D)
plt.imshow(lags_mapped_to_2D)
plt.colorbar()
plt.savefig(filename)
plt.clf()
print(f'output saved to {filename}')

except:
print(f'error, likely with overlap, try a smaller overlap')
pass

if __name__ == "__main__":
start = time.time()
main(win=45,
o=0.90,
pad=0,
wss=False,
my_lag=True)
end = time.time()
log.info(f'Time taken: {end-start}s')
59 changes: 59 additions & 0 deletions 5_Depth_maps/parameter_grid_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

from get_depth import *
import numpy as np

# I load the functions python -i 5_Depth_maps/parameter_grid_search.py
# then run in GridSearchDepthHyperParameters in the command line.

def GridSearchDepthHyperParameters(win_search_space=np.unique(np.concatenate((np.linspace(10, 25, 16), np.linspace(5, 50, 10)), axis=0)),
overlap_search_space=np.unique(np.concatenate((np.linspace(0, 0.9, 10), np.linspace(0.7, 0.99, 30)), axis=0)),
padding_search_space=np.linspace(0, 2, 3),
window_search_strategy_search_space=[True, False],
mylagfunc_search_space=[True, False]):
""" Performed parameter search for depth maps.
Args:
win_search_space (1D np array): window search size in pixels. Defaults to np.linspace(5,50,10).
overlap_search_space (1D np array): overlap of windows. Defaults to np.linspace(0.7,0.99,30).
padding_search_space (1D np array): pad window to increase search space. Defaults to np.linspace(0, 2, 3)
window_search_strategy_search_space (list): search in a widow or along a row. Defaults to [True, False].
mylagfunc_search_space (list): uses my 2Dlag function or scipy's signal.correlate. Defaults to [True, False].
"""
filenames=os.listdir('5_Depth_maps/data/')
jpgs = [x for x in filenames if '.jpg' in x]
file_pairs = []

for x in jpgs:
name = x.split('_')[0]
if x.split('_')[1] == 'left.jpg':
file_pairs.append(('5_Depth_maps/data/'+x, '5_Depth_maps/data/'+name+'_right.jpg'))

ims = ['giraffe', 'block', 'rubiks']
for k, p in enumerate(file_pairs):
left, right = load_image_pairs(p)
log.debug('image pair loaded')

for wss in window_search_strategy_search_space:
for b in mylagfunc_search_space:
for win in win_search_space:
for o in overlap_search_space:
for pad in padding_search_space:
try:
lags_mapped_to_2D = GetDepthMap(left,
right,
windowsize=int(win),
overlap=o,
padding=int(pad),
windowsearch=wss,
use_my_lag_function=b)
filename=f'5_Depth_maps/data/research/{ims[k]}_mylagfnc_{b}_winsearch_{wss}_window_{int(win)}px_overlap_{int(o*100)}pc_padding_{int(pad)}sq.pdf'
cmap = plt.cm.jet
image = cmap(lags_mapped_to_2D)
plt.imshow(lags_mapped_to_2D)
plt.colorbar()
# plt.show()
plt.savefig(filename)
plt.clf()
print(f'saved window {int(win)}, overlap {int(o*100)} and padding {int(pad)} with my lag function {b} and window search {wss}')
except:
pass
Binary file not shown.
Loading

0 comments on commit 6a557ea

Please sign in to comment.