apply_median_filter

ketos.audio.utils.filter.apply_median_filter(img, row_factor=3, col_factor=4)[source]

Discard pixels that are lower than the median threshold.

The resulting image will have 0s for pixels below the threshold and 1s for the pixels above the threshold.

Note: Code adapted from Kahl et al. (2017)

Paper: http://ceur-ws.org/Vol-1866/paper_143.pdf Code: https://github.com/kahst/BirdCLEF2017/blob/master/birdCLEF_spec.py

Args:
imgnumpy array

Array containing the img to be filtered. OBS: Note that contents of img are modified by call to function.

row_factor: int or float

Factor by which the row-wise median pixel value will be multiplied in orther to define the threshold.

col_factor: int or float

Factor by which the col-wise median pixel value will be multiplied in orther to define the threshold.

Returns:
filtered_img: numpy array

The filtered image with 0s and 1s.

Example:
>>> from ketos.audio.utils.filter import apply_median_filter
>>> img = np.array([[1,4,5],
...                 [3,5,1],
...                 [1,0,9]])
>>> img_fil = apply_median_filter(img, row_factor=1, col_factor=1)
>>> print(img_fil)
[[0 0 0]
 [0 1 0]
 [0 0 1]]