Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: HomeForumBasicsExpressionsTutorialsPodcastsMotion GraphicsTrainingCinema 4DFAQ

get average hsl value from multiple frames

Cow Forums : Adobe After Effects Expressions

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>
get average hsl value from multiple frames
by Pierre-Alexis Tremblay on Jun 30, 2009 at 7:38:40 pm

I'm not sure how to put this...
How to set the opacity of a layer based on the average brightness of the underlying layer which is let's say a movie clip but I need this value to be constant, so the value would be a combination of an average from the image area and from the time range (?)

P.A.T.

Respond to this post   •   Return to posts index

Re: get average hsl value from multiple frames
by Dan Ebberts on Jun 30, 2009 at 8:19:29 pm

This should get you close:

L = thisComp.layer("Your Movie");
startRange = L.inPoint;
stopRange = L.outPoint;
accum = 0;
n = 0;
for (i = timeToFrames(startRange); i < timeToFrames(stopRange); i++){
rgba = L.sampleImage([L.width/2,L.height/2],[L.width/2,L.height/2],true,framesToTime(i));
accum += rgbToHsl(rgba)[2];
n++;
}
linear(accum/n,0,1,0,100)


Dan



Respond to this post   •   Return to posts index

Re: get average hsl value from multiple frames
by Pierre-Alexis Tremblay on Jul 2, 2009 at 3:40:02 pm

Works fine, thanks a lot!

Would it be possible to adapt this so it would get the average brightness of all the underlying layers as if they were a composite?

P.A.T.

Respond to this post   •   Return to posts index


Re: get average hsl value from multiple frames
by Dan Ebberts on Jul 2, 2009 at 5:49:37 pm

Sure, you'd just need to add an outer loop that cycles through all the layers you're interested in, adds the result to an accumulator total variable and (at the end) divides by the number of layers. The exact code would depend on which layers you're after.


Dan



Respond to this post   •   Return to posts index

Re: get average hsl value from multiple frames
by Pierre-Alexis Tremblay on Jul 2, 2009 at 8:25:34 pm

Could I turn the last value (the 100 at the end) into a variable that would get its value from an external text file?

P.A.T.

Respond to this post   •   Return to posts index

Re: get average hsl value from multiple frames
by Dan Ebberts on Jul 3, 2009 at 3:01:27 am

Sure, just put a valid JavaScript statment in the file, like this:

maxOpacity = 75;

Do an eval() of the file, as in the other recent threads, and change the last line to this:

linear(accum/n,0,1,0,maxOpacity)


Dan



Respond to this post   •   Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINETRAININGVIDEOS - REELSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]