Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Determine if a layer contains only one color

  • Determine if a layer contains only one color

    Posted by Paul Connors on June 25, 2020 at 12:17 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.

    Paul Connors replied 5 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Kevin Camp

    June 25, 2020 at 8:29 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

  • Paul Connors

    June 25, 2020 at 8:56 pm

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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy