How to calculate variance, kurtosis, and skewness of a ROI (Region of Interest) in grayscale image?
    10 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
I'm going to calculate means, standard deviation, kurtosis, skewness, and also variance from a ROI of grayscale image. I create select the ROI using mask. This is the code I use
Img = imread('image_name.jpg');
GrayImg = rgb2gray(Img);
h = impoly(gca);
wait(h);
mask = createMask(h);
Mean = mean2(GrayImg(mask));
StandardDeviation = std2(GrayImg(mask));
How to calculate variance, kurtosis and skewness of the grayscale image using the mask? Is the code to calculate mean and standard deviation is correct?
0 commentaires
Réponses (2)
  Image Analyst
      
      
 le 29 Déc 2024
        See my attached demo for computing image moments.  Adapt as needed.
0 commentaires
  ag
      
 le 29 Déc 2024
        Hi Yogi,
To calculate the statistical measures such as mean, standard deviation, variance, kurtosis, and skewness for a region of interest (ROI) in a grayscale image, you can utilize a mask to define the ROI. Below is an improved version of your code, which accurately performs these calculations:
% Read the image and convert it to grayscale
Img = imread('image_name.jpg');
GrayImg = rgb2gray(Img);
% Select the ROI using a polygon tool
h = impoly(gca);
wait(h);
% Generate a mask from the selected polygon
mask = createMask(h);
% Extract the pixel values within the mask
maskedPixels = GrayImg(mask);
% Compute the statistical measures
Mean = mean(maskedPixels);
StandardDeviation = std(maskedPixels);
Variance = var(maskedPixels);
Kurtosis = kurtosis(double(maskedPixels)); % Convert to double for kurtosis
Skewness = skewness(double(maskedPixels)); % Convert to double for skewness
% Display the results
For more details, please refer to the following MathWorks documentations:
- mean - https://www.mathworks.com/help/matlab/ref/double.mean.html
- std - https://www.mathworks.com/help/matlab/ref/double.std.html
- var - https://www.mathworks.com/help/matlab/ref/double.var.html
- kurtosis - https://www.mathworks.com/help/stats/kurtosis.html
- skewness - https://www.mathworks.com/help/stats/skewness.html
Hope this helps!
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


