6
$\begingroup$
1 2 1                         1 2 1                    
2 4 2 (A)            (1/16) * 2 4 2  (B)
1 2 1                         1 2 1

Both matrices are the same except that the matrix B is multiplied by the sum of its elements. When convolved with an image, they give nearly the same blurred image.

What is the exact difference between them and when they should be used ?

$\endgroup$
  • 4
    $\begingroup$ The obvious answer: the difference between the two outputs is a factor of $\frac{1}{16}$ since the filter is linear. $\endgroup$ – Jason R Apr 10 '13 at 12:47
8
$\begingroup$

The rightmost one (where you divide by the sum) ensures that the output of the filter wil have the same dynamic range as the input.

Actually, the output blurred images are not the same because their pixel values are different. You have the feeling that they are similar because your software (I assume Matlab) does remap the intensity values of the pixels to a range that is acceptable by typical displays, i.e., 8-bits values between 0 and 255. If you used a more "close to the metal" software or library, then you would have to do this operation by yourself.

Data dynamic range

The dynamic range of an image is given either by the min and max intensity values present in the image or by the min and max intensity that can be represented by the digital format used to store the intensity values. (From the context it is usually clear which one of the definitions is in use.)

Typical ranges are $[2,255]$ (with integer spacing) that corresponds to 8 bits quantization and $[0,1]$ for floating point values (either single or double precision). The same convention is used in Computer Graphics, OpenGL, etc.

If you take a constant image with value 1 everywhere:

  • the left filter will output a constant image with value 16 everywhere,
  • the second (rightmost) one produces a constant image of value 1.

From this simple example, you can see that one filter preserved the enery of the image, while the second one increased it.

While it is harmless in this case, it can lead to numerous problems in practice. For example, iterative algorithms may diverge (because of numerical overflows), your computer may run out of bits to represent your data, or you may lose precision (single and double precision floating-point values do not have a uniform precision over the range of the possible values).

$\endgroup$
  • $\begingroup$ Could you please elaborate on "dynamic range" that you mentioned in your first line ? $\endgroup$ – Animesh Pandey Apr 10 '13 at 15:50
  • $\begingroup$ I've edited the answer. Please feel free to ask for more information. $\endgroup$ – sansuiso Apr 10 '13 at 16:35
1
$\begingroup$

When you convolve an image with a filter, the result depends on both the filter and the image pixel values. if the filter doesn't sum up to one, then it will have its own positive contribution to the convolution. For example if you convolve an image that consists of only a constant value, with a filter that doesn't sum up to one, then the convolution would result in an image with a higher constant value. So this filter would change the average brightness of the image, which may not be desirable.

The exact difference between both images would be a constant term i.e. the sum of the filter kernel, the dynamic range that is the difference between positive and negative values, would stay exactly the same.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.