5 Replies Latest reply on Sep 6, 2016 10:57 PM by Rick Gerard

    sampleImage Offset

    dkchang

      This is the expression:

       

      sourceLayer = thisComp.layer("Control Layer");

       

      sampleSize = [1,1];

       

      samplePoint = transform.position;

       

      colour = sourceLayer.sampleImage(sampleSize,samplePoint);

       

      x=colour[0]*125;

       

      [x,x]

       

      Expected Behavior: Assets scale to 125% when directly on top of white areas. The animation is symmetrical. Refer to this animation.

       

      Reality: The scaling is offset. Scaling is magnified and seems to be anchored at the bottom right corner.

       

      Screen Shot 2016-09-01 at 11.54.32 PM.pngScreen Shot 2016-09-01 at 11.54.15 PM.pngScreen Shot 2016-09-01 at 11.54.56 PM.png

      How can this issue be fixed?

        • 1. Re: sampleImage Offset
          Mylenium Most Valuable Participant

          How can this issue be fixed?

           

          Adjust your expression code accordingly. Your sample point has nothing to do with your actual layer positions because your layers are not comp sized and thus the coordinates don't match.

           

          Mylenium

          1 person found this helpful
          • 2. Re: sampleImage Offset
            dkchang Level 1

            Hi Mylenium,

             

            What needs to be adjusted in the expression code?

             

            Thanks,
            Daniel

            • 3. Re: sampleImage Offset
              Rick Gerard Adobe Community Professional & MVP

              The sample is always rectangular. You are only sampling one pixel. If it were my project I would make a circular gradient for the sample layer and then sample based on either a null or the comp dimensions and make the sample size the height and width of the gradient circle.

               

              The sample layer is not selected so I can't see where the anchor point is but I'm guessing it is at the bottom right corner. You can locate the sample based on the comp dimensions and then move the white layer around or your can base your sample on one of the other layer's position and wait for that layer to move over the white square.

               

              I'm not exactly clear what you are doing in your comp and the link to the animation is broken. Does that help?

              1 person found this helpful
              • 4. Re: sampleImage Offset
                dkchang Level 1

                Hi Rick,

                 

                This is helpful.

                 

                Here is the project file.

                 

                Thanks,
                Daniel

                • 5. Re: sampleImage Offset
                  Rick Gerard Adobe Community Professional & MVP

                  Your comp has a few problems. The first is that the Controller comp is not the same size as the main comp. This throws off the calculations for the sample. The second is that your expression is pointing to the wrong things. Your expression should read like this:

                  t = thisComp.layer("Control Layer");

                  s = t.sampleImage(thisLayer.position, radius = [.5, .5], postEffect = true, t = time);

                  ns = linear(s[0], 0, 1, 50, 150);

                  [ns, ns]

                   

                  • t is the target layer - the control layer.
                  • s is a sample you take from the target layer using the position of the current layer as the sample point. I've just used the default language for everything except point so you can easily see what the values represent
                  • ns calculates the new scale by sampling the red channel of the target layer at the current layer's position. There are 4 color channels sampled and you only want to use one of them, then a linear method is applied to the sample value so that zero equals 50% scale and 1 equals 150% scale.
                  • The last line is just an array made from the new scale values

                  I hope this helps. You'll get a better result if you use a shape layer with an animated radial gradient as your sample. This will make the layer smoothly scale up and down as the image passes behind the layers position. Something like this: Dropbox - sample image and scale.aep (note: your browser may add a .txt extension to the app file with it downloads. Just remove it to open the project)

                  1 person found this helpful