still working on the psychovisual model

This commit is contained in:
minjaesong
2025-09-21 01:36:31 +09:00
parent 206e43a308
commit 5d48cc62eb
2 changed files with 50 additions and 42 deletions

View File

@@ -3896,47 +3896,47 @@ class GraphicsJSR223Delegate(private val vm: VM) {
when (subbandType) { when (subbandType) {
0 -> { // LL subband - contains most image energy, preserve carefully 0 -> { // LL subband - contains most image energy, preserve carefully
return when { return when {
level >= 6 -> 0.6f // LL6: High energy but can tolerate moderate quantization (range up to 22K) level >= 6 -> 0.5f // LL6: High energy but can tolerate moderate quantization (range up to 22K)
level >= 5 -> 0.7f // LL5: Good preservation level >= 5 -> 0.7f // LL5: Good preservation
else -> 0.8f // Lower LL levels: Fine preservation else -> 0.9f // Lower LL levels: Fine preservation
} }
} }
1 -> { // LH subband - horizontal details (human eyes more sensitive) 1 -> { // LH subband - horizontal details (human eyes more sensitive)
return when { return when {
level >= 6 -> 0.7f // LH6: Significant coefficients (max ~500), preserve well level >= 6 -> 0.8f // LH6: Significant coefficients (max ~500), preserve well
level >= 5 -> 0.8f // LH5: Moderate coefficients (max ~600) level >= 5 -> 1.0f // LH5: Moderate coefficients (max ~600)
level >= 4 -> 1.0f // LH4: Small coefficients (max ~50) level >= 4 -> 1.2f // LH4: Small coefficients (max ~50)
level >= 3 -> 1.2f // LH3: Very small coefficients, can quantize more level >= 3 -> 1.6f // LH3: Very small coefficients, can quantize more
level >= 2 -> 1.4f // LH2: Minimal impact level >= 2 -> 2.0f // LH2: Minimal impact
else -> 1.6f // LH1: Least important else -> 2.5f // LH1: Least important
} }
} }
2 -> { // HL subband - vertical details (less sensitive due to HVS characteristics) 2 -> { // HL subband - vertical details (less sensitive due to HVS characteristics)
return when { return when {
level >= 6 -> 0.9f // HL6: Can quantize more aggressively than LH6 level >= 6 -> 1.0f // HL6: Can quantize more aggressively than LH6
level >= 5 -> 1.0f // HL5: Standard quantization level >= 5 -> 1.2f // HL5: Standard quantization
level >= 4 -> 1.3f // HL4: Notable range but less critical level >= 4 -> 1.5f // HL4: Notable range but less critical
level >= 3 -> 1.5f // HL3: Can tolerate more quantization level >= 3 -> 2.0f // HL3: Can tolerate more quantization
level >= 2 -> 1.7f // HL2: Less important level >= 2 -> 2.5f // HL2: Less important
else -> 2.0f // HL1: Most aggressive for vertical details else -> 3.5f // HL1: Most aggressive for vertical details
} }
} }
3 -> { // HH subband - diagonal details (least important for HVS) 3 -> { // HH subband - diagonal details (least important for HVS)
return when { return when {
level >= 6 -> 1.1f // HH6: Preserve some diagonal detail level >= 6 -> 1.2f // HH6: Preserve some diagonal detail
level >= 5 -> 1.3f // HH5: Can quantize aggressively level >= 5 -> 1.6f // HH5: Can quantize aggressively
level >= 4 -> 1.6f // HH4: Very aggressive level >= 4 -> 2.0f // HH4: Very aggressive
level >= 3 -> 2.0f // HH3: Minimal preservation level >= 3 -> 2.8f // HH3: Minimal preservation
level >= 2 -> 2.2f // HH2: Maximum compression level >= 2 -> 3.5f // HH2: Maximum compression
else -> 2.5f // HH1: Most aggressive quantization else -> 5.0f // HH1: Most aggressive quantization
} }
} }
else -> 1.0f
} }
} else { } else {
// CHROMA CHANNELS: Less critical for human perception, more aggressive quantization // CHROMA CHANNELS: Less critical for human perception, more aggressive quantization
when (subbandType) { when (subbandType) {
0 -> { // LL chroma - still important but less than luma 0 -> { // LL chroma - still important but less than luma
return 1f
return when { return when {
level >= 6 -> 0.8f // Chroma LL6: Less critical than luma LL level >= 6 -> 0.8f // Chroma LL6: Less critical than luma LL
level >= 5 -> 0.9f level >= 5 -> 0.9f
@@ -3944,6 +3944,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
} }
} }
1 -> { // LH chroma - horizontal chroma details 1 -> { // LH chroma - horizontal chroma details
return 1.8f
return when { return when {
level >= 6 -> 1.0f level >= 6 -> 1.0f
level >= 5 -> 1.2f level >= 5 -> 1.2f
@@ -3954,6 +3955,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
} }
} }
2 -> { // HL chroma - vertical chroma details (even less critical) 2 -> { // HL chroma - vertical chroma details (even less critical)
return 1.3f;
return when { return when {
level >= 6 -> 1.2f level >= 6 -> 1.2f
level >= 5 -> 1.4f level >= 5 -> 1.4f
@@ -3964,6 +3966,7 @@ class GraphicsJSR223Delegate(private val vm: VM) {
} }
} }
3 -> { // HH chroma - diagonal chroma details (most aggressive) 3 -> { // HH chroma - diagonal chroma details (most aggressive)
return 2.5f
return when { return when {
level >= 6 -> 1.4f level >= 6 -> 1.4f
level >= 5 -> 1.6f level >= 5 -> 1.6f
@@ -3973,7 +3976,6 @@ class GraphicsJSR223Delegate(private val vm: VM) {
else -> 2.5f else -> 2.5f
} }
} }
else -> 1.0f
} }
} }
return 1.0f return 1.0f

View File

@@ -800,41 +800,45 @@ static void quantise_dwt_coefficients(float *coeffs, int16_t *quantised, int siz
// Get perceptual weight for specific subband - Data-driven model based on coefficient variance analysis // Get perceptual weight for specific subband - Data-driven model based on coefficient variance analysis
static float get_perceptual_weight(int level, int subband_type, int is_chroma, int max_levels) { static float get_perceptual_weight(int level, int subband_type, int is_chroma, int max_levels) {
// Psychovisual model based on DWT coefficient statistics and Human Visual System sensitivity // Psychovisual model based on DWT coefficient statistics and Human Visual System sensitivity
// strategy: JPEG quantisation table + real-world statistics from the encoded videos
if (!is_chroma) { if (!is_chroma) {
// LUMA CHANNEL: Based on statistical analysis from real video content // LUMA CHANNEL: Based on statistical analysis from real video content
if (subband_type == 0) { // LL subband - contains most image energy, preserve carefully if (subband_type == 0) { // LL subband - contains most image energy, preserve carefully
if (level >= 6) return 0.6f; // LL6: High energy but can tolerate moderate quantization (range up to 22K) if (level >= 6) return 0.5f; // LL6: High energy but can tolerate moderate quantization (range up to 22K)
if (level >= 5) return 0.7f; // LL5: Good preservation if (level >= 5) return 0.7f; // LL5: Good preservation
return 0.8f; // Lower LL levels: Fine preservation return 0.9f; // Lower LL levels: Fine preservation
} else if (subband_type == 1) { // LH subband - horizontal details (human eyes more sensitive) } else if (subband_type == 1) { // LH subband - horizontal details (human eyes more sensitive)
if (level >= 6) return 0.7f; // LH6: Significant coefficients (max ~500), preserve well if (level >= 6) return 0.8f; // LH6: Significant coefficients (max ~500), preserve well
if (level >= 5) return 0.8f; // LH5: Moderate coefficients (max ~600) if (level >= 5) return 1.0f; // LH5: Moderate coefficients (max ~600)
if (level >= 4) return 1.0f; // LH4: Small coefficients (max ~50) if (level >= 4) return 1.2f; // LH4: Small coefficients (max ~50)
if (level >= 3) return 1.2f; // LH3: Very small coefficients, can quantize more if (level >= 3) return 1.6f; // LH3: Very small coefficients, can quantize more
if (level >= 2) return 1.4f; // LH2: Minimal impact if (level >= 2) return 2.0f; // LH2: Minimal impact
return 1.6f; // LH1: Least important return 2.5f; // LH1: Least important
} else if (subband_type == 2) { // HL subband - vertical details (less sensitive due to HVS characteristics) } else if (subband_type == 2) { // HL subband - vertical details (less sensitive due to HVS characteristics)
if (level >= 6) return 0.9f; // HL6: Can quantize more aggressively than LH6 if (level >= 6) return 1.0f; // HL6: Can quantize more aggressively than LH6
if (level >= 5) return 1.0f; // HL5: Standard quantization if (level >= 5) return 1.2f; // HL5: Standard quantization
if (level >= 4) return 1.3f; // HL4: Notable range but less critical if (level >= 4) return 1.5f; // HL4: Notable range but less critical
if (level >= 3) return 1.5f; // HL3: Can tolerate more quantization if (level >= 3) return 2.0f; // HL3: Can tolerate more quantization
if (level >= 2) return 1.7f; // HL2: Less important if (level >= 2) return 2.5f; // HL2: Less important
return 2.0f; // HL1: Most aggressive for vertical details return 3.5f; // HL1: Most aggressive for vertical details
} else { // HH subband - diagonal details (least important for HVS) } else { // HH subband - diagonal details (least important for HVS)
if (level >= 6) return 1.1f; // HH6: Preserve some diagonal detail if (level >= 6) return 1.2f; // HH6: Preserve some diagonal detail
if (level >= 5) return 1.3f; // HH5: Can quantize aggressively if (level >= 5) return 1.6f; // HH5: Can quantize aggressively
if (level >= 4) return 1.6f; // HH4: Very aggressive if (level >= 4) return 2.0f; // HH4: Very aggressive
if (level >= 3) return 2.0f; // HH3: Minimal preservation if (level >= 3) return 2.8f; // HH3: Minimal preservation
if (level >= 2) return 2.2f; // HH2: Maximum compression if (level >= 2) return 3.5f; // HH2: Maximum compression
return 2.5f; // HH1: Most aggressive quantization return 5.0f; // HH1: Most aggressive quantization
} }
} else { } else {
// CHROMA CHANNELS: Less critical for human perception, more aggressive quantization // CHROMA CHANNELS: Less critical for human perception, more aggressive quantization
// strategy: mimic 4:2:2 chroma subsampling
if (subband_type == 0) { // LL chroma - still important but less than luma if (subband_type == 0) { // LL chroma - still important but less than luma
return 1.0f;
if (level >= 6) return 0.8f; // Chroma LL6: Less critical than luma LL if (level >= 6) return 0.8f; // Chroma LL6: Less critical than luma LL
if (level >= 5) return 0.9f; if (level >= 5) return 0.9f;
return 1.0f; return 1.0f;
} else if (subband_type == 1) { // LH chroma - horizontal chroma details } else if (subband_type == 1) { // LH chroma - horizontal chroma details
return 1.8f;
if (level >= 6) return 1.0f; if (level >= 6) return 1.0f;
if (level >= 5) return 1.2f; if (level >= 5) return 1.2f;
if (level >= 4) return 1.4f; if (level >= 4) return 1.4f;
@@ -842,6 +846,7 @@ static float get_perceptual_weight(int level, int subband_type, int is_chroma, i
if (level >= 2) return 1.8f; if (level >= 2) return 1.8f;
return 2.0f; return 2.0f;
} else if (subband_type == 2) { // HL chroma - vertical chroma details (even less critical) } else if (subband_type == 2) { // HL chroma - vertical chroma details (even less critical)
return 1.3f;
if (level >= 6) return 1.2f; if (level >= 6) return 1.2f;
if (level >= 5) return 1.4f; if (level >= 5) return 1.4f;
if (level >= 4) return 1.6f; if (level >= 4) return 1.6f;
@@ -849,6 +854,7 @@ static float get_perceptual_weight(int level, int subband_type, int is_chroma, i
if (level >= 2) return 2.0f; if (level >= 2) return 2.0f;
return 2.2f; return 2.2f;
} else { // HH chroma - diagonal chroma details (most aggressive) } else { // HH chroma - diagonal chroma details (most aggressive)
return 2.5f;
if (level >= 6) return 1.4f; if (level >= 6) return 1.4f;
if (level >= 5) return 1.6f; if (level >= 5) return 1.6f;
if (level >= 4) return 1.8f; if (level >= 4) return 1.8f;