Skip to main content
. 2023 Sep 30;23(19):8190. doi: 10.3390/s23198190
Algorithm 3: Image noise enhancement algorithm based on mean filtering
Input: image kernel_size
Output: enhanced_image
  1:  functionenhance_noise_with_average_filter(image, kernel_size)
  2:  height, width = image.shape
  3:  Creates a blank image of the same size as the original image.
  4:  Gets the height and width of the image.
  5:  Performs noise enhancement on the image.
  6:  for y = 0 to height − 1 do
  7:   for x = 0 to width − 1 do
  8:      Calculate the boundary coordinates of the filter. Assume that the coordinates of the computational boundary are (x,y).
(x.y)=top=max(yN/2,0)bottom=min(y+N/2,height1)left=max(xN/2,0)right=min(x+N/2,width1)
  9:      The average value is calculated for the pixels within the filter.
sumvalue=i=topbottomj=leftrightimage(x+iN/2,y+jN/2)
 10:      The average value is used as the enhanced pixel value.
average=sum_valueN×N
 11:   end for
 12:  end for
 13:  return enhanced_image
 14:  end function