3 Replies Latest reply on Sep 10, 2014 9:59 PM by Blacknest

    Can I translate a layer in fractions of a pixel?

    Blacknest Level 1

      I'm using a script to iron out slight variations of camera position in a sequence of time-lapse images (the camera movement is caused by daily expansion and contraction of the timber wall that the DSLR is bolted onto).  I've motion-tracked the sequence in another program and produced a file of the translations to be applied to each image, expressed as a number of pixels in X and Y, in floating point numbers.

      The script reads the file into an array, reads in each image, applies the translation (and a number of other transformations such as cropping and scaling) and writes the image out again.

       

      The script works fine, except that Photoshop rounds the translation to the nearest whole pixel before applying it, which is simply not accurate enough to give a stable sequence. I've tested this in a separate script using a test image, and hard-wiring the translation values directly into the function call, and confirmed that it only seems possible to move a raster layer in Photoshop in whole pixels, regardless of whether snap-to-pixel is disabled, and regardless of the zoom level.

       

      The workaround is obviously to scale the image up each time - say 5 or 10 times - apply a scaled translation - and then scale it down again - but I thought I'd see if I was being stupid and missing something trivial first!

       

      P.S I've tried Auto-align, but with limited success - with changing shadows and sunlight, and moving branches etc, it often gets confused.

        • 1. Re: Can I translate a layer in fractions of a pixel?
          c.pfaffenbichler Level 9

          Hmm …

          Using a function that utilises Action Manager code on a Smart Object it is possible to offset that by 0.5 pixels (the resulting Layer’s Transformation Box seems to confirm it) but the result is probably not at all what you are after.

          I have not tested with all Interpolation Methods, though.

           

          A possible work-around might be up-sampling the whole thing to 200% and after corrections down-sample again.

          Not ideal, certainly, but maybe someone else has a better idea.

          • 2. Re: Can I translate a layer in fractions of a pixel?
            Blacknest Level 1

            Yes, I tried smart objects - the transform box shows that it moves half a pixel, but the moment you actually try to do anything (e.g. rasterize, merge or flatten the image) the layer hops to the nearest pixel. It's the same thing with vector shapes - you can move a path in fractional pixel increments, but once it's rasterized, it can only be translated in whole-pixel increments.

             

            I've come to the conclusion that this is a permanent feature of Photoshop - all raster layers are locked to the pixel grid.  I guess it's logical really - otherwise you would get image degradation every time you moved a layer. Obviously this is still going to happen if you rotate or scale, but this feature ensures that translation is lossless on its own.

             

            So I'm using the scale-up/scale-down method - at 500% as I want 0.2 pixel accuracy. This pushes my processing time from less than a second per frame to 7 or 8 seconds - which is quite significant on 35,000 images - but I can always run it at night!

            • 3. Re: Can I translate a layer in fractions of a pixel?
              Blacknest Level 1

              Just in case anyone else with a similar problem stumbles on this thread, here's what transpired:

               

              After deciding on the scale-up/scale-down method to get 0.2 pixel accuracy on translation, I needed to rotate the images by small amounts to line everything up. That's when I found that the 'rotate' function in Photoshop has a similar problem - it only seems to work to one decimal place (for a layer) or two (for the whole image).  On a 3000-pixel-wide image the rounding errors produce a jitter in the animated sequence.  Of course with rotation, upscaling and downscaling don't help - an angle is an angle whatever size the image is. So, back to the drawing board....

               

              I finally solved the issue by avoiding Photoshop altogether for this particular exercise.  I wrote my own program (in VB.NET) to process the images - the .NET environment provides matrix functions to shift images by amounts down to .0000001 of a pixel (or whatever the smallest 32-bit floating point number is!) and to rotate and scale with the same accuracy. There's no need to upscale & downscale, so the program works fast - less than a second per frame to load, shift, rotate, crop, resize, rotate 180,  and save.  The results are indistinguishable in quality from those produced by the Photoshop script, and the time-lapse sequence is now rock-steady.  Hooray!