fix irradiance computation

This commit is contained in:
Vladyslav Usenko 2019-07-12 10:56:47 +02:00
parent 7919878582
commit dd087bdbb8
1 changed files with 20 additions and 9 deletions

View File

@ -31,8 +31,13 @@ imgs = np.array(imgs)
print(imgs.shape) print(imgs.shape)
print(imgs.dtype) print(imgs.dtype)
inv_resp = np.arange(256, dtype=np.float64)
inv_resp[250:] = -1.0 # Use negative numbers to detect oversaturation
num_pixels_by_intensity = np.bincount(imgs.flat)
print('num_pixels_by_intensity', num_pixels_by_intensity)
inv_resp = np.arange(num_pixels_by_intensity.shape[0], dtype=np.float64)
inv_resp[-1] = -1.0 # Use negative numbers to detect saturation
def opt_irradiance(): def opt_irradiance():
@ -43,7 +48,9 @@ def opt_irradiance():
corrected_imgs[corrected_imgs < 0] = 0 corrected_imgs[corrected_imgs < 0] = 0
denom = np.sum(times, axis=0) denom = np.sum(times, axis=0)
irr = np.sum(corrected_imgs, axis=0) / denom idx = (denom != 0)
irr = np.sum(corrected_imgs, axis=0)
irr[idx] /= denom[idx]
irr[denom == 0] = -1.0 irr[denom == 0] = -1.0
return irr return irr
@ -51,14 +58,16 @@ 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, generated_imgs.flat >= 0) num_pixels_by_intensity = np.bincount(imgs.flat, generated_imgs.flat >= 0)
generated_imgs[generated_imgs < 0] = 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
idx = np.nonzero(num_pixels_by_intensity > 0) idx = np.nonzero(num_pixels_by_intensity > 0)
new_inv_resp[idx] = sum_by_intensity[idx] / num_pixels_by_intensity[idx] new_inv_resp[idx] = sum_by_intensity[idx] / num_pixels_by_intensity[idx]
new_inv_resp[250:] = -1.0 new_inv_resp[-1] = -1.0 # Use negative numbers to detect saturation
return new_inv_resp return new_inv_resp
def print_error(): def print_error():
generated_imgs = irradiance[np.newaxis, :, :] * exposures[:, np.newaxis, np.newaxis] generated_imgs = irradiance[np.newaxis, :, :] * exposures[:, np.newaxis, np.newaxis]
@ -66,7 +75,7 @@ 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))
for iter in range(3): for iter in range(5):
irradiance = opt_irradiance() irradiance = opt_irradiance()
print_error() print_error()
inv_resp = opt_inv_resp() inv_resp = opt_inv_resp()
@ -75,12 +84,14 @@ for iter in range(3):
plt.figure() plt.figure()
plt.plot(inv_resp) plt.plot(inv_resp[:-1])
plt.ylabel('Img Mean') plt.ylabel('Irradiance Value')
plt.xlabel('Exposure') plt.xlabel('Image Intensity')
plt.title('Inverse Responce Function')
plt.figure() plt.figure()
plt.imshow(irradiance) plt.imshow(irradiance)
plt.title('Irradiance Image')
plt.show() plt.show()