Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Get average colour from layer based on target objects area

  • Get average colour from layer based on target objects area

    Posted by Jamie Shiels on October 1, 2014 at 5:45 am

    Hi,

    Im after an expression to find the average color of an image based on the target layers area. I am creating a countryside field patchwork image and am tracing around some old aerial pics. I want to grab the average colour of the original pic based on the area of the shape not the pictures anchor point.

    Thanks

    Jamie

    Jamie Shiels replied 11 years, 10 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    October 1, 2014 at 6:40 am

    I’m not sure I understand completely, and you didn’t specify where this expression will be applied, but it will probably be something like this:

    L1 = thisComp.layer(“target”);
    L2 = thisComp.layer(“image”);
    p = L2.fromComp(L1.toComp(L1.anchorPoint));
    avgColor = L2.sampleImage(p,[L1.width,L1.height]/2,true,time)

    Dan

  • Jamie Shiels

    October 1, 2014 at 6:54 am

    Hi Dan,

    Thanks for the speedy post and sorry for not being clearer. I have a composition with about 130 individual shape layers that I want to get an average colour from an image for each of the shapes. I wanted to use an expression on the shapes colour or it could use it on a fill effect that applies the average colour to the shape based on the shapes area. I can’t use anchor points because if you use the images anchor point all the shapes will have the same colour and the shapes anchor point is the centre of the comp so thats no use either. It would be great if the expression automatically set the area based on the shape it was applied to so I didn’t have to manually change the expression for each shape.

    I hope this is clearer.

    Thanks

    Jamie

  • Dan Ebberts

    October 1, 2014 at 6:01 pm

    This seems to work for the fill color of rectangular shapes:

    L = thisComp.layer(“image”);
    p = L.fromComp(toComp(anchorPoint)+content(“Rectangle 1”).transform.position);
    avgColor = L.sampleImage(p,content(“Rectangle 1”).content(“Rectangle Path 1”).size/2,true,time)

    Dan

  • Jamie Shiels

    October 2, 2014 at 5:16 am

    Hi Dan,

    Thanks for this, it works a treat on rectangular shape layers but because Im re-creating a “patchwork of fields” effect I need to use bezier paths. Is there a way to adapt this expression for beziers?

    Thanks

    Jamie

  • Dan Ebberts

    October 2, 2014 at 6:46 am

    Unfortunately, I can’t think of a practical way to do it with beziers.

    Dan

  • Jamie Shiels

    October 2, 2014 at 7:45 am

    Thanks for trying Dan, much appreciated.

    Jamie

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