Electron microscopy
 
PythonML
Image Convolution
- Python Automation and Machine Learning for ICs -
- An Online Book -
Python Automation and Machine Learning for ICs                                                           http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

Image convolution involves applying a filter that adds each pixel value of an image to its neighbors, weighted according to a kernel matrix. It is a fundamental operation used in various image processing tasks, especially in convolutional neural networks (CNNs):

  1. Filter/Kernel: 

    A filter or kernel is a small matrix of numbers that is used for the convolution operation. Each element in the kernel represents a weight. Figure 3547a shows an 5x5 image and a 3x3 Kernel with their values of the pixels created by a Python Code.      

     (a)  (b)

    Figure 3547a.  (a) A 5x5 image, and (b) a 3x3 Kernel. 

  2. Convolution Operation: 

    The convolution operation involves sliding the filter over the input image, multiplying the filter values with the corresponding pixel values in the image, and summing up these products. This process is repeated for every position of the filter as it moves across the image. 

    The mathematical operation for a single element (pixel) in the output feature map is given by:  

      ---------------- [3547a]

    where,

    I(i+m,j+n) refers to the pixel value in the image matrix at position (i+m,j+n), and K(m,n) refers to the value in the kernel matrix at position (m,n). The double summation involves iterating over all positions in the kernel matrix, and the result is the convolution output at position (i,j). 

    For example, we can calculate the convolution output at position (1,1): 

      ---------------- [3547b]

    In Figure 3547a, the image Matrix is:
            

    And, the Kernel Matrix is:
            

    Therefore, the Output(1,1) can be given by,
             Output(1,1) = 137×0.84+3×0.54+54×0.69+48×0.9+167×0.88+37×0.74+47×0.53+133×0.12+121×0.15 = 429.92

  3. Weighted Sum: 

    At each position, the values in the filter are multiplied by the pixel values they overlay in the image, and the results are summed up to produce a single value. This value represents the contribution of the filter to the output image at that position. 

  4. Output Image: 

    The result of the convolution operation is a new image, often referred to as the feature map or convolved feature. It highlights specific patterns or features present in the original image, as the convolution operation emphasizes certain local patterns based on the filter's weights. 

Image convolution is crucial in tasks like edge detection, feature extraction, and other image processing applications. In deep learning, convolutional layers use learnable filters (weights) that are adjusted during training to automatically extract relevant features from the input images. 

In programming, the image.filter(ImageFilter.Kernel()) method in Pillow (PIL) can be used for custom image convolution. As shown in Figure 3547b, the ImageFilter.Kernel class allows us to define a custom convolution kernel and apply it to an image (code): 

 (a)  (b)

Figure 3547b. 3x3 kernel for edge detection: (a) Original image and (b) Edge detection filtered image. 

============================================


         
      
         

 

============================================

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 



















































 

 

 

 

 

=================================================================================