/emotapal

A library to pair emotions with colors

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

EmotaPal

WARNING: As of September 20th, 2020 the package is depracated.

pip install emotapal 

Table of Contents

About

An EmotaPal is a palette of words and colors.

Just as a 'color palette' describes the colors of some visual object, an 'emotion palette' describes the emotions felt from a visual object. An EmotaPal combines both pieces (visual and psychological) of information.

Core Data

Functionally, this library provides methods to associate emotions with colors through an EmotaPal object. That object relies on a KNN model which predicts emotions from colors. The model was trained on a dataset constructed by parsing the dominant color of 100 Google Image results for 264 emotions.

For more information on the data, please read here.

Use Cases

Maybe you are an artist and are deciding between what color palettes to use. This, in turn, could depend on the psychological associations a color palette provokes. EmotaPal's from_colors() constructor will return the emotions associated with colors in your color palettes.

Maybe you started a brewery and are interested in how regional companies are positioning themselves. EmotaPal's from_gimg() constructor will allow you to construct an EmotaPal from google images, so you can "scrape" the probable affective responses to your competitor's logos.

Usage

There are 4 ways to construct an EmotaPal.

Constructing an EmotaPal

from emotapal import EmotaPal

e1 = EmotaPal().from_colors(color_list)
e2 = EmotaPal().from_image(some_image, ncolors)
e3 = EmotaPal().from_url(image_url, ncolors)
e4 = EmotaPal().from_gimg(query, nimages)

Constructing an EmotaPal from a list of colors.

"""
Params:
  clrs (list): A list of colors, each element either an RGB tupple or hex string 
  topn (int, optional):  Keep only the topn best (input color, emotion color) matches. 
  unique_words (bool, optional): Keep only the best (shortest distance) match if one emotion matches with
   two colors.
"""
ep = EmotaPal(topn=100, unique_words=False).from_colors(clrs)

Constructing an EmotaPal from an image.

Note: Do not make ncolors too high or you'll pick up non-central colors of an image.

""" 
Params:
  img (image): An image object. 
  ncolors (int): Construct a palette from the topn most dominant colors of an image. 
  topn (int, optional): see above
  unique_words (bool, optional): see above
"""
ep = EmotaPal(topn=100, unique_words=False).from_image(img, ncolors)

Constructing an EmotaPal from a url pointing to an image.

""" 
Params:
  url (str): A url pointing to an image.
  ncolors (int): Construct a palette from the topn colors of an image. 
  topn (int, optional): see above
  unique_words (bool, optional): see above
"""
ep = EmotaPal(topn=100, unique_words=False).from_url(url, ncolors)

Constructing an EmotaPal from a Google Images query.

""" 
Params:
  query (str): A Google Images query. 
  nimages (int): The number of images to scrape.
  topn (int, optional): see above
  unique_words (bool, optional): see above
"""
ep = EmotaPal(topn=100, unique_words=False).from_gimages(query, nimages)

EmotaPal information and methods

ep = EmotaPal().from_url(url)

Return the info of an EmotaPal.

An EmotaPal's info is a list of dictionaries, each element containing information on a color, its associated emotion, and the distance between the input color and emotion color. This dictionary is sorted by distance (ascending order), such that the first entry is the best match and last entry is worst match.

info = ep.info 

Words

words = ep.words.text # return words of EmotaPal
sentiment = ep.words.sentiment # return sentiment of EmotaPal's words

Colors

rgbs = ep.colors.as_rgb # return colors as rgb values
hexs = ep.colors.as_hex # return colors as strings of hex values
ep.colors.display(save_img=False) # display color palette with option to save image