I tried to understand masking and how it works with image filters. I am using the following code to try to develop my understanding.
import scipy.ndimage as ndi
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(seed=182)
mask = np.random.randint(2, size=(901, 877))
img = np.random.rand(901, 877)
img_masked = np.ma.masked_array(img, mask = mask)
img_masked_filtered = ndi.median_filter(img_masked, size=10)
img_unmasked_filtered = ndi.median_filter(img, size=10)
median_masked = np.ma.median(img_masked)
median_unmasked = np.ma.median(img)
In the results, median_unmasked! = Median_masked, as expected, but img_masked_filtered == img_unmasked_filtered, which I don't want. scipy.ndimage.median_filter does exactly the job that I need, but it does not work with masked images. What can I use, it will do the same as the median filter, but which will work on a masked image?
The weird size I use for the array is that the size of the image that I end up wanting to filter is