I have a large gridded dataset I'd like to lowpass filter. The catch is, need to specify a different sigma value for each pixel of the grid.
Using a single value of sigma for the entire grid is easy with imgaussfilt, so for example, I can filter the grid I using a sigma value of 3 like this:
I = 10*rand(100);
If = imgaussfilt(I,3);
But I don't want tuse a single value of sigma for the entire grid. Instead, I want to specify a different sigma for every pixel. For this 100x100 grid it's easy to loop through each row and column, filtering the grid to specified values of sigma like this:
sigma = abs(peaks(100))+0.1;
If2 = NaN(size(I));
for row = 1:size(I,1)
for col = 1:size(I,2)
tmp = imgaussfilt(I,sigma(row,col));
If2(row,col) = tmp(row,col);
The nested loop approach gives the answer I want, but it's inelegant, and slow for very large grids. Is there a better way to define a locally-varying filter?