How to calculate the average gradient of an image?

조회 수: 32 (최근 30일)
Munshida P
Munshida P 2019년 8월 27일
댓글: Munshida P 2019년 9월 13일
i have tried this code.But the results are mismatching.
[Gmag, Gdir] = imgradient(X, 'sobel');
AG=abs((sum(sum(mode(Gmag))/(sqrt(2)))))
  댓글 수: 3
Munshida P
Munshida P 2019년 8월 30일
original image and enhanced image(DICOM format)
Munshida P
Munshida P 2019년 8월 30일
Sir, i can't attach my dicom image here because,the file format is not supported.(.dcm)

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

답변 (3개)

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

Bruno Luong
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
Guillaume
Guillaume 2019년 8월 30일
So far, the issue does not appear to be matlab but maths.
Munshida P
Munshida P 2019년 8월 30일
k

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


Raunak Gupta
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
[Gmag,Gdir] = imgradient(X,'sobel');
% 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
PPO POT
PPO POT 2019년 9월 13일
편집: PPO POT 2019년 9월 13일
This is my code, with this code you can browse image file and then calculate AG automatically,
[filename1,pathname] = uigetfile('*.*',' Select the Original Image ');
orgIM = imread(filename1);
% Pattern
%[Gmag, Gdir] = imgradient(I,'prewitt');
% 1] If test image is true color covert its to grayscale
if size(orgIM,3) == 3
testIM = rgb2gray(imread(filename1));
[Gmag,Gdir] = imgradient(testIM,'prewitt');
% Calcualte Average gradient
AG = sum(sum(Gmag))./(sqrt(2)*(size(testIM,1)-1)*(size(testIM,2)-1))
end
Munshida P
Munshida P 2019년 9월 13일
info = dicominfo('MR-MONO2-12-an2');
X= dicomread(info);
imshow(X,[])
[Gmag,Gdir] = imgradient(X,'prewitt');
%Average gradient
AG = sum(sum(Gmag))./(sqrt(2)*(size(X,1)-1)*(size(X,2)-1 ))
got it....thank you sir

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by