def dnb_scale(img, fillValue=-999.0, solarZenithAngle=None, highAngleCutoff=None, lowAngleCutoff=None, out=None): """ This scaling method uses histogram equalization to flatten the image levels across the day and night regions. The img data will be separated into day, night, and mixed regions using the solarZenithAngle data. The highAngleCutoff and lowAngleCutoff define the points between the regions. If data points do not have a corresponding solarZenithAngle, they will be considered to be invalid data and set to fill values. """ if out is None: out = numpy.zeros_like(img) # build the day and night area masks LOG.debug("Generating day, night, and mixed region masks...") day_mask, mixed_mask, night_mask, good_mask = \ _make_day_night_masks(img, solarZenithAngle, fillValue, highAngleCutoff=highAngleCutoff, lowAngleCutoff=lowAngleCutoff) # has_multi_times = (mixed_mask is not None) and (len(mixed_mask) > 0) if day_mask is not None and day_mask.any(): LOG.debug(" scaling DNB in day mask") histogram_equalization(img, day_mask, out=out) if mixed_mask is not None and (len(mixed_mask) > 0): LOG.debug(" scaling DNB in twilight mask") for mask in mixed_mask: histogram_equalization(img, mask, out=out) if night_mask is not None and night_mask.any(): LOG.debug(" scaling DNB in night mask") histogram_equalization(img, night_mask, out=out) # set any data that's not in the good areas to fill out[~good_mask] = fillValue return out
def dnb_scale(img, fillValue=-999.0, solarZenithAngle=None, highAngleCutoff=None, lowAngleCutoff=None, out=None): """ This scaling method uses histogram equalization to flatten the image levels across the day and night regions. The img data will be separated into day, night, and mixed regions using the solarZenithAngle data. The highAngleCutoff and lowAngleCutoff define the points between the regions. If data points do not have a corresponding solarZenithAngle, they will be considered to be invalid data and set to fill values. """ if out is None: out = numpy.zeros_like(img) # build the day and night area masks LOG.debug("Generating day, night, and mixed region masks...") day_mask, mixed_mask, night_mask, good_mask = \ _make_day_night_masks(img, solarZenithAngle, fillValue, highAngleCutoff=highAngleCutoff, lowAngleCutoff=lowAngleCutoff) # has_multi_times = (mixed_mask is not None) and (len(mixed_mask) > 0) if day_mask is not None and day_mask.any(): LOG.debug(" scaling DNB in day mask") histogram_equalization(img, day_mask, out=out) if mixed_mask is not None and (len(mixed_mask) > 0): LOG.debug(" scaling DNB in twilight mask") for mask in mixed_mask: histogram_equalization(img, mask, out=out) if night_mask is not None and night_mask.any(): LOG.debug(" scaling DNB in night mask") histogram_equalization(img, night_mask, out=out) # set any data that's not in the good areas to fill out[~good_mask] = fillValue return out
def adaptive_dnb_scale(img, fillValue=-999.0, solarZenithAngle=None, lunarZenithAngle=None, moonIllumFraction=None, highAngleCutoff=None, lowAngleCutoff=None, waterMask=None, out=None): """This scaling method uses histogram equalization to flatten the image levels across the day and night regions. The img data will be separated into day, night, and mixed regions using the solarZenithAngle data. The highAngleCutoff and lowAngleCutoff define the points between the regions. If data points do not have a corresponding solarZenithAngle, they will be considered to be invalid data and set to fill values. The night region will be equalized using settings determined by the amount of moonlight in the scene (as determined by the moonIllumFraction and the lunarZenithAngle). FIXME: The below shouldn't need to be true If `out` is provided it must be a writable copy of the original DNB data. """ if img is out: LOG.error("Out array can not be the same as the input array") raise ValueError("Out array can not be the same as the input array") if out is None: out = numpy.zeros_like(img) # build the day and night area masks LOG.debug("Generating day, night, and mixed region masks...") day_mask, mixed_mask, night_mask, good_mask = \ _make_day_night_masks(img, solarZenithAngle, fillValue, highAngleCutoff=highAngleCutoff, lowAngleCutoff=lowAngleCutoff) has_multi_times = (mixed_mask is not None) and (len(mixed_mask) > 0) night_water = None # a mask of water at night if day_mask is not None and day_mask.any(): LOG.debug(" scaling DNB in day mask") if has_multi_times: local_histogram_equalization(img, day_mask, valid_data_mask=good_mask, local_radius_px=400, out=out) else: histogram_equalization(img, day_mask, out=out) if mixed_mask is not None and len(mixed_mask) > 0: LOG.debug(" scaling DNB in twilight mask") for mask in mixed_mask: local_histogram_equalization(img, mask, valid_data_mask=good_mask, local_radius_px=100, out=out) if night_mask is not None and night_mask.any(): LOG.debug(" scaling DNB in night mask") # log.debug("Moon Illumination, before angle weighting: " + str(moonIllumFraction)) # weightedMoonIllumFract = _calculate_average_moon_illumination (moonIllumFraction, # lunarZenithAngle, # good_mask) # log.debug("Moon Illumination, after angle weighting: " + str(weightedMoonIllumFract)) # # # TODO, this should probably also be affected by whether or not there is a day mask # if weightedMoonIllumFract > 0.90 : # if has_multi_times : # local_histogram_equalization(img, night_mask, valid_data_mask=good_mask, local_radius_px=100, out=out) # else : # histogram_equalization(img, night_mask, out=out) # else : # # FUTURE, for now we're not using the water mask # #night_water = night_mask & waterMask # #tmp_night_mask = night_mask & ~waterMask # tmp_night_mask = night_mask # if weightedMoonIllumFract > 0.25 : # local_histogram_equalization(img, tmp_night_mask, valid_data_mask=good_mask, local_radius_px=200, out=out) # elif weightedMoonIllumFract > 0.10 : # local_histogram_equalization(img, tmp_night_mask, valid_data_mask=good_mask, local_radius_px=100, out=out) # else : # local_histogram_equalization(img, tmp_night_mask, valid_data_mask=good_mask, local_radius_px=50, out=out) histogram_equalization(img, night_mask, out=out) # if night_water is not None and (numpy.any(night_water)): # log.debug (" scaling DNB in night water mask") # local_histogram_equalization(img, night_water, valid_data_mask=good_mask, local_radius_px=500, out=out) # set any data that's not in the good areas to fill out[~good_mask] = fillValue return out
def adaptive_dnb_scale(img, fillValue=-999.0, solarZenithAngle=None, lunarZenithAngle=None, moonIllumFraction=None, highAngleCutoff=None, lowAngleCutoff=None, waterMask=None, out=None): """This scaling method uses histogram equalization to flatten the image levels across the day and night regions. The img data will be separated into day, night, and mixed regions using the solarZenithAngle data. The highAngleCutoff and lowAngleCutoff define the points between the regions. If data points do not have a corresponding solarZenithAngle, they will be considered to be invalid data and set to fill values. The night region will be equalized using settings determined by the amount of moonlight in the scene (as determined by the moonIllumFraction and the lunarZenithAngle). FIXME: The below shouldn't need to be true If `out` is provided it must be a writable copy of the original DNB data. """ if img is out: LOG.error("Out array can not be the same as the input array") raise ValueError("Out array can not be the same as the input array") if out is None: out = numpy.zeros_like(img) # build the day and night area masks LOG.debug("Generating day, night, and mixed region masks...") day_mask, mixed_mask, night_mask, good_mask = \ _make_day_night_masks(img, solarZenithAngle, fillValue, highAngleCutoff=highAngleCutoff, lowAngleCutoff=lowAngleCutoff) has_multi_times = (mixed_mask is not None) and (len(mixed_mask) > 0) night_water = None # a mask of water at night if day_mask is not None and day_mask.any(): LOG.debug(" scaling DNB in day mask") if has_multi_times: local_histogram_equalization(img, day_mask, valid_data_mask=good_mask, local_radius_px=400, out=out) else: histogram_equalization(img, day_mask, out=out) if mixed_mask is not None and len(mixed_mask) > 0: LOG.debug(" scaling DNB in twilight mask") for mask in mixed_mask: local_histogram_equalization(img, mask, valid_data_mask=good_mask, local_radius_px=100, out=out) if night_mask is not None and night_mask.any(): LOG.debug(" scaling DNB in night mask") # log.debug("Moon Illumination, before angle weighting: " + str(moonIllumFraction)) # weightedMoonIllumFract = _calculate_average_moon_illumination (moonIllumFraction, # lunarZenithAngle, # good_mask) # log.debug("Moon Illumination, after angle weighting: " + str(weightedMoonIllumFract)) # # # TODO, this should probably also be affected by whether or not there is a day mask # if weightedMoonIllumFract > 0.90 : # if has_multi_times : # local_histogram_equalization(img, night_mask, valid_data_mask=good_mask, local_radius_px=100, out=out) # else : # histogram_equalization(img, night_mask, out=out) # else : # # FUTURE, for now we're not using the water mask # #night_water = night_mask & waterMask # #tmp_night_mask = night_mask & ~waterMask # tmp_night_mask = night_mask # if weightedMoonIllumFract > 0.25 : # local_histogram_equalization(img, tmp_night_mask, valid_data_mask=good_mask, local_radius_px=200, out=out) # elif weightedMoonIllumFract > 0.10 : # local_histogram_equalization(img, tmp_night_mask, valid_data_mask=good_mask, local_radius_px=100, out=out) # else : # local_histogram_equalization(img, tmp_night_mask, valid_data_mask=good_mask, local_radius_px=50, out=out) histogram_equalization(img, night_mask, out=out) # if night_water is not None and (numpy.any(night_water)): # log.debug (" scaling DNB in night water mask") # local_histogram_equalization(img, night_water, valid_data_mask=good_mask, local_radius_px=500, out=out) # set any data that's not in the good areas to fill out[~good_mask] = fillValue return out