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?

c.pfaffenbichler
Community Expert
Community Expert
January 28, 2019

Not particulary! I didn't measure it but I would say less then a second for analyzing the tiles. So it seems fine for the moment. Paul Riggott's Script looks really interesting, I'll look deeper into it later, thank you!

I've tested the photomosaic with a few small pictures and the color analyzing and comparison seem to work fine, but not for every tile:

(Please dont mind the black frame)

As you can see most of the sample images are placed properly in their tile (there's a resize function missing, so it's not stretched to the tile size yet).


Two things which seem to be kinda off:
1. Analyzing the blue tiles give me more than one most dominant color, theyre both pretty close though. I was thinking that it was because the function mostDominantColor gets too close to the edge and thus gets a brighter color from yellow or a darker from green?

2. Using the weigthed eucledian algorithm puts the pink doc image over the blue tile on the top right. Any ideas why? The distance is about 20 off to the blue clock, could that be the cause from the problem mentioned above?

I would appreciate your thoughts on this!
The full code is kinda long, so I dont think posting everything in here makes sense. I hope I could make it understandable, if not feel free to tell me!

PS: Using Lab makes sense I guess, but If possible I'd really like to stick to my rgb functions.

Edit:Individual pixels: Yes. The script looks for individual pixels only. I was thinking of using the color sampler with a sample size of 10x10, but I havent figured out how to do so yet. I'd like to try that, if any of you have a hint for me how to do it in Extendscript!


Another thing: I think the Sampler should be at (0.5, 0.5).

Does it make a difference in your measurements?

2. Using the weigthed eucledian algorithm puts the pink doc image over the blue tile on the top right. Any ideas why? The distance is about 20 off to the blue clock, could that be the cause from the problem mentioned above?

I am unsure what you mean by »puts the pink doc image over the blue tile on the top right« as I don’t know the listing parameters and the intended order.

1. Analyzing the blue tiles give me more than one most dominant color, theyre both pretty close though.

What is »dominant« exactly – more than a certain percentage of the total number of pixels, simply the most numerous RGB value combination, …?