fix: denoise

This commit is contained in:
Hinnka committed 2026-03-22 10:35:30 +08:00
1 parent 88a3f9c3e9
commit 3597ff6b17
4 files changed
+24 -11

No files matched your search

@@ -973,9 +973,9 @@ class LutImageProcessor {
val texelW = 1.0f / width
val texelH = 1.0f / height
// 将降噪强度映射到合理范围 (0.01 ~ 0.1)
val h = 0.01f + noiseReduction * noiseReduction * 4f
val ch = 0.01f + chromaNoiseReduction * chromaNoiseReduction * 2f
// 将降噪强度映射到合理范围 (0.001 ~ 0.1)
val h = 0.001f + noiseReduction * noiseReduction * 0.2f
val ch = 0.001f + chromaNoiseReduction * chromaNoiseReduction * 0.2f
val identityMatrix = FloatArray(16)
android.opengl.Matrix.setIdentityM(identityMatrix, 0)
@@ -1092,18 +1092,22 @@ class RawDemosaicProcessor {
val noiseBase = (sqrt((s * 1e-3f + o * 1e-6f).toDouble()).toFloat() * 100.0f)
// 动态计算 h 值 (衰减系数)
// 规则:基础强度 + 增益强度系数 + 传感器噪声水平系数
// 使用 sqrt(totalGain) 是因为噪声标准差随增益的平方根增加(近似)
val noise = if (noiseBase > 0f) {
noiseBase * denoiseValue * 0.5f + 0.002f * sqrt(totalGain.toDouble()).toFloat()
// 让 noiseProfile 的基础噪声和总增益都更明显地参与估算:
// 1. noiseBase 直接决定主体强度
// 2. totalGain 同时以 sqrt 与线性两部分参与,提升高增益场景下的去噪力度
val gainSqrt = sqrt(totalGain.toDouble()).toFloat()
val gainNoise = denoiseValue * (0.0035f * gainSqrt + 0.0006f * totalGain)
val baseNoise = if (noiseBase > 0f) {
noiseBase * denoiseValue * 0.8f
} else {
denoiseValue * 0.008f * sqrt(totalGain.toDouble()).toFloat()
denoiseValue * 0.010f * gainSqrt
}
val noise = baseNoise + gainNoise
val h = noise.coerceIn(0.001f, 0.1f)
PLog.d(
TAG,
"Dynamic NLM: totalGain=${"%.2f".format(totalGain)} (ISO=$isoGain, Boost=$digitalGain, Post=$postGain), noiseBase=$noiseBase, h=$h"
"Dynamic NLM: totalGain=${"%.2f".format(totalGain)} (ISO=$isoGain, Boost=$digitalGain, Post=$postGain), noiseBase=$noiseBase, baseNoise=$baseNoise, gainNoise=$gainNoise, h=$h"
)
val identityMatrix = FloatArray(16)
@@ -672,7 +672,7 @@ fun PhotoEditScreen(
viewModel = cameraViewModel,
rawProfile = rawProfile,
rawNlmNoiseFactor = editRawNlmNoiseFactor,
onRawNlmNoiseFactorChange = viewModel::setRawDenoiseValue,
onRawNlmNoiseFactorChange = { viewModel.saveRawDenoiseValue(currentPhoto, it) },
modifier = Modifier.fillMaxWidth()
)
} else if (editTab == 3) {
@@ -1392,8 +1392,17 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
editChromaNoiseReduction.value = value
}
fun setRawDenoiseValue(value: Float) {
fun saveRawDenoiseValue(photoData: PhotoData, value: Float) {
editRawDenoise.value = value
viewModelScope.launch {
val metadata = photoData.metadata?.copy(
rawDenoiseValue = editRawDenoise.value,
)
val context = getApplication<Application>()
metadata?.let {
PhotoManager.saveMetadata(context, photoData.id, it)
}
}
}
/**