How to calculate gradient features of an image?

조회 수: 11 (최근 30일)
Maninder
Maninder 2014년 10월 22일
댓글: Munshida P 2019년 8월 25일
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
Guillaume
Guillaume 2014년 10월 22일
Please use the {} Code button to format your code.
And what is your question exactly?

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillaume
Guillaume 2014년 10월 22일
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
Munshida P
Munshida P 2019년 8월 25일
Capture.PNG
Munshida P
Munshida P 2019년 8월 25일
how to calulate the average gradient ?
i have calculated Gx,Gy,Gmag,Gdir

댓글을 달려면 로그인하십시오.


Munshida P
Munshida P 2019년 8월 24일
how to calculate average gradient of an image
  댓글 수: 6
Walter Roberson
Walter Roberson 2019년 8월 25일
[Gmag, Gdir] = imgradient(YourGrayscaleImage, 'prewitt');
average_gradient = sum(double(Gmag(:))) ./ ((size(Gmag,1)-1) .* ((size(Gmag,2)-1).*sqrt(2));
Munshida P
Munshida P 2019년 8월 25일
Thank you sir. I will try it now

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by