Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Sampleimage measurement of many pixels

  • Sampleimage measurement of many pixels

    Posted by Paul Roper on June 23, 2011 at 12:06 am

    Hello

    I need to create a 10×10 matrix of numbers, each one representing the brightness of a greyscale pixel underneath it. The 10×10 pixels appear in the comp massively enlarged (in fact it’s a 900×900 pixel photoshop image made by enlarging a 10×10 image with nearest neighbour).

    I can easily create a text layer with a sampleimage expression and a point control to display the red value of the underlying layer (as I mentioned, it’s a greyscale image underneath so I’m only interested in one of the RGB values). But the tricky bit is how can I replicate this easily to do all 100 pixels? Has anyone had experience of maybe using particle playground’s grid/text functions plus an expression?

    I suspect I may just end up with 100 layers made manually. Not elegant, but I’d probably spend more time figuring out how to do it using expressions. Unless somebody out there has a magic suggestion?!

    Thanks,
    Paul

    red=thisComp.layer("big greyscale image").sampleImage(effect("Point Control")("Point"),[.5, .5])[0];

    Math.round(red*255)

    Paul Roper replied 14 years, 10 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    June 23, 2011 at 5:31 am

    You could sample the 10×10 grid and create a 10×10 grid of numbers, all with a single text layer, but I’m not sure how you’d get the two grids to line up. Maybe you could use a monospaced font so the expression could calculate where each character is located in comp space.

    Dan

  • Paul Roper

    June 23, 2011 at 4:07 pm

    Thanks Dan, but I went for the manual, tedious method in the end, but put an expression on the position of each text layer to automatically position it correctly. Strangely, some of the ‘sampleimage’ results were completely wrong, for no apparent reason – for example some points were very dark grey, but the sampleimage gave me a result of around 1. Odd.

    Look at all those lovely, boring layers:

    …and here’s the position expression to space the 100 text layers automatically (in a 10×10 grid layout):

    [thisComp.layer(index-10).transform.position[0],thisComp.layer(index-10).transform.position[1]+90]

  • Dan Ebberts

    June 23, 2011 at 4:45 pm

    >Strangely, some of the ‘sampleimage’ results were completely wrong

    What does your sampleImage() expression look like?

    Dan

  • Paul Roper

    July 13, 2011 at 8:48 pm

    Dan – some of the sampleimage results were wrong because I had the text layer parented to a null and shifted out of position, so the pixel it was actually over was not the pixel it “thought” it was over. That was an easy fix…

    but…

    Now I need to do the same thing, but with a grid of 40 x 45 numbers. That’s 1800 numbers = 1800 layers. I tried making a comp of a row of 40 numbers, with each number sampling the picture in the parent comp. This worked perfectly for the first row, so I duplicated it, but obviously it’s only one comp, so the expressions only get calculated once, producing a nice row of numbers, which is then duplicated.

    So…any further thoughts, anyone?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy