More fun with sampleImage(): Ascii animation in After Effects

More experimentation with sampleImage(). This one relies on this expression.


target = thisComp.layer("layerToSample.mov");
samples = new Array();

var spacing = 10;
var w = target.width / spacing ;
var layerOrder = 1;
var h = 10 * layerOrder;

letters = "   .,:!-+=;iot76x0s&8%#@$";

for(x= 0; x < w; x++){
	samples[x] = target.sampleImage([x* spacing ,h],[spacing , spacing], false, time);
}

var string = '';

for(z = 0; z < samples.length; z++){
	var y = Math.round((0.299 * samples[z][0] + 0.587 * samples[z][1] + 0.114* samples[z][2]) * 100)/ 4;
	string = string + letters.substring(y,y + 1);

}

We loop through the row of pixels and place the sampled RGB pixels in the samples array, convert the RGB samples to YUV and grab the Y or brightness value for comparison against a rough gradient of ASCII values. For best results, use a monospace font to retain proper spacing. A more complete script/expression and breakdown to come.

7 Comments

  1. hey dale… it’s cool you’re pursuing this effect. i’ve wanted to recreate the rd_Characterize script i wrote a few years back for UT (http://www.redefinery.com/ut/view.php?item=rd_Characterize) as an AE script/expression, but you’re further along than i am. i’m glad the AE community is digging sampleImage().

  2. Dale said

    Hey Jeff,

    Thanks for the link. I don’t know, in a lot of ways,rd_Characterize is cooler then what I’ve got started here. I love the way the image is holding together. It definitely gives me some inspiration of possible directions to take. sampleimage() is definitely way cool.

    Dale

  3. Alexandre Teles said

    very cool
    i´ll start making some tests with that

    AT

  4. Jonas Hummelstrand said

    Dale,

    Great stuff as always! I’ve been playing with using sampleImage() to create a flicker stabilizer by driving the Levels (Individual) effect, but being a very modest scripter I can’t say I’ve had much success yet.

  5. aremes said

    @Jonas Hummelstrand:

    Same problem here, i know your post is over 18 months old, but maybe you read this and have some results you would like to share? at the moment im struggeling to even get sampleimage to work from an external jsx file. it works fine when i insert the script in a layers property, but when i call sampleimage on a layer from an external script, the layer object claims it does not have such a function..

  6. filip said

    I second what aremes said – the only way to get sampleimage’s value seems to be adding it to layer’s expressions. is there a way to access that using jsx?

  7. Dale said

    Hey filip,

    I’m pretty sure sampleimage() is only available at runtime via expressions. You can certainly create expressions in scripts, but you need to design your script to work through the expression. I’d also take a look at creating a simple plugin if you’ve got some C experience, you can evaluate a script through the AEGP plugin interface.

    Dale

RSS feed for comments on this post

Comments are closed.