The new program can even pinpoint expressions for complex or seemingly contradictory emotions such as "sadly angry" or "happily disgusted," according to the Ohio State University researchers.
They said their achievement will help scientists map emotion in the brain with greater accuracy than before, and could help in the diagnosis and treatment of conditions such as autism and post-traumatic stress disorder.
Until now, limits on reading facial expressions restricted scientists to studying six basic emotions: happy, sad, fearful, angry, disgusted and surprised.
"We've gone beyond facial expressions for simple emotions like happy or sad," Aleix Martinez, a cognitive scientist and associate professor of electrical and computer engineering, said in a university news release. "We found a strong consistency in how people move their facial muscles to express 21 categories of emotions."
"That is simply stunning," he said. "That tells us that these 21 emotions are expressed in the same way by nearly everyone, at least in our culture."
The researchers created the computer program by taking 5,000 photos of 130 women and 100 men making faces in response to statements such as, "You just got some great unexpected news" (happily surprised), or, "You smell a bad odor" (disgusted).
Analysis of the facial muscles in the photos enabled the team to identify expressions linked to 21 emotions, according to the study, which was published in this week's issue of the journal Proceedings of the National Academy of Sciences.
The American Academy of Family Physicians explains how emotions affect your health.