Skip to main content
. 2022 May 31;8:e953. doi: 10.7717/peerj-cs.953

Algorithm 1: Two-Level Adaptive Median Noise Removal Filter.

Input: The gray level gx,y of the pixel at the coordinates (x,y), the maximal value smax of the side of the square Us.
Output: The noise removed value of the gray level g¯x,y of the pixel in the coordinates (x,y).
Step 1: Assume that LA and LB are the two levels of noise pollution.
Step 2: Consider a s-neighborhood Us. Initially, we take s = 3.
Step 3: Calculate gmed, gmin, gmax as the median, minimal, and maximal gray level of the pixels in Us.
Step 4: Level LA.
A11=gmedgmin,A12=gmedgmax.
Step 5: if (A11 > 0  &&   A12 < 0) then go to Step 11.
Step 6: else s = s + 2 // We increase the size of s-neighborhood Us (s must be an odd number, as the pixel (x,y) must be in the center).
Step 7: end if
Step 8: if ssmax then go to Step 4.
Step 9: else Output: g¯x,y=gx,y.
Step 10: end if
Step 11: Level LB.
B11=gx,ygmin,B12=gx,ygmax.
Step 12: if (B11 ≥ 0   &&   B12 ≤ 0) then Output: g¯x,y=gmed.
Step 13: else Output: g¯x,y=gx,y.
Step 14: end if