How to calculate the average gradient of an image?

i have tried this code.But the results are mismatching.
[Gmag, Gdir] = imgradient(X, 'sobel');
AG=abs((sum(sum(mode(Gmag))/(sqrt(2)))))

3 comentarios

Raunak Gupta
Raunak Gupta el 30 de Ag. de 2019
Hi,
Can you provide from what you are comparing with, while generating the result?
Munshida P
Munshida P el 30 de Ag. de 2019
original image and enhanced image(DICOM format)
Munshida P
Munshida P el 30 de Ag. de 2019
Sir, i can't attach my dicom image here because,the file format is not supported.(.dcm)

Iniciar sesión para comentar.

Respuestas (3)

Guillaume
Guillaume el 30 de Ag. de 2019
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 el 30 de Ag. de 2019
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 comentarios

Munshida P
Munshida P el 30 de Ag. de 2019
|Gmag| is there in the equation.....so i used mode function
Bruno Luong
Bruno Luong el 30 de Ag. de 2019
There is no relation between |Gmag| and MODE.
If you code arbitrary without to trying understand what the formula means and what the function does, then you'll get arbitrary result.
Munshida P
Munshida P el 30 de Ag. de 2019
|Gmag| means?
Guillaume
Guillaume el 30 de Ag. de 2019
Editada: Guillaume el 30 de Ag. de 2019
is the absolute value of x, nothing to do with the mode (particularly as mode(x) = x for scalar x). As Bruno says, you need to understand your formula before trying to implement it.
In the same respect, you need to know how G(x, y) is calculated. As I answered, it's probably not calculated with the sobel operator which will give different results to other gradient operators. Wherever you found that formula, there should also be a definition for G(x, y).
edit: in fact, you can be guaranteed that G is not imgradient since imgradient will always return a positive gradient magnitude, so there would be no point in the taking the absolute value.
Munshida P
Munshida P el 30 de Ag. de 2019
k.Iam new to matlab.need more to study about it.i will try once more
Guillaume
Guillaume el 30 de Ag. de 2019
So far, the issue does not appear to be matlab but maths.
Munshida P
Munshida P el 30 de Ag. de 2019
k

Iniciar sesión para comentar.

Raunak Gupta
Raunak Gupta el 30 de Ag. de 2019
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 comentarios

Munshida P
Munshida P el 30 de Ag. de 2019
k...i will try this code
PPO POT
PPO POT el 12 de Sept. de 2019
Please tell me about this research paper title,
I will be investigate this problem.
Munshida P
Munshida P el 12 de Sept. de 2019
base paper:"A new approach for medical image enhancement through luminance level modulation and gradient modulation"
PPO POT
PPO POT el 13 de Sept. de 2019
Thank you, Munshida P
PPO POT
PPO POT el 13 de Sept. de 2019
Editada: PPO POT el 13 de Sept. de 2019
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
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

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 27 de Ag. de 2019

Comentada:

el 13 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by