What is the difference between gradient and imgradient?

Viewed 1353

I would like to compute gradient of image I. I have two options that are

[Gx, Gy] = gradient(I);
g = sqrt(Gx.^2+Gy.^2);

and

[g,~] = imgradient(I, 'sobel');

My question are

  1. What is gradient method using in first option?

  2. What is befinet of finding gradient using sobel method ?

Thank all

This is what I tried

I=zeros([128 128]);
I(50:100,50:100)=100;
[Gx, Gy] = gradient(I);
g1 = sqrt(Gx.^2+Gy.^2);
[g2,~] = imgradient(I, 'sobel');
subplot(121);imshow(g1,[]);title('First option')
subplot(122);imshow(g2,[]);title('Second option')

enter image description here

When noisy is added to image, the different will be more clear

I=zeros([128 128]);
I(50:100,50:100)=100;
%% Add noise image;
noiseStd=5;
I_noise = I + (noiseStd * randn([128, 128]));
[Gx, Gy] = gradient(I_noise);
g1 = sqrt(Gx.^2+Gy.^2);
[g2,~] = imgradient(I_noise, 'sobel');
subplot(121);imshow(g1,[]);title('First option')
subplot(122);imshow(g2,[]);title('Second option')

enter image description here

As visualization, the second option provided more brightness value

2 Answers
Related