ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Determine if a layer contains only one color

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Paul Connors
Determine if a layer contains only one color
on Jun 25, 2020 at 12:17:15 am

Hello. I'm trying to write an expression that determines if a layer contains only one color. I'm analyzing various images that I've placed on a background layer. Some of the images are simply solid colors. Others are all sorts of colors. The issue I'm running into is sometimes the images that are solid colors end up being the same color as the background layer. When that happens the image obviously disappears into the background layer. I tried using sampleImage but it was giving me the average color of the sample radius. Essentially I'd like to be able to create an expression that answers the "yes or no" question of: is this image one solid color? Any help would be greatly appreciated. Thank you.


Return to posts index

Kevin Camp
Re: Determine if a layer contains only one color
on Jun 25, 2020 at 8:29:44 pm

I'd try to compare the sampleImage() of a single point to the sampleImage() that averages the whole image (or a big radius).

Technically it won't be fool proof, but try this: add a checkbox control to a image layer and then add this expression to the checkbox:
p = [ width / 2, height / 2] ;
s1 = sampleImage( p, [ .5, .5 ] ) ;
s2 = sampleImage( p, p ) ;
if ( s1[0] == s2[0] && s1[1] == s2[1] && s1[2] == s2[2] ) true else false ;

If the center pixel of the image has different RGB values to the average of the whole image, the checkbox should be unchecked.

If the center pixel has the same RGB values as the average of all the pixels, then the checkbox should be true.

Kevin Camp
Art Director
KCPQ & KZJO


Return to posts index

Paul Connors
Re: Determine if a layer contains only one color
on Jun 25, 2020 at 8:56:27 pm

Hi Kevin. This sounds like exactly what I'm looking for. Thank you very much!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]