Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/ipa/rpi/controller/rpi/denoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ int DenoiseConfig::read(const libcamera::YamlObject &params)
cdnEnable = params.contains("cdn");
if (cdnEnable) {
auto &cdnParams = params["cdn"];
cdnDeviation = cdnParams["deviation"].get<double>(120);
cdnDeviationNoTdn = cdnParams["deviation_no_tdn"].get<double>(150);
/*
* For backwards compatibility with existing tuning files, interpret "deviation"
* as giving the "no TDN" deviation, where present.
*/
cdnDeviationNoTdn = cdnParams["deviation"].get<double>(cdnDeviationNoTdn);
/*
* A third the value of the no TDN deviation is about right for with-TDN, if
* the user hasn't specified otherwise.
*/
cdnDeviationWithTdn = cdnParams["deviation_with_tdn"].get<double>(cdnDeviationNoTdn / 3);
cdnStrength = cdnParams["strength"].get<double>(0.2);
}

Expand All @@ -48,13 +58,14 @@ int DenoiseConfig::read(const libcamera::YamlObject &params)
tdnThreshold = tdnParams["threshold"].get<double>(0.75);
} else if (sdnEnable) {
/*
* If SDN is enabled but TDN isn't, overwrite all the SDN settings
* If SDN is enabled but TDN isn't, overwrite all the SDN/CDN settings
* with the "no TDN" versions. This makes it easier to enable or
* disable TDN in the tuning file without editing all the other
* parameters.
*/
sdnDeviation = sdnDeviation2 = sdnDeviationNoTdn;
sdnStrength = sdnStrengthNoTdn;
cdnDeviationWithTdn = cdnDeviationNoTdn;
}

return 0;
Expand Down Expand Up @@ -107,6 +118,7 @@ void Denoise::switchMode([[maybe_unused]] CameraMode const &cameraMode,
currentSdnDeviation_ = currentConfig_->sdnDeviationNoTdn;
currentSdnStrength_ = currentConfig_->sdnStrengthNoTdn;
currentSdnDeviation2_ = currentConfig_->sdnDeviationNoTdn;
currentCdnDeviation_ = currentConfig_->cdnDeviationNoTdn;
}

void Denoise::prepare(Metadata *imageMetadata)
Expand Down Expand Up @@ -159,8 +171,12 @@ void Denoise::prepare(Metadata *imageMetadata)

if (currentConfig_->cdnEnable && mode_ != DenoiseMode::ColourOff) {
struct CdnStatus cdn;
cdn.threshold = currentConfig_->cdnDeviation * noiseStatus.noiseSlope + noiseStatus.noiseConstant;
cdn.threshold = currentCdnDeviation_ * noiseStatus.noiseSlope + noiseStatus.noiseConstant;
cdn.strength = currentConfig_->cdnStrength;
/* For the next frame, we back off the CDN deviation as TDN ramps up. */
double f = currentConfig_->sdnTdnBackoff;
currentCdnDeviation_ = f * currentCdnDeviation_ + (1 - f) * currentConfig_->cdnDeviationWithTdn;

imageMetadata->set("cdn.status", cdn);
LOG(RPiDenoise, Debug)
<< "programmed cdn threshold " << cdn.threshold
Expand Down
4 changes: 3 additions & 1 deletion src/ipa/rpi/controller/rpi/denoise.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct DenoiseConfig {
double sdnDeviationNoTdn;
double sdnStrengthNoTdn;
double sdnTdnBackoff;
double cdnDeviation;
double cdnDeviationNoTdn;
double cdnDeviationWithTdn;
double cdnStrength;
double tdnDeviation;
double tdnThreshold;
Expand Down Expand Up @@ -54,6 +55,7 @@ class Denoise : public DenoiseAlgorithm
double currentSdnDeviation_;
double currentSdnStrength_;
double currentSdnDeviation2_;
double currentCdnDeviation_;
};

} // namespace RPiController