This commit is contained in:
Vladyslav Usenko 2019-07-11 19:13:03 +02:00
parent 6e7357b250
commit 7919878582
1 changed files with 9 additions and 7 deletions

View File

@ -13,7 +13,7 @@ dataset_path = sys.argv[1]
print(dataset_path) print(dataset_path)
timestamps = np.loadtxt(dataset_path + '/mav0/cam0/data.csv', usecols=[0], delimiter=',', dtype=np.int64) timestamps = np.loadtxt(dataset_path + '/mav0/cam0/data.csv', usecols=[0], delimiter=',', dtype=np.int64)
exposures = np.loadtxt(dataset_path + '/mav0/cam0/exposure.csv', usecols=[1], delimiter=',', dtype=np.int64).astype(np.float64) * 1e-9 exposures = np.loadtxt(dataset_path + '/mav0/cam0/exposure.csv', usecols=[1], delimiter=',', dtype=np.int64).astype(np.float64) * 1e-6
pixel_avgs = list() pixel_avgs = list()
if timestamps.shape[0] != exposures.shape[0]: print("timestamps and exposures do not match") if timestamps.shape[0] != exposures.shape[0]: print("timestamps and exposures do not match")
@ -34,21 +34,23 @@ print(imgs.dtype)
inv_resp = np.arange(256, dtype=np.float64) inv_resp = np.arange(256, dtype=np.float64)
inv_resp[250:] = -1.0 # Use negative numbers to detect oversaturation inv_resp[250:] = -1.0 # Use negative numbers to detect oversaturation
irradiance = imgs[0] / exposures[0]
def opt_irradiance(): def opt_irradiance():
corrected_imgs = inv_resp[imgs] * exposures[:, np.newaxis, np.newaxis] corrected_imgs = inv_resp[imgs] * exposures[:, np.newaxis, np.newaxis]
times = np.ones_like(corrected_imgs) * (exposures**2)[:, np.newaxis, np.newaxis] times = np.ones_like(corrected_imgs) * (exposures**2)[:, np.newaxis, np.newaxis]
times[corrected_imgs < 0] == 0
corrected_imgs[corrected_imgs < 0] == 0
irr = np.sum(corrected_imgs, axis=0) / np.sum(times, axis=0) times[corrected_imgs < 0] = 0
corrected_imgs[corrected_imgs < 0] = 0
denom = np.sum(times, axis=0)
irr = np.sum(corrected_imgs, axis=0) / denom
irr[denom == 0] = -1.0
return irr return irr
def opt_inv_resp(): def opt_inv_resp():
generated_imgs = irradiance[np.newaxis, :, :] * exposures[:, np.newaxis, np.newaxis] generated_imgs = irradiance[np.newaxis, :, :] * exposures[:, np.newaxis, np.newaxis]
num_pixels_by_intensity = np.bincount(imgs.flat) num_pixels_by_intensity = np.bincount(imgs.flat, generated_imgs.flat >= 0)
sum_by_intensity = np.bincount(imgs.flat, generated_imgs.flat) sum_by_intensity = np.bincount(imgs.flat, generated_imgs.flat)
new_inv_resp = inv_resp new_inv_resp = inv_resp
@ -64,7 +66,6 @@ def print_error():
generated_imgs[imgs == 255] = 0 generated_imgs[imgs == 255] = 0
print(np.sum(generated_imgs**2)) print(np.sum(generated_imgs**2))
print_error()
for iter in range(3): for iter in range(3):
irradiance = opt_irradiance() irradiance = opt_irradiance()
print_error() print_error()
@ -72,6 +73,7 @@ for iter in range(3):
print_error() print_error()
plt.figure() plt.figure()
plt.plot(inv_resp) plt.plot(inv_resp)
plt.ylabel('Img Mean') plt.ylabel('Img Mean')