Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between gradient and imgradient?

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

like image 871
Jame Avatar asked Mar 09 '16 13:03

Jame


People also ask

What does Imgradient do in Matlab?

[ 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.

What is gradient of a pixel?

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.

What is gradient in image processing?

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.

What is gradient magnitude?

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.


1 Answers

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):

enter image description here

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.

like image 134
Ander Biguri Avatar answered Sep 29 '22 02:09

Ander Biguri