Auto-detect and fix inverted colors

- Detect inverted colors by checking mean brightness
- Automatically invert if mean > 0.7 (indicating mostly white/bright)
- Print warning when color correction is applied
parent 1e1ea201
...@@ -10188,6 +10188,14 @@ def main(args): ...@@ -10188,6 +10188,14 @@ def main(args):
if frames.min() < 0: if frames.min() < 0:
# Convert from [-1, 1] to [0, 1] # Convert from [-1, 1] to [0, 1]
frames = (frames + 1.0) / 2.0 frames = (frames + 1.0) / 2.0
# Check if colors appear inverted (mostly dark images mean inverted)
# Inverted images have mean > 0.5 when they should be < 0.5
mean_val = np.mean(frames)
if mean_val > 0.7: # Likely inverted
print(f" ⚠️ Detected inverted colors (mean={mean_val:.2f}), correcting...")
frames = 1.0 - frames
# Now convert from [0, 1] to [0, 255] # Now convert from [0, 1] to [0, 255]
frames = np.clip(frames, 0.0, 1.0) * 255 frames = np.clip(frames, 0.0, 1.0) * 255
frames = frames.astype(np.uint8) frames = frames.astype(np.uint8)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment