Skip to main content
Known Participant
September 20, 2016
Answered

Is there something like sampleImage() for a Comp?

  • September 20, 2016
  • 3 replies
  • 1604 views

Hi everyone,

I couldn't find any reference for this -

Can I check the alpha value of a comp pixel and not a layer pixel (similar to a layer's sampleImage() method)?

AEScripts.com and various other places have scripts like these:

Auto Crop - aescripts + aeplugins - aescripts.com

pt_CropPrecomps - aescripts + aeplugins - aescripts.com 

How do the various auto crop scripts know where the comp's layers transparency is in order to crop it to the layers' actual size?

I don't necessarily want to crop a comp - just get the alpha values of a comp in a script... or whatever method those auto-crop scripts use.

Thanks a lot in advance,

Roy

This topic has been closed for replies.
Correct answer UQg

i'd say add the comp as a precomp layer to a temp comp with same specs, add the expression, collect the result, remove the temp comp from the project.

Xavier

3 replies

Known Participant
September 20, 2016

That's what I was thinking regarding the sourceRecAtTime... That it won't do the trick.

I think that I'm missing a crucial method or function that these scripts use because I don't think they are using sampleImage -- it's a pretty slow scan and these scripts work immediately.

I think they are using a more precise and faster  function than sampleImage.

UQg
Legend
September 20, 2016

To crop, dont start scanning with a one pixel radius, or it can be extremely slow, especially if the non transparent area is small compared to the layer.

Start with a large radius, scan to find the rough border, then lower the radius and scan in a smaller area, and so on until the desired accuracy (for instance: bisection method).

Not that using sampleImage with a large radius does require 16 or 32 bpc, 8 is often not fine enough.

Xavier

Known Participant
September 21, 2016

Yeah, me and my coding partner wrote a kick ass algorithm for bi-section sampleImage scanning. Works very fast! OK, it was mostly my coding partner who wrote it .

Can you please elaborate on the 8 bits vs the higher bit depths? We are just checking if the alpha channel is higher than zero - will 8 bits sampleImage give us incorrect values in this case?

Mathias Moehl
Community Expert
Community Expert
September 20, 2016

The AVLayer object has a function sourceRectAtTime that gives you a bounding box for the visible part of the layer. I guess this is what pt_CropPrecomps is using.

If you really need sampleImage instead, maybe you can place your comp as precomp inside of another composition and then apply sampleImage to the precomp layer?

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Known Participant
September 20, 2016

Thank you both

I will have to try both methods to see which is giving me the best results.

It seems the Auto crop scripts take into account the actual non-transparent pixels of the comp and not a sourceRecAtTime of a specific layer inside the comp. I mean that the resulting cropped comp size is sometimes more and sometimes less than the combined sourceRecAtTime of all the visible layers. So maybe sourceRecAtTime won't help me. I'll give it a go.

Thanks again,

Roy.

UQg
Legend
September 20, 2016

I might be wrong, but i think that sourceRectAtTime never takes masks and effects into account.

Hence, for layers with a source, sourceRectAtTime invariably returns an object with

     width : theLayer.width,

     height: theLayer.height,

which is not so useful.

Xavier

UQg
UQgCorrect answer
Legend
September 20, 2016

i'd say add the comp as a precomp layer to a temp comp with same specs, add the expression, collect the result, remove the temp comp from the project.

Xavier

Known Participant
September 21, 2016

Both xavier and Mathias are right regarding the Auto Crop scripts.  Since they only work on pre comps, and since I couldn't find any other way of doing it , it is clear they use sampleImage. Well, at least now it's clear to me

I will try to implement that temporary comp and precomp method. Thanks a lot to you both.