15 lines
1.2 KiB
Plaintext
15 lines
1.2 KiB
Plaintext
One class of image digital filters is described by a rectangular matrix of real coefficients called [https://en.wikipedia.org/wiki/Kernel_(image_processing) '''kernel'''] convoluted in a sliding window of image pixels. Usually the kernel is square <math>K_{kl}</math>, where <i>k</i>, <i>l</i> are in the range -<i>R</i>,-<i>R</i>+1,..,<i>R</i>-1,<i>R</i>. <i>W</i>=2<i>R</i>+1 is the kernel width.
|
|
|
|
The filter determines the new value of a '''grayscale image''' pixel P<sub><i>ij</i></sub> as a convolution of the image pixels in the window centered in <i>i</i>, <i>j</i> and the kernel values:
|
|
|
|
<blockquote>
|
|
<math>P_{ij}=\displaystyle\sum_{k=-R}^R \sum_{l=-R}^R P_{i+k\ j+l} K_{k l}</math>
|
|
</blockquote>
|
|
|
|
'''Color images''' are usually split into the channels which are filtered independently. A color model can be changed as well, i.e. filtration is performed not necessarily in RGB. Common kernels sizes are 3x3 and 5x5. The complexity of filtrating grows quadratically ([[O]](<i>n</i><sup>2</sup>)) with the kernel width.
|
|
|
|
'''Task''': Write a generic convolution 3x3 kernel filter. Optionally show some end user filters that use this generic one.
|
|
|
|
''(You can use, to test the functions below, these [[Read_ppm_file|input]] and [[Write_ppm_file|output]] solutions.)''
|
|
|