fix: raw noise model green read noise fallback
This commit is contained in:
1 parent
ccc6d53e8e
commit
60aa79a8b8
4 files changed
+46
No files matched your search
@@ -224,6 +224,7 @@ internal class GlesMgcRawBaseFrameSelector(
|
||||
minimumSensitivityIso = frame.minimumSensitivityIso,
|
||||
maximumAnalogSensitivityIso = frame.maximumAnalogSensitivityIso,
|
||||
perFrameCamera2Profile = frame.channelNoiseProfile,
|
||||
cfaPattern = cfaPattern,
|
||||
)
|
||||
check(noiseModel.source != RawNoiseModelSource.UNAVAILABLE) {
|
||||
"Noise model is unavailable for base candidate ${frame.frameNumber}"
|
||||
|
||||
@@ -3385,6 +3385,7 @@ internal class GlesMgcRawSpatialStacker(
|
||||
minimumSensitivityIso = frame.minimumSensitivityIso,
|
||||
maximumAnalogSensitivityIso = frame.maximumAnalogSensitivityIso,
|
||||
perFrameCamera2Profile = frame.channelNoiseProfile,
|
||||
cfaPattern = cfaPattern,
|
||||
)
|
||||
|
||||
private fun noiseModelForFrame(frame: RawStackFrame): RawNoiseModel =
|
||||
|
||||
@@ -26,6 +26,14 @@ class RawNoiseModel private constructor(
|
||||
fun normalizedReadNoiseForShader(cfaPattern: Int = 0): FloatArray =
|
||||
canonicalChannels(readNoise, cfaPattern)
|
||||
|
||||
/**
|
||||
* Spatial's MaximumMergeWeight divides by the canonical Gr read variance, so a profile whose
|
||||
* Gr O term is zero (commonly a negative vendor O clamped by [sanitizeCoefficient]) cannot
|
||||
* drive the merge even though it passes the generic Camera2 validity check.
|
||||
*/
|
||||
fun hasPositiveGreenReadNoise(cfaPattern: Int): Boolean =
|
||||
normalizedReadNoiseForShader(cfaPattern)[1] > 0f
|
||||
|
||||
fun canonicalChannelPairs(cfaPattern: Int = 0): FloatArray {
|
||||
val shot = normalizedShotNoiseForShader(cfaPattern)
|
||||
val read = normalizedReadNoiseForShader(cfaPattern)
|
||||
@@ -202,6 +210,7 @@ internal object RawNoiseModelResolver {
|
||||
minimumSensitivityIso: Int = 0,
|
||||
maximumAnalogSensitivityIso: Int = 0,
|
||||
perFrameCamera2Profile: FloatArray?,
|
||||
cfaPattern: Int? = null,
|
||||
): ResolvedRawNoiseModel {
|
||||
when (selection) {
|
||||
is RawNoiseProfileSelection.Calibrated -> {
|
||||
@@ -221,6 +230,7 @@ internal object RawNoiseModelResolver {
|
||||
perFrameCamera2Profile
|
||||
?.let(RawNoiseModel::fromCamera2NoiseProfile)
|
||||
?.takeIf { it.hasValidCamera2Profile }
|
||||
?.takeIf { model -> cfaPattern == null || model.hasPositiveGreenReadNoise(cfaPattern) }
|
||||
?.let { model ->
|
||||
return ResolvedRawNoiseModel(model, RawNoiseModelSource.CAMERA2_PER_FRAME)
|
||||
}
|
||||
|
||||
@@ -184,6 +184,40 @@ class RawNoiseModelTest {
|
||||
assertArrayEquals(expected.readNoise, resolved.model.readNoise, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun spatialResolverUsesConfiguredFallbackWhenCanonicalGreenReadTermIsZero() {
|
||||
// GRBG: phase 0 is Gr, so a zero O on the first pair leaves Spatial without Gr read noise.
|
||||
val zeroGreenReadProfile = floatArrayOf(
|
||||
1f, 0f,
|
||||
2f, 20f,
|
||||
3f, 30f,
|
||||
4f, 40f,
|
||||
)
|
||||
|
||||
val generic = RawNoiseModelResolver.resolve(
|
||||
selection = systemSelection,
|
||||
sensitivity = 800,
|
||||
perFrameCamera2Profile = zeroGreenReadProfile,
|
||||
)
|
||||
val spatial = RawNoiseModelResolver.resolve(
|
||||
selection = systemSelection,
|
||||
sensitivity = 800,
|
||||
perFrameCamera2Profile = zeroGreenReadProfile,
|
||||
cfaPattern = 1,
|
||||
)
|
||||
val rggb = RawNoiseModelResolver.resolve(
|
||||
selection = systemSelection,
|
||||
sensitivity = 800,
|
||||
perFrameCamera2Profile = zeroGreenReadProfile,
|
||||
cfaPattern = 0,
|
||||
)
|
||||
|
||||
assertEquals(RawNoiseModelSource.CAMERA2_PER_FRAME, generic.source)
|
||||
assertEquals(RawNoiseModelSource.GCAM_SYSTEM_FALLBACK, spatial.source)
|
||||
assertTrue(spatial.model.hasPositiveGreenReadNoise(cfaPattern = 1))
|
||||
assertEquals(RawNoiseModelSource.CAMERA2_PER_FRAME, rggb.source)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun defaultResolverUsesConfiguredFallbackWhenCamera2ReadTermsAreZero() {
|
||||
val shotOnlyProfile = floatArrayOf(
|
||||
|
||||
Reference in new issue
Block a user