PDA

View Full Version : Quick Q about Subtract


AnnaFan777
5th May 2008, 23:21
in the avisynth documentation:
=============================
Subtract (clip1, clip2)

Subtract produces an output clip in which every pixel is set according
to the difference between the corresponding pixels in clip1 and clip2.
More specifically, it sets each pixel to (50% gray) + (clip1 pixel) - (clip2 pixel).
===========================

Shouldn't it be like

(50% gray) + ( (clip1 pixel) - (clip2 pixel) ) / 2

neuron2
6th May 2008, 00:17
Why do you think the difference should be halved?

stickboy
6th May 2008, 01:47
Because the difference is being offset by 50% gray.

Suppose all pixel values could range from [0, 255]. The maximum difference between any two pixels would be +/- 255. If you then offset it by 127, you're no longer in the [0, 255] range.

IanB
6th May 2008, 12:41
Lookup tablefor (int i=0; i<=512; i++) Diff[i] = max(0,min(255,i-129));Lumasrc1p[x] = Diff[src1p[x] - src2p[x] + 126 + 129];Chromasrc1pV[x] = Diff[src1pV[x] - src2pV[x] + 128 + 129];RGBsrc1p[x] = Diff[src1p[x] - src2p[x] + 128 + 129];There is no divide by 2, the values are clamp saturated.