An apparatus, comprising: an input, which, in operation, receives image data; digital image processing circuitry, which, in operation: determines a shadow threshold intensity based on the image data; sets a minimum signal-to-noise ratio for each exposure of a plurality of exposures; determines, for each merge transition between the exposures of the plurality of exposures having a respective plurality of exposure times, a respective threshold integration ratio based on a respective threshold signal-to-noise ratio for the merge transition, wherein the threshold integration ratio for each respective merge transition between exposures is a threshold integration time ratio between the corresponding exposures that satisfies the threshold signal-to-noise ratio for a respective merge transition; determines, based on the shadow threshold intensity, an integration ratio for each merge transition between the exposures of the plurality of exposures, wherein the integration ratio for a merge transition between exposures is a ratio of integration times for the corresponding exposures, whereby the determined integration ratio for each merge transition optimizes a signal-to-noise ratio for all of the plurality of exposures subject to the threshold integration ratio and the minimum signal-to-noise ratio for the respective exposure for each of the plurality of exposures by adjusting the integration ratios between the exposures; and generates an output image based on the determined integration ratios. an input, which, in operation, receives image data; digital image processing circuitry, which, in operation: determines a shadow threshold intensity based on the image data; sets a minimum signal-to-noise ratio for each exposure of a plurality of exposures; determines, for each merge transition between the exposures of the plurality of exposures having a respective plurality of exposure times, a respective threshold integration ratio based on a respective threshold signal-to-noise ratio for the merge transition, wherein the threshold integration ratio for each respective merge transition between exposures is a threshold integration time ratio between the corresponding exposures that satisfies the threshold signal-to-noise ratio for a respective merge transition; determines, based on the shadow threshold intensity, an integration ratio for each merge transition between the exposures of the plurality of exposures, wherein the integration ratio for a merge transition between exposures is a ratio of integration times for the corresponding exposures, whereby the determined integration ratio for each merge transition optimizes a signal-to-noise ratio for all of the plurality of exposures subject to the threshold integration ratio and the minimum signal-to-noise ratio for the respective exposure for each of the plurality of exposures by adjusting the integration ratios between the exposures; and generates an output image based on the determined integration ratios. determines a shadow threshold intensity based on the image data; sets a minimum signal-to-noise ratio for each exposure of a plurality of exposures; determines, for each merge transition between the exposures of the plurality of exposures having a respective plurality of exposure times, a respective threshold integration ratio based on a respective threshold signal-to-noise ratio for the merge transition, wherein the threshold integration ratio for each respective merge transition between exposures is a threshold integration time ratio between the corresponding exposures that satisfies the threshold signal-to-noise ratio for a respective merge transition; determines, based on the shadow threshold intensity, an integration ratio for each merge transition between the exposures of the plurality of exposures, wherein the integration ratio for a merge transition between exposures is a ratio of integration times for the corresponding exposures, whereby the determined integration ratio for each merge transition optimizes a signal-to-noise ratio for all of the plurality of exposures subject to the threshold integration ratio and the minimum signal-to-noise ratio for the respective exposure for each of the plurality of exposures by adjusting the integration ratios between the exposures; and generates an output image based on the determined integration ratios.