Text Color Predictor


dummy text

click on train to start the network



This is a neural network. It takes the 3 random RGB values of a color and feeds it into the net. It has 3 neurons in the input layer that go into 5 neurons in a hidden layer and finally they all lead to a single neuron in the output layer. That decides whether black text or white text is visible better on the given color.
So it looks somewhat like this:


More or less.
The net is trained using back propagation. The data it trains on is calculated on the spot for every loop. Takes a random color and uses the following snippet to determine the intensity of the color and what text color to use.

function findTextCol(color){
	var threshold = 128 / 256; //threshold should in theory be 186
	 			   //but I settled on that couse it feels better

	var target = color[0] * 0.299 + color[1] * 0.587 + color[2] * 0.114;

	if(target > threshold){
		return 0; //text color should be BLACK
	}else{
		return 1; //text color should be WHITE
	}
}
		

made with passion, by Alexandru Popa