summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ipa/ipu3/algorithms/agc.cpp21
-rw-r--r--src/ipa/ipu3/algorithms/agc.h4
2 files changed, 11 insertions, 14 deletions
diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp
index db76d6ef..4e424857 100644
--- a/src/ipa/ipu3/algorithms/agc.cpp
+++ b/src/ipa/ipu3/algorithms/agc.cpp
@@ -79,8 +79,8 @@ static constexpr uint32_t kMaxLuminance = 255;
static constexpr double kNormalizedLumaTarget = 0.16;
Agc::Agc()
- : frameCount_(0), iqMean_(0.0), lineDuration_(0s), minExposureLines_(0),
- maxExposureLines_(0), filteredExposure_(0s), currentExposure_(0s)
+ : frameCount_(0), iqMean_(0.0), lineDuration_(0s), minShutterSpeed_(0s),
+ maxShutterSpeed_(0s), filteredExposure_(0s), currentExposure_(0s)
{
}
@@ -99,17 +99,16 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)
lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s
/ configInfo.sensorInfo.pixelRate;
- /* \todo replace the exposure in lines storage with time based ones. */
- minExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_;
- maxExposureLines_ = std::min(context.configuration.agc.maxShutterSpeed / lineDuration_,
- kMaxShutterSpeed / lineDuration_);
+ minShutterSpeed_ = context.configuration.agc.minShutterSpeed;
+ maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed,
+ kMaxShutterSpeed);
minAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);
maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);
/* Configure the default exposure and gain. */
context.frameContext.agc.gain = minAnalogueGain_;
- context.frameContext.agc.exposure = minExposureLines_;
+ context.frameContext.agc.exposure = minShutterSpeed_ / lineDuration_;
return 0;
}
@@ -236,11 +235,9 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain)
* exposure value applied multiplied by the new estimated gain.
*/
currentExposure_ = effectiveExposureValue * evGain;
- utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_;
- utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_;
/* Clamp the exposure value to the min and max authorized */
- utils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_;
+ utils::Duration maxTotalExposure = maxShutterSpeed_ * maxAnalogueGain_;
currentExposure_ = std::min(currentExposure_, maxTotalExposure);
LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_
<< ", maximum is " << maxTotalExposure;
@@ -250,14 +247,14 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double currentYGain)
/* Divide the exposure value as new exposure and gain values */
utils::Duration exposureValue = filteredExposure_;
- utils::Duration shutterTime = minShutterSpeed;
+ utils::Duration shutterTime;
/*
* Push the shutter time up to the maximum first, and only then
* increase the gain.
*/
shutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain_,
- minShutterSpeed, maxShutterSpeed);
+ minShutterSpeed_, maxShutterSpeed_);
double stepGain = std::clamp(exposureValue / shutterTime,
minAnalogueGain_, maxAnalogueGain_);
LOG(IPU3Agc, Debug) << "Divided up shutter and gain are "
diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h
index 17a5d1d9..31c5a6e5 100644
--- a/src/ipa/ipu3/algorithms/agc.h
+++ b/src/ipa/ipu3/algorithms/agc.h
@@ -45,8 +45,8 @@ private:
double iqMean_;
utils::Duration lineDuration_;
- uint32_t minExposureLines_;
- uint32_t maxExposureLines_;
+ utils::Duration minShutterSpeed_;
+ utils::Duration maxShutterSpeed_;
double minAnalogueGain_;
double maxAnalogueGain_;
>array(means), 0, None) sq_means = np.sqrt(means) """ least squares fit model """ fit = np.polyfit(sq_means, stds, 1) Cam.log += '\nBlack level = {}'.format(Img.blacklevel_16) Cam.log += '\nNoise profile: offset = {}'.format(int(fit[1])) Cam.log += ' slope = {:.3f}'.format(fit[0]) """ remove any values further than std from the fit anomalies most likely caused by: > ucharacteristically noisy white patch > saturation in the white patch """ fit_score = np.abs(stds - fit[0]*sq_means - fit[1]) fit_std = np.std(stds) fit_score_norm = fit_score - fit_std anom_ind = np.where(fit_score_norm > 1) fit_score_norm.sort() sq_means_clean = np.delete(sq_means, anom_ind) stds_clean = np.delete(stds, anom_ind) removed = len(stds) - len(stds_clean) if removed != 0: Cam.log += '\nIdentified and removed {} anomalies.'.format(removed) Cam.log += '\nRecalculating fit' """ recalculate fit with outliers removed """ fit = np.polyfit(sq_means_clean, stds_clean, 1) Cam.log += '\nNoise profile: offset = {}'.format(int(fit[1])) Cam.log += ' slope = {:.3f}'.format(fit[0]) """ if fit const is < 0 then force through 0 by dividing by sq_means and fitting poly order 0 """ corrected = 0 if fit[1] < 0: corrected = 1 ones = np.ones(len(means)) y_data = stds/sq_means fit2 = np.polyfit(ones, y_data, 0) Cam.log += '\nOffset below zero. Fit recalculated with zero offset' Cam.log += '\nNoise profile: offset = 0' Cam.log += ' slope = {:.3f}'.format(fit2[0]) # print('new fit') # print(fit2) """ plot fit for debug """ if plot: x = np.arange(sq_means.max()//0.88) fit_plot = x*fit[0] + fit[1] plt.scatter(sq_means, stds, label='data', color='blue') plt.scatter(sq_means[anom_ind], stds[anom_ind], color='orange', label='anomalies') plt.plot(x, fit_plot, label='fit', color='red', ls=':') if fit[1] < 0: fit_plot_2 = x*fit2[0] plt.plot(x, fit_plot_2, label='fit 0 intercept', color='green', ls='--') plt.plot(0, 0) plt.title('Noise Plot\nImg: {}'.format(Img.str)) plt.legend(loc='upper left') plt.xlabel('Sqrt Pixel Value') plt.ylabel('Noise Standard Deviation') plt.grid() plt.show() """ End of plotting code """ """ format output to include forced 0 constant """ Cam.log += '\n' if corrected: fit = [fit2[0], 0] return fit else: return fit