I have a 2D signal, and I want to compute a new signal by calculating a weighted mean of each sample's neighbours. However, I also have a 2D bitmask, the same size as the original signal, which indicates that samples in certain positions should be ignored in any average they appear in, including not being counted in the total number of points being averaged, e.g. if my kernel was a 3x3 grid with 1/9 in each entry, then a masked position next to the sample being averaged would mean the sum (of the remaining 8 elements) would be divided by 8 instead of 9. (Unfortunately my kernel is not this simple in practice)
For now, I am calculating this in amplitude space straightforwardly, i.e. for each sample, I go through each value in the kernel, check whether the corresponding cell is masked, and if not, add it to a running total, then divide by the number of unmasked cells.
My understanding is that if I was not masking out samples, this would be a convolution and I could compute the same result more efficiently by taking the FFT of the signal, the FFT of the (zero-padded) kernel, multiplying the two elementwise and then un-FFTing. Being able to do the calculation this way would be a big performance improvement, because I already have to do an FFT of the data for other reasons and so retaining it is "free."
Does anyone know if it is possible to extend the FFT method to take into account that certain samples should be ignored?