Reputation: 1375
In applying the laplacian to an image,What is the difference between
fspecial('laplacian', alpha)
and
L = del2(U)
Do they do the same operation on image?
Upvotes: 2
Views: 604
Reputation: 10859
Except for a factor of 4 (del2 is only one fourth of the laplacian for 2D images) they are both approximating the Laplacian. They are both using a 3x3 filter, however the edges are treated differently. They use exactly the same filter for parameter alpha
in fspecial
set to 0. For all other values of the paramter fspecial
will deliver a more smooth estimate of the Laplacian which is important in cases of noisy images.
Example:
[xi, yi] = ndgrid(1:10, 1:10);
data = xi.^2 + yi.^2 + rand(10);
a = 4 * del2(data);
alpha = 0;
b = imfilter(data, fspecial('laplacian', alpha),'replicate');
sum(sum(abs(a(2:end-1,2:end-1)-b(2:end-1,2:end-1))))
gives
ans = 7.061e-13
del2
is about 4 times faster because of lower overhead and behaves better at the borders. fspecial
with parameter alpha
set to 0 is not very smooth. For very noisy data alpha
closer to 1 might be desired. Noisy numerical derivatives is a topic for itself.
Comment: See the sources of del2 and fspecial with ctrl.+d in the editor and you see what they are doing.
Upvotes: 4