Skip to main content
Participating Frequently
January 23, 2019
Question

How to compare multiple colors to one another

  • January 23, 2019
  • 3 replies
  • 1199 views

Hi,
Im currently writing a script for Photoshop in Extendscript. Now Im trying to figure out, how to compare colors to each other. I've mostly tried to stick to wikipedias article about comparing colors and using a weighed eucledian algorithm to get a distance which indicates their difference. Comparing 2 colors is no problem with that.

But in my script I have 3 Inputs (Most common color, second most common color, and the third most common color). Now if I want to compare this to their aquivalent part, lets say I have a Main_tile with their 3 Inputs and a Tile_file with 3 Inputs, I can compare (Common to common, second common to second common..), which seems to work fine.

My question is what happens if my Tile_file has only 1 Input, how do I compare it to the Main_tile?

Example: 3 Main, 1 Tile color given. I could pick the most common main color only and compare most common to most common but this number would always be lower than comparing 3x3 colors to one another, so I would pick the lowest number, hence the lowest color difference, which is not really what I want. Any ideas on this topic?

I tried to make everything clear, but if theres something unclear just tell me!

Thanks in advance for the help!

This topic has been closed for replies.

3 replies

c.pfaffenbichler
Community Expert
Community Expert
January 28, 2019

Maybe you should check out this thread:

https://www.ps-scripts.com/viewtopic.php?t=7743&start=10

Chuck Uebele
Community Expert
Community Expert
January 25, 2019

I don't know about that.

c.pfaffenbichler
Community Expert
Community Expert
January 24, 2019

Quite frankly the math is beyond me but I do not even understand what you mean exactly by

Most common color, second most common color, and the third most common color

How do you determine those and do you factor in some tolerance?

And what do you mean when you say the tile may have only one color – is I really just a flat color or …?

Some screenshots might help illustrate.

TK289Author
Participating Frequently
January 24, 2019

Currently I cant provide screenshots, but I'll try to further elaborate what I mean:

Im using the Photoshop colorpicker to get the average colors from a picture. Then I sort them and I get returned the most common color from a picture and so on.
Now I can compare them with another picture and if theyre equal, I will paste them in (Im creating a Photomosaic).

But if the picture im providing is pure black (0,0,0), I wont get a second most common color.
My question is, how do I compare them with the other picture which might have (20,20,30, 40,30,20, 10,20,30) ?
Only comparing (20,20,30 to 0,0,0) doenst make any sense, right?

Chuck Uebele
Community Expert
Community Expert
January 24, 2019

As far as I can tell, if you have fewer colors, you need to include either an if statement or a switch to run code that only compares a certain number of colors.