Discontinuities in imgaussfilt3 near integer values of sigma

1 次查看(过去 30 天)
I've noticed some discontinuities in the way that imgaussfilt3 works when sigma nears (and passes) and integer value. This is readily reproducible, as shown below:
rng(1)
A=randn(100,100,100);
ind=find(A==max(A(:)));
X=linspace(.9,5.1,1000);
dist=0*X;
for i=1:1000
i
B=imgaussfilt3(A,X(i));
dist(i)=B(ind);
end
scatter(X,dist)
This gives the following plot, clearly showing issues at integer values. This is also visible if you increase the "resolution", that is something like X=linspace(2.98,3.02,1000) with the same loop, you readily see this issue.
What's happening here ? Why is this function not continuous as a function of inputted sigma ?

采纳的回答

DGM
DGM 2021-8-10
编辑:DGM 2021-8-10
This also happens for imgaussfilt() and others (e.g. using MIMT fkgen() and imfilter()). If you take a closer look, you'll notice it's not strictly integer-values that are the problem areas. It's integers and half-integers.
rng(1)
A=randn(100,100);
ind=find(A==max(A(:)));
X=linspace(.9,5.1,1000);
dist=0*X;
for i=1:1000
B=imgaussfilt(A,X(i));
dist(i)=B(ind);
end
plot(X,dist,'.')
grid on
These defects are an artifact of the kernel size calculation, which must be integer-valued.
bsig = linspace(.9,5.1,1000);
bsize = 2*ceil(2*bsig) + 1;
plot(bsig,bsize);
grid on
The significance of these sudden changes can be reduced by explicitly specifying a larger filter size.
rng(1)
A=randn(100,100);
ind=find(A==max(A(:)));
X=linspace(.9,5.1,1000);
dist=0*X;
for i=1:1000
bsize = 2*ceil(4*X(i)) + 1;
B=imgaussfilt(A,X(i),'filtersize',bsize);
dist(i)=B(ind);
end
plot(X,dist,'.')
grid on
I tend to prefer a bit more filter support than the default provides, but as always, the defaults are a compromise between quality and speed.

更多回答(0 个)

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by