Python program that converts a Black & White image to Colored. Uses various ML algorithms such as SVR to predict the color of each pixel.
-
Install Necessary Packages
All the necessary packages can be installed by using pip:
pip install -r requirements.txt
-
Download Dataset
The dataset required to train the model can be created with the help of the web scraper included.
python get-images.py
The script is designed to go on an unlimited loop, terminate the script when necessary amount of images have been downloaded.
-
Train the Model
The model can be easily trained by running the train-model script
python train-model.py
-
Test the Model
In order to test the model you need to pass a black and white as input:
python test-model.py <image_name>
-
Generating Sub squares -
For a given image generate the following -
-
Array of subsquares
-
Array containing average U values for the sub squares
-
Array containing average V values for the sub squares
-
Segmentation -
Segmentation is done to change the representation of the image into something that is more meaningful and easier to analyze.
Functions used -
skimage.util.img_as_float() skimage.data.imread() skimage.segmentation.slic()
-
Get YUV Values - From the RGB values that were found from the segmentation process calculate the YUV values using the conversion matrix.
Use
np.dot()
to calculate dot product. -
Find n_segments -
The N segment of the image will be the maximum value in the segments array plus 1.
-
Computing Centroids -
Create templates of U, V, centroids and point_count using np.zeros()
Iterate through the segments array with the help of np.ndenumerate() and calculate each element in the arrays.
Calculate Centroids, U and V with the help of point_count.
-
Calculate the Sub Square -
Create a template for the Sub Square.
Calculate the sub square using fourier transform with the help of np.ftt.ftt2
-
-
Train Models -
-
Training the base model -
Using sklearn.svm.SVR() train the base models using SVM with constant values of C and Epsilon.
-
Fitting the Model -
Using the fit() function, fit the base model using X, U_L and V_L.
-
Modules Involved -
get-images -- Design a web scraper to get images of landscapes that will end up becoming the data set.train-model -- Utilize Support Vector Regressions to segment and train on the dataset based on YUV colorspace.test-model -- Use multiple layers of SVR on test image then apply Markov Random Fields to find hidden chrominance values and generate an output.