Filter löschen
Filter löschen

Discontinuities in imgaussfilt3 near integer values of sigma

2 Ansichten (letzte 30 Tage)
qfn
qfn am 9 Aug. 2021
Kommentiert: qfn am 10 Aug. 2021
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 ?

Akzeptierte Antwort

DGM
DGM am 10 Aug. 2021
Bearbeitet: DGM am 10 Aug. 2021
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.

Weitere Antworten (0)

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by