Page 309 - AI Computer 10
P. 309

Flipping the Kernel Matrix

        In 2-D convolution, we flip the kernel matrix two times – once horizontally and once vertically. This process is
        called Flipping the kernel matrix. In the vertical flip, we exchange the top row with bottom, second from top,
        second from bottom, and so on. In the horizontal flip, the rightmost column is flipped with the leftmost, and
        so on for the remaining. This in effect, causes the kernel matrix to be turned through 180 degrees. For ease
        of operations, the Kernel matrix is always kept as a square matrix with rows = columns = an odd number. The
        number is 3 or 5 in most of the cases.

        Flipping of the kernel is important in context of convolutions. If we don’t flip the kernel, the process will be of
        correlation, i.e., measuring similarities between two signals, rather than processing the signal to extract features.
        The flip ensures that the convolution operation correctly captures the relationship between the input and the
        kernel, allowing for proper feature extraction and signal processing.







                        1      2      3               3       2      1               9       8      7

                        4      5      6               6       5      4               6       5      4


                        7      8      9               9       8      7               3       2      1







        To produce the output image, follow the given steps:

        Step 1:   Select a cell from the input image matrix.
        Step 2:   Take a kernel matrix of suitable size and flip it.

        Step 3:   Place the center of the kernel matrix at the selected cell in the image matrix.
        Step4:   Perform element-wise multiplication of the input matrix and the kernel matrix and add the products
                 to produce a single value as the output.
        Step 5:   Store the computed value in the output matrix in the corresponding cell as the input matrix.

        Solved Example

        Let us compute the convolution of an input matrix and kernel matrix.
                                    1        2        1         1       –2       1
            1        2       3                                                               11       15       13

                                    –1       0        –2        –2      0        –1
            4        5       6                                                               17       18       12

                                    1        –2       1         1       2        1
            7        8       9                                                               –11     –23      –23


               Input Image                Kernel Image               Flipped Kernel          Convolution Output




                                                                                                             175
                                                                                                             175
   304   305   306   307   308   309   310   311   312   313   314