MATLAB Answers

How to calculate gradient features of an image?

54 views (last 30 days)
Maninder
Maninder on 22 Oct 2014
Commented: Munshida P on 25 Aug 2019
My code is:
a = imread('C:\Users\DELL\Desktop\01_test.tif');
[Gx, Gy] = gradient(a);
[Gmag, Gdir] = gradient(Gx, Gy);
figure, imshow(Gmag, []), title('Gradient magnitude') figure, imshow(Gdir, []), title('Gradient direction') title('Gradient Magnitude (Gmag) and Gradient Direction (Gdir) using Sobel method') figure; imshowpair(Gx, Gy, 'montage'); axis off; title('Directional Gradients, Gx and Gy, using Sobel method')
error is:
??? Error using ==> rdivide Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> gradient at 75 g(2:n-1,:) = (f(3:n,:)-f(1:n-2,:))./h(:,ones(p,1));

  1 Comment

Guillaume
Guillaume on 22 Oct 2014
Please use the {} Code button to format your code.
And what is your question exactly?

Sign in to comment.

Answers (2)

Guillaume
Guillaume on 22 Oct 2014
Possibly, you meant to use imgradient or imgradientxy.
You left out the important bit of the error, which is the one that told you on which line of your code the error occurred. I assume it's the
[Gmag, Gdir] = gradient(Gx, Gy);
line that gives you the error, since the 2nd argument to gradient must be a scalar value.

  10 Comments

Show 7 older comments
Malik Zulqarnain
Malik Zulqarnain on 25 Apr 2018
how i can calculate high gradient values of image
Munshida P
Munshida P on 25 Aug 2019
how to calulate the average gradient ?
i have calculated Gx,Gy,Gmag,Gdir

Sign in to comment.


Munshida P
Munshida P on 24 Aug 2019
how to calculate average gradient of an image

  6 Comments

Show 3 older comments
Munshida P
Munshida P on 25 Aug 2019
yaaaa....i understand
how can i calculate this?please help me sir
Capture.PNG
Walter Roberson
Walter Roberson on 25 Aug 2019
[Gmag, Gdir] = imgradient(YourGrayscaleImage, 'prewitt');
average_gradient = sum(double(Gmag(:))) ./ ((size(Gmag,1)-1) .* ((size(Gmag,2)-1).*sqrt(2));

Sign in to comment.


Translated by