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
What is gradient method using in first option?
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')
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')
As visualization, the second option provided more brightness value
[ Gmag , Gdir ] = imgradient( Gx , Gy ) returns the gradient magnitude and direction from the directional gradients Gx and Gy in the x and y directions, respectively.
Formally, an image gradient is defined as a directional change in image intensity. Or put more simply, at each pixel of the input (grayscale) image, a gradient measures the change in pixel intensity in a given direction.
An image gradient is a directional change in the intensity or color in an image. The gradient of the image is one of the fundamental building blocks in image processing. For example, the Canny edge detector uses image gradient for edge detection.
The gradient magnitude is a scalar quantity that describes the local rate of change in the scalar field. For notational convenience, we will use f′ to indicate the magnitude of the gradient of f, where f is the scalar function representing the data.
The difference is the 'Sobel' operator indeed. The sobel operator is a matrix that is convoluted with the image to compute its directional gradients.
The sobel operator is defined as (from wikipedia):
while what gradient
does is just directional differences. You can interpret this as gradient doing
Gx=[ 0 0 0; Gx=[ 0 -1 0;
-1 0 1; and 0 0 0;
0 0 0] 0 1 0];
This difference is because when one has an image, it is know that it is a discretization of a continuous domain. The Sobel operator helps to take into account things that happen "around" the given pixel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With