FORUMS: list search recent posts

Using expressions to find frame tears?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
James Thompson
Using expressions to find frame tears?
on Nov 26, 2011 at 4:42:20 am

Hello,

I've been using AE for years doing compositing and effects, but not too much scripting aside from the basics. What I am trying to accomplish is using expressions to mark on a image where frame tearing is happening. We are able to visualize frame tearing by looking at the difference between say frame 1 and frame 2. I'd like to be able to mark that using sampleImage. Here is an example image:



The basic process is:

1. Sample the entire image to see if the difference is 0, if so move tear line out of frame.
2. If difference isn't 0 then begin checking the frame line by line for differences. If the difference is 0, then move to the next line. Iterate until we find a line that meets a given threshold of difference (say 50) then mark this line.
3. If the iterations go above 720 (height of frame) then move tear line out of frame.

That is the basic functionality I am looking for. I'd also like to log this information to file per frame for additional analysis. But for starters, here is what I have (doesn't work just yet):
//Samples Full Frame @ 1280x720
sampleSize = [640,360];
target = thisComp.layer("Find Tears");
//Sets Sample origin at center of document
samplePos = [target.width,target.height]/2;
fullRgb = target.sampleImage(samplePos, sampleSize, true, time);
fullHsl = rgbToHsl(fullRgb);
//End Sample Full Frame

//Samples Single Line
lineSampleSize = [640,0.5];
lineTarget = thisComp.layer("Find Tears");
//Sets the start sample at the Tear Start location
lineSamplePos = thisComp.layer ("Tear Start").position;
lineRgb = lineTarget.sampleImage(lineSamplePos, lineSampleSize, true, time);
lineHsl = rgbToHsl(lineRgb);
lineHsl[2]*100;
//End Line Sample

//If whole frame is black, set line location to -1
if (fullHsl[2]*100 == 0){
[360,-1]
}
//If the first line is black, iterate until value reaches threshold then set line location at tear
else if (lineHsl[2]*100 <= 50){
lineSamplePos++;
if (lineHsl[2]*100 >= 50){
[360, lineSamplePos++]
}
}
//If the lineSamplePos reaches 720 (frame height) then set line location to -1
else if (lineSamplePos = 720){
[360,-1]
}


Before I spend too much time on this I wanted to know if this approach is even possible with expressions. Any help or direction would be greatly appreciated.

Thanks,
James


Return to posts index

James Thompson
Re: Using expressions to find frame tears?
on Nov 28, 2011 at 7:19:50 pm

Hi All,

I really hate to "bump" the thread, but I need to know if this approach is even possible before I spend too much more time on it. Can expression preform multiple samples like this per frame without having time involved?

I really appreciate and information.

Thanks,
James


Return to posts index

Dan Ebberts
Re: Using expressions to find frame tears?
on Nov 28, 2011 at 8:41:29 pm

I think what you're mainly missing is a loop for your line sampling. I'd do it like this (not tested):


for (i = 0; i < 720; i ++){
lineRgb = lineTarget.sampleImage([360,i], lineSampleSize, true, time);
lineHsl = rgbToHsl(lineRgb);
if (lineHsl[2] <= .5) break;
}
if (i < 720) [360,i] else [360,-1]


Dan



Return to posts index


James Thompson
Re: Using expressions to find frame tears?
on Nov 29, 2011 at 8:57:13 pm

Hey Dan,

That did just the trick! Thank you very much for setting me in the right direction. Do you know off hand any good tutorials on writing the results to a text file? If not I am sure I can find something on the forum.

Thanks again,
James


Return to posts index

James Thompson
Re: Using expressions to find frame tears?
on Nov 30, 2011 at 5:11:40 am

Hey All,

Getting so close to having it do what I need. I am coming across one little issue with the loop. Right now, it iterates until it finds something greater than the threshold which isn't desirable. Here's the code:
for (i = 0 + lineSamplePos[1]; i < 720; i++){
lineRgb_Loop = lineTarget.sampleImage([640,i], lineSampleSize, true, time);
lineHsl_Loop = rgbToHsl(lineRgb_Loop);
if (lineHsl_Loop[2]* 100 >= 10) break;
}
if (i < 720, i > lineSamplePos[1]) [640,i] else [640,-1]
}


What I need it to do is check to see if the lineSample is equal to 0 then iterate to the next line. If the next line isn't 0 but is greater than or equal to the threshold, set to [640, i] otherwise set line locations to [640, -1.

This way it only checks the first non black line. I am sure it is something simple I am missing, but I can't figure it out for the life of me. :S

Thanks again for all the help!

Thanks,
James


Return to posts index

James Thompson
Re: Using expressions to find frame tears?
on Dec 1, 2011 at 3:56:17 am

Hey Guys,

With plenty of mucking about I seem to have came up with a solution. I am sure there was a more elegant way of doing it, but it appears to be working. :)
for (i = 0 + lineSamplePos[1]; i < 720 - lineSamplePos[1]; i++){
lineRgb_Loop = lineTarget.sampleImage([640,i], lineSampleSize, true, time);
lineHsl_Loop = rgbToHsl(lineRgb_Loop);
if (lineHsl_Loop[2]* 100 != 0) break;
}
//If the break happened at less than line 720, line value was greater than or equal to a threshold of 10, then put tear line at break. Otherwise move out of frame.
if (i < 720, i > lineSamplePos[1], lineHsl_Loop[2]*100 >=10) [640,i] else [640,-1]
}


Thanks,
James


Return to posts index

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