When Color Constancy Goes Wrong: Correcting Improperly White-Balanced Images

Aug 9, 2023 | Data Science

Color is a crucial element in photography and visual arts, and ensuring that images are white-balanced appropriately is vital for achieving realism. In this article, we explore the technical aspects of correcting improperly white-balanced images, as presented in the study by Mahmoud Afifi, Brian Price, Scott Cohen, and Michael S. Brown.

Understanding the Color Constancy Challenge

Imagine you’re in a bakery filled with delectable pastries under different colored lights — blue, yellow, and red. While the pastries look fabulous, the colors appear distorted. This scenario illustrates the challenge of color constancy, where the brain struggles to interpret true colors under varying lighting conditions, similar to how a camera might misinterpret colors during photo capture. Fortunately, the authors of this paper present a method to correct these color misrepresentation issues.

Getting Started: Quick Installation

  • For Matlab Users:
    • Run install_.m
    • Run demo.m to process a single image or demo_images.m for processing all images in a directory.
    • Check evaluation_examples.m for reporting errors with different metrics.
  • For Python Users:
    • Ensure you have numpy, opencv-python, and skimage installed.
    • Run demo.py to process an image or demo_images.py for multiple images.
    • Refer to evaluation_examples.py for evaluation metrics reporting.

Graphical User Interface (GUI)

An interactive GUI for Matlab is provided to facilitate parameter tuning intuitively. You can explore it via demo_GPU.m.

Parameter Tuning

Optimizing the code’s performance requires adjusting several parameters:

  • K: The number of nearest neighbors for KNN search.
  • sigma: The fall-off factor for KNN blending.
  • device: Choose between GPU or CPU.
  • gamut_mapping: Decide on scaling or clipping options for pixel mapping.
  • upgraded_model: Load the upgraded model for potentially enhanced results.

Dataset

The primary dataset includes over 65,000 images, with a total of 105,638 rendered images for comprehensive testing. You can download these useful resources through the following links:

  • Input Images – [Download (PNG lossless compression)](https://ln2.sync.com/dl/21ce83f60v36jwspj-e4mw2vtb-s6ifkgmv-jzc8mvya)
  • Ground-truth Images – [Download](https://ln2.sync.com/dl/1f607c380ypyw5z4p-q765pviu-rc8tzi2n-4pyyep8h)

Working with Videos

This project also offers an option for video processing. Each frame can be processed independently, although some flickering may occur due to lack of temporal coherence.

Troubleshooting

While running the code, you might encounter some issues:

  • Ensure your Python or Matlab environment is set up correctly.
  • Confirm that all necessary libraries and dependencies are installed.
  • Adjust the parameters if the output seems off or unsatisfactory.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Closing Thoughts

Understanding the intricacies of color correction in images can significantly enhance visual fidelity. This study bridges the gap between theory and practical application, providing both Matlab and Python solutions to a common problem in photography. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox