From b5f0fd92c3e588e3d0a3759561313af8cdf61054 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sun, 30 Jun 2024 13:29:20 -0400 Subject: [PATCH] Add BlackCurrent support for DJI, fix multiplication by radio calib coefficient --- opendm/multispectral.py | 17 +++++++---------- opendm/photo.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/opendm/multispectral.py b/opendm/multispectral.py index ff29fa3f1..19767cd43 100644 --- a/opendm/multispectral.py +++ b/opendm/multispectral.py @@ -37,14 +37,6 @@ def dn_to_radiance(photo, image): exposure_time = photo.exposure_time gain = photo.get_gain() gain_adjustment = photo.gain_adjustment - photometric_exp = photo.get_photometric_exposure() - - if a1 is None and photometric_exp is None: - log.ODM_WARNING("Cannot perform radiometric calibration, no FNumber/Exposure Time or Radiometric Calibration EXIF tags found in %s. Using Digital Number." % photo.filename) - return image - - if a1 is None and photometric_exp is not None: - a1 = photometric_exp V, x, y = vignette_map(photo) if x is None: @@ -81,7 +73,9 @@ def dn_to_radiance(photo, image): if gain is not None and exposure_time is not None: image /= (gain * exposure_time) - image *= a1 + if a1 is not None: + # multiply with the radiometric calibration coefficient + image *= a1 if gain_adjustment is not None: image *= gain_adjustment @@ -123,7 +117,10 @@ def vignette_map(photo): def dn_to_reflectance(photo, image, use_sun_sensor=True): radiance = dn_to_radiance(photo, image) irradiance = compute_irradiance(photo, use_sun_sensor=use_sun_sensor) - return radiance * math.pi / irradiance + reflectance = radiance * math.pi / irradiance + reflectance[reflectance < 0.0] = 0.0 + reflectance[reflectance > 1.0] = 1.0 + return reflectance def compute_irradiance(photo, use_sun_sensor=True): # Thermal (this should never happen, but just in case..) diff --git a/opendm/photo.py b/opendm/photo.py index 943ac9420..d6921c0ae 100644 --- a/opendm/photo.py +++ b/opendm/photo.py @@ -413,6 +413,17 @@ def parse_exif_values(self, _path_file): self.set_attr_from_xmp_tag('speed_z', xtags, [ '@drone-dji:FlightZSpeed', ], float) + + # DJI MS + if self.black_level is None and 'Camera:BlackCurrent' in xtags: + self.set_attr_from_xmp_tag('black_level', xtags, [ + 'Camera:BlackCurrent' + ], str) + if '@drone-dji:ExposureTime' in xtags: + self.set_attr_from_xmp_tag('exposure_time', xtags, [ + '@drone-dji:ExposureTime' + ], float) + self.exposure_time /= 1e6 # is in microseconds # Account for over-estimation if self.gps_xy_stddev is not None: