Skip to content

AI-based colorizer in c++ using the Dlib library

License

Notifications You must be signed in to change notification settings

Cydral/Colorify

Repository files navigation

Colorify - AI-Powered Image Colorization with Dlib

image

Colorify is a versatile image colorization program built upon Dlib. It offers a spectrum of advanced techniques for image colorization, including supervised learning methods like classification and regression, alongside cutting-edge self-supervised generative adversarial networks (GANs). Our program empowers users to create two distinct models: one for efficient low-resolution colorization (up to 65K colors) and another for high-resolution colorization, capable of producing images with rich detail and a palette of over 262K colors. Our approach leverages a robust dataset comprising more than 900,000 images, ensuring that our models can colorize images with striking realism and naturalness. Whether you're looking to add subtle tints or bring life to monochrome photographs, Colorify offers a comprehensive solution for all your image colorization needs. Dive into the world of vibrant colors and unleash your creativity with Colorify.

Description

Colorify is a comprehensive C++ application that harnesses the capabilities of generative models to perform automated colorization of black and white images. It employs a sophisticated neuronal architecture to achieve this task. When given a grayscale image as input, Colorify utilizes generative AI models (two pre-calculated models are provided that can also be fine-tuned) to produce a fully colorized version.

The program opens the way to a multitude of use cases. Although it excels in static image enhancement, its potential extends far beyond this, as it can also be used for automated movie colorization. Drawing on the latest developments in the Dlib image processing library, we have also provided a dedicated "ready-to-use" program, designed specifically for video colorization. This comprehensive suite enables users to bring individual images and entire film sequences to life with unrivalled ease and efficiency.

Overview

The Colorify program takes a multi-faceted approach to revitalizing monochromatic images, by employing three distinct methods to generate different models. For the "low resolution" model, we employ a supervised learning approach widely recognized in the literature for this purpose. However, instead of traditional color quantization based on the determination of an index, we implement a color reduction technique. This method automatically creates an index by compressing the "a" and "b" channel values of the Lab color model. The approach simplifies the calculation, which is similar to that used in segmentation, but limits the color palette to a maximum of 65,000 different colors, hence the name "low resolution" for this model.

For those looking for images with a wider, more vibrant color spectrum, we propose an alternative approach. The other method combines supervised learning, in particular regression, to initially calculate a basic model. We then refine this model using a GAN, resulting in a "high-resolution" model capable of producing images with a rich and detailed color range, potentially up to 16 million colors.

Whichever method you choose, the program also offers a progressive display of the results and the performance of the current learning model for the colorization task. Additionally, the backbone used for understanding the intrinsic features of the image can be extracted and injected into each learning process (learning transfer), allowing you to leverage the outcomes of previous training phases for enhanced performance.

Training Data and Process

The training data for the Colorify model consists of a diverse set of about 900k images collected from the Web. These images were randomly extracted using the FFspider program, available here. This rich dataset serves as the foundation for teaching the AI model to understand color relationships and patterns, enabling it to generate accurate and vibrant colorizations.

To enhance the diversity and robustness of the training data, an augmentation method was employed. This method involves extracting random sub-zones of the images, ranging from 85% to 100% of the original size. This augmentation strategy enriches the dataset, enabling the AI model to grasp color relationships and patterns more comprehensively

During the training process, Colorify adopts a unique approach to channel decomposition by utilizing the CIE L*a*b space. Similarly to traditional methods, the network receives the luminance channel directly as input and learns to generate the a and b channels as output. This approach is tailored to each of the three methods employed:

  1. Low-Resolution Model: in this method, we use a classification approach to determine the value of an index, which represents a compressed and compacted version of the a*b channels. This indexing method significantly reduces complexity while allowing a maximum of 65K unique colors for the recomposed color image.
  2. Base Model and Fine-Tuning: for achieving a broader and richer color spectrum, we implement a dual-pronged approach. Initially, a supervised regression-based learning process communicates the expected output masks, comprising two separate channels with variable precision. Then, fine-tuning occurs through the core "[G]enerator/[D]iscriminator" dynamics of a GAN, which refines the learning process.

Each of these methods empowers Colorify to cater to diverse colorization requirements while maintaining flexibility and efficiency.

Models: Colorify's colorization magic

Colorify's colorization prowess is based on a sophisticated neural network model. This model is composed of a ResNet structure with a U-Net architecture, bringing a distinctive advantage to the colorization process.

  • ResNet with U-Net architecture: ResNet is a convolutional neural network renowned for its depth. Paired with the U-Net architecture, this model becomes exceptionally skilled at learning intricate color patterns. U-Net is well-suited for image-to-image translation tasks, as it can seamlessly capture high-level and low-level features simultaneously, resulting in more accurate colorizations.
  • Model complexity: the trained neural network boasts a staggering complexity, with a total of 223 layers and approximately 41.7 million parameters. This formidable structure ensures that Colorify can perform its colorization task with exceptional precision.
  • Training strategy: training this neural network was a multi-step process. Initially, it underwent regression training on a subset of the target database, comprising roughly 10% of the final training dataset. Gradually, more images were introduced into the network, allowing it to adapt and fine-tune its colorization abilities over time.
  • Backbone reusability: Colorify incorporates a feature via the "--[export-backbone|import-backbone]" launch parameter, enabling the reuse of the same backbone across different training methods. For instance, the "low-resolution" model didn't require training from scratch; it leveraged the previously formatted backbone through regression. This flexibility empowers users to efficiently fine-tune models for specific use cases while maintaining the benefits of the established backbone
  • Model persistence: all trained models are meticulously saved post-training. This means that they can be readily utilized for fine-tuning to better align with specific colorization requirements and target use cases.

During training, Colorify processes data in batches, with each batch containing about 20 images. This batch processing approach optimizes the learning process, allowing the neural networks to efficiently extract features and patterns from the training data. Each model undergoes progressive training, with a total of around 700,000 iterations.

Some results

The "samples (highres)" directory presents a compilation of colorization results for images commonly used to illustrate and compare colorization processes. These standard images usually serve as a benchmark, highlighting the program's capability to seamlessly infuse vibrant and realistic colors into everyday visuals.

Taking a leap into artistic expression, the "b&w images from Pexels/highres" directory demonstrates the program's prowess in transforming black and white photographs sourced from the renowned platform, Pexels.com. These images, chosen for their diverse compositions, showcase the program's ability to breathe life into monochromatic captures, producing results that are not only captivating but also artistically compelling. While not all outcomes from the "b&w images from Pexels/highres" directory were selected for formal presentation, they collectively deliver convincingly impressive results. The program's capacity to adapt to various photographic styles and compositions underscores its versatility and potential across a spectrum of creative endeavors.

Disclaimer

Please note that Colorify's colorization algorithm is primarily trained on a dataset consisting of images randomly selected from web sites. While it performs well for similar types of images, it may not yield optimal results for all image types due to the inherent "dataset bias" problem, as mentioned in the document Colorful Image Colorization paper from Richard Zhang, Phillip Isola and Alexei A. Efros.

The algorithm may also produce impressive colorizations; there might occasionally occur what we term as "chromatic aberration." This phenomenon can manifest as traces of blurriness in certain areas of the image along with color saturation. This is mainly attributed to localized "neural saturation" failing to recognize specific patterns. We include these aspects as part of our experimental observations and findings in the colorization process.

Furthermore, despite the substantial size of the training dataset used for the provided DNN model, a "gray-toned effect" (or brownish) might also manifest. This effect reflects a statistical uncertainty regarding the color that the neural network should generate for the specific area (or even the entire image) being processed.

Contributions

Contributions to Colorify are welcome! If you'd like to enhance the program or fix any issues, please follow these steps:

  • Fork the repository.
  • Create a new branch for your feature or bug fix.
  • Make your changes and commit them.
  • Push your changes to your forked repository.
  • Create a pull request, detailing the changes you've made.
Enjoy with the Colorify framework!

License

Colorify is released under the MIT License. See the LICENSE file for more details.

About

AI-based colorizer in c++ using the Dlib library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages