Skip to content

Commit

Permalink
Merge pull request #1772 from pierotofy/blacklevel
Browse files Browse the repository at this point in the history
Add black level support for certain DJI drones
  • Loading branch information
pierotofy authored Jul 1, 2024
2 parents 9acbaf5 + b5f0fd9 commit 186b4c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
17 changes: 7 additions & 10 deletions opendm/multispectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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..)
Expand Down
11 changes: 11 additions & 0 deletions opendm/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 186b4c9

Please sign in to comment.