FORUMS: list search recent posts

sampleImage() to drive Source Text is not working

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nate Smith
sampleImage() to drive Source Text is not working
on Jun 20, 2013 at 4:23:07 pm

I've searched exhaustively for a reason this will not work and have come up empty. I have tried multiple different approaches to this and have gotten the same results.

I am trying to drive the source text to display a 1 or a 0 depending on the returned value. The value returned is always 0 though. I am using a black and white image with very high contrast so there should be 0 or 1 returned.

I have tried all RGBA channels with no differing results. I have tried setting the sampleImage pre and post layer effects to true and false. I have ensurecd that it was not just a stored memory issue. In short, I have tried everything.

What am I missing?

Thanks for any help in advance,
Nate


//Apply to a text layer. Ensure there is a layer in the comp named 'Image'

//Set the sampled Image to be used
targetLayer = thisComp.layer("Image");

//Set the X & Y of the point to be used
samplePointX = transform.anchorPoint[0];
samplePointY = transform.anchorPoint[1];

//Set the Radius for the sample point
sampleRadius = [3,3];

//Get the color at the point and extract a single value
sample = targetLayer.sampleImage([samplePointX,samplePointY], sampleRadius)[0];

//Assign text depending on if the value is greater than .5 or not
if (sample > .5)
{ outputString = "0"; }
else
{ outputString = "1"; }


Return to posts index

Nate Smith
Re: sampleImage() to drive Source Text is not working
on Jun 20, 2013 at 4:51:37 pm

Fixed it. Anchor point is static. Had to subtract anchor point from position.

//Apply to a text layer. Ensure there is a layer in the comp named 'Image'

//Set the sampled Image to be used
targetLayer = thisComp.layer("Image");

//Set the X & Y of the point to be used
//OLD CODE samplePointX = transform.anchorPoint[0];
//OLD CODE samplePointY = transform.anchorPoint[1];

samplePointX = transform.position[0] - transform.anchorPoint[0];
samplePointY = transform.position[1] - transform.anchorPoint[1];


//Set the Radius for the sample point
sampleRadius = [3,3];

//Get the color at the point and extract a single value
sample = targetLayer.sampleImage([samplePointX,samplePointY], sampleRadius)[0];

//Assign text depending on if the value is greater than .5 or not
if (sample > .5)
{ outputString = "0"; }
else
{ outputString = "1"; }


Return to posts index

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