# How to calculate the average gradient of an image?

77 ビュー (過去 30 日間)
Munshida P 2019 年 8 月 27 日
コメント済み: Munshida P 2019 年 9 月 13 日
i have tried this code.But the results are mismatching.
AG=abs((sum(sum(mode(Gmag))/(sqrt(2)))))
##### 3 件のコメント表示非表示 2 件の古いコメント
Munshida P 2019 年 8 月 30 日
Sir, i can't attach my dicom image here because,the file format is not supported.(.dcm)

サインインしてコメントする。

### 回答 (3 件)

Guillaume 2019 年 8 月 30 日
Missing from your equation, is the exact definition of G. You're currently using the sobel operator to compute the gradient and as documented in the algorithms section of imgradient whichever operator you use is going to give you vastly different results for the magnitude.
I suspect that your equation use a completely different definition than 'sobel' for G.
As asked by Raunak, for us to be able to tell you what is wrong, we need the actual source image and whatever you compare it to.
##### 0 件のコメント表示非表示 -1 件の古いコメント

サインインしてコメントする。

Bruno Luong 2019 年 8 月 30 日
AG=abs((sum(sum(mode(Gmag))/(sqrt(2)))))
I can't see the denominator factor (H-1)*(W-1). And Why you use MODE?
Those two errors explain discrepency already.
##### 7 件のコメント表示非表示 6 件の古いコメント
Munshida P 2019 年 8 月 30 日
k

サインインしてコメントする。

Raunak Gupta 2019 年 8 月 30 日
Hi,
As per the formula you have mentioned above, the syntax for Calculating ‘AG’ is mistaken. For implementing the formula, you can use below commands.
%Here X is the array for which Gradient is to be calculated
% Here since Gmag represent Magnitude of Gradient so no need to take absolute value
AG = sum(sum(Gmag))./(sqrt(2)*(size(X,1)-1)*(size(X,2)-1));
If you want to try other method for calculating gradient you may investigate ’method’ parameter in imgradient. Please keep in mind that imgradient works only for grayscale images and would not provide required results for RGB images. Here is the link to the documentation of imgradient.
##### 6 件のコメント表示非表示 5 件の古いコメント
Munshida P 2019 年 9 月 13 日
info = dicominfo('MR-MONO2-12-an2');
imshow(X,[])
AG = sum(sum(Gmag))./(sqrt(2)*(size(X,1)-1)*(size(X,2)-1 ))
got it....thank you sir

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by