Skip navigation
greengnu
Currently Being Moderated

calculate and apply residual images in photoshop

May 11, 2012 4:25 AM

I would like to use photoshop to create accurate residual images (image describing the difference between two images) and to apply such residual images to restore one of the images used to create the residual.

 

given two 8bit images (pixel values in the range [0, 255]) a residual image would be created by subtracting one image from the other:

 

Residual = Image A - Image B

 

as the potential range of this residual is [-255, 255] it must be mapped to [0, 255] to be saved as image:

 

Residual = (Image A - Image B) / 2 + 127

 

given the residual image and image B, image A can then be restored as

 

Image A = Image B + (Residual - 127) * 2

 

 

so my question is: are these two processes (creating a residual image and restoring image A) possible using blending modes, and if not, can i program it somehow? I already tried it using PixelBender, but the PixelBender photoshop plugin doesn't seem to work for pixel bender kernels that take two input images.

 
Replies
  • Currently Being Moderated
    May 11, 2012 8:13 AM   in reply to greengnu

    Try using a combination of the Levels command (not adjustment layer) and Image > Apply Image. Because you're compressing and then re-expanding the tonality, you will lose accuracy due to rounding errors. Maybe it could be more accurate using 32-bit images, but many of the operations in Apply Image don't work on these.

     
    |
    Mark as:
  • Noel Carboni
    23,496 posts
    Dec 23, 2006
    Currently Being Moderated
    May 11, 2012 11:52 AM   in reply to greengnu

    16 bits / channel could yield a happy medium.

     

    If you want mathematical precision, switching to a linear color space would be helpful I think.

     

    Difference blending can yield a result that shows you the difference between two images, but you lose the sign (i.e., your pixel values get the absolute value of the difference).  You might be able to do something where you offset the pixel values in hte first image to middle gray before using Difference, then you'd retain the sign.

     

    Overlay blending could potentially yield a result something like you're looking for in your second equation.

     

    I've done stuff using these blending modes in Actions, for example in the process of isolating noise from an image so as to be able to cancel it out.

     

    -Noel

     
    |
    Mark as:
  • Currently Being Moderated
    May 11, 2012 1:44 PM   in reply to Noel Carboni

    That's why I suggested Apply Image: it has a 'Subtract' mode, as well as 'Difference'.

     
    |
    Mark as:
  • Noel Carboni
    23,496 posts
    Dec 23, 2006
    Currently Being Moderated
    May 11, 2012 2:57 PM   in reply to Semaphoric

    And a good suggestion it was! 

     

    -Noel

     
    |
    Mark as:
  • Noel Carboni
    23,496 posts
    Dec 23, 2006
    Currently Being Moderated
    May 12, 2012 11:47 AM   in reply to greengnu

    In order for 127 to be "middle gray" you'll need to go to a linear color space.

     

    Actions just operate the Photoshop functions available to us.  Armed with an understanding of how the data is represented, and what the various functions do, one can manipulate images with them.  You may ultimately end up with an action that can repeat the steps you want to do on multiple images.

     

    For example, if you want to offset image values by 127, rather than add a middle gray, you'll probably want to use a Curves function and pull up the black point to 127, leaving the white point alone.  You lose another bit of precision, and as I mentioned before switching to 16 bits/channel mode early on in the process might be a good idea.

     

    -Noel

     
    |
    Mark as:
  • Currently Being Moderated
    May 12, 2012 1:14 PM   in reply to greengnu

    What I was thinking was to run Levels on the two images. On one, set the Black Point (down in th 'Ouput Levels' field)  to 128, and in the other, set the White Point to 127. This does the division before the subtraction. This is algebraically the same: (A - B) /2 = (A / 2) - (B / 2) [Distributaive Law].

     

    The image with the altered Whit Point will look dark, since its range has been compressed to 0 - 127. The image with the altered Black Point will look light, with a range fron 128 - 255. Note that the range is compressed, not clipped.

     

    Then, subtract the darker from the lighter with Apply Image. Since the lightest pixel of the dark image is darker than the darkest pixel of the light image, the result will always be > 0.

     
    |
    Mark as:
  • Currently Being Moderated
    May 14, 2012 8:46 AM   in reply to Semaphoric

    Okay, I got it to work. After doing as I posted above, go to the darker image 'B'. Run Apply Image, using the residual image, with a blending mode of 'Add'. Then, run Levels, with the Shadows field in the 'Input levels' area set to 127 (or should it be 128).

     

    Compare the two Histograms of the original and recovered images

     

    ResidulHists.gif

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points