Engineering @ PaperG

Creation

PaperG’s proprietary ad platform, PlaceLocal, is an ad generator that builds ads from the ground up using only the name and location of a business. During the process PlaceLocal searches the web to find relevant information including positive reviews, logos and photos of the small business to create the most applicable and appealing ad — part of the building process is color scheme recognition.

The color scheme for an ad determines the visual aesthetics of the ad. Each color scheme includes a number of complimentary colors that are used for the decorative elements in a given ad design. This includes the border, the background, and even the text itself.

PlaceLocal finds a great color scheme by using image processing to determine which of our color schemes is most complementary to a company’s logo, based on the dominant colors used in it (if there is no logo, PlaceLocal will analyze the dominant colors of the other images selected to run as part of the ad). PlaceLocal selects a color scheme to avoid situations where the color scheme clashes with the emotional intent of the ad. Think about how awful it would be to suggest a lime green color scheme for a dignified ad, or if it was a bright upbeat ad and dark gloomy shades were selected!

There are a number of parts to the process we go through, but before we can walk you through those, we must first talk about color comparison.

In order to determine a color scheme, we have to be able to compare colors. It turns out — from a mathematical perspective — the color wheel that everyone was taught in school doesn’t do us any good. In order to compare colors, we chose to think in terms of a color cube, that is, a three dimensional X-Y-Z graph with values from 0 to 255 for each axis, and measure the “distance” between colors (explained why later).

We use a fairly standard Internet notation when defining colors — (R, G, B). The first number is the amount of red in that pixel, the second number is the amount of green, and the third number is the amount of blue, and these components determine where that color sits within the cube. Zero means that component is not there, and 255 means it’s bright, saturated and fully present. As a result, (0, 0, 0) is black, the absence of all color, and (255, 255, 255) is white since all the colors are present and mixed together. Once we get two colors in the cube, it’s a fairly simple piece of vector math to determine the distance between them.

To process the logo (or any other image), we sample the pixels in it and build a histogram of the color families present. We sample the pixels because if we were to process EVERY pixel, it would take far too long. However, if we were to sample too few pixels in the name of speed, accuracy would suffer. We did extensive testing to strike just the right balance. To define “color family,” here’s an example: if we find a pixel that is (10, 34, 123) (a shade of blue), and then we find another pixel that is (13, 31, 120), by looking at the distance between them, it’s clear that these pixels are in the same color family. We keep track of the count of the number of pixels in each identified color family in the image.  This generates a histogram of the color families and the number of pixels in each family in the logo (or image).

Before looking for the color scheme, we discard each of the colors that aren’t helpful. These are colors that are too close to black (0, 0, 0), too close to white (255, 255, 255), or too close to grey (127, 127, 127). It is interesting to note that while (127, 127, 127) is the central value for grey, any color where all three values are close to each other ((64, 64, 64) for example) are also grey.

We have given each of our color schemes a “nexus” — a point in the three dimensional color cube which best represents that color scheme. It can be the primary color of the scheme itself, an average of the predominant colors, or it may be a hand tuned value. In the creation of the color scheme detector, extensive testing was done to determine the “subjectively best” nexus for each color scheme that consistently generated the best results.

For each color family in the histogram, we find the closest nexus to it, and that color scheme gets a vote equal to the number of pixels in the family. At the end of this process the color scheme with the most votes is the winner; it’s very egalitarian.

Nexus - The color family is closest to the red nexus, so the red color scheme is chosen

While this really is a very simple process, no peek behind the curtain would be complete without telling you that the hard work came in the form of weeks of testing. A sample of what we tested:

  1. Which of the myriad of mathematical representations of color was the best for the PlaceLocal application (this is what led us to the selection of the color cube).
  2. Values for the nexuses and how those values interacted with each other
  3. Speed versus accuracy tradeoff in the sampling of images
  4. Volume in the color cube a color family should be allowed to occupy

We tested everything we could think of to consistently get the best outcome. Testing was the key to the success of this feature!

The next time you see a PlaceLocal ad and wonder, “How did they know (in under a second) that red would be the perfect color scheme for that ad?” This is how.

Submit a comment

You must be logged in to post a comment.