<<< Home << Web < Arithmetic Top Bottom < Prev Next >

Image Arithmetic
Add/Average - Effect of Divisor

A Quick Review

On the previous page, we dealt with addition using a divisor of 1 and a bias of 0. Under those circumstances, a pixel's colors are added using the formula (a,b,c) + (x,y,z) = (a+x,b+y,c+z). Since each of the values a, b, c, x, y and z range from 0-255, the results range from 0-510. The values 256-510 have to be dropped down into the range 0-255. When clipping is used, these values are all set to 255. Otherwise, 256 is subtracted to create the "wrap-around" sequence 253, 254, 255, 0, 1, 2, ...

Using a Divisor

Ignoring bias (which is discussed in the next page), the addition formula is actually:

  (a,b,c) + (x,y,z) = ( (a+x)/d , (b+y)/d , (c+z)/d )

where d is the divisor.

Addition usually works best with a divisor of 2. This sets each of the red, green and blue components to the average of the values of the two pixels being added. Resultant values are always in the range 0-255, so there's no need to worry about values outside the allowable range. As long as the bias is zero, it makes no difference whether you specify clipping or not.

Note:
The average function is the same as the add function with a divisor of 2.

After performing your addition with a divisor of 2, you'll often find that the result is an image that's a little too dark (or occasionally a little too light). You can use other features of PSP to adjust this - Gamma correction, brightness/contrast adjustment, equalization, etc. On the other hand, if you use a divisor of 1 and if your images are reasonably light, many of the results will be larger than 255 and either clip or wrap around. The PSP adjustments won't give anywhere near as good results as if you had used a divisor of 2.

Another way to lighten or darken a resultant image is to use a positive or negative bias. This is discussed on the next page.

Divisors larger than 2 are seldom useful in addition. If you use a divisor of 3, the largest value is 510/3, or 170, and your result will be a darker image with fewer possible colors. Divisors larger than 3 reduce the largest value even more, giving even darker images with fewer possible colors.

When you use a divisor of 1, adding black (0,0,0) to a pixel does not change the pixel. This is no longer true with larger divisors. If your divisor is 2, adding black reduces a value to half its size: (0+x)/2. With divisors other than 1, there is no color you can add to all other colors without affecting them.

Examples

Here are some examples using divisor=2:


Addition - Divisor=2, Bias=0
1st color 2nd color Result
0,0,0 0,255,0 0,127,0
0,0,0 128,255,64 64,127,32
255,0,0 0,255,0 127,127,0
255,0,0 0,0,255 127,0,127
0,255,0 0,0,255 0,127,127
255,255,255 51,102,153 153,178,204
255,255,255 0,37,104 127,146,179
85,152,53 208,85,2 146,118,27

<<< Home << Web < Arithmetic Top Bottom < Prev Next >