MATLAB: How to apply the “lillietest” function to data from a grayscale image to see how the data fits a normal distribution

distributionimagelilleforslillietestnormalStatistics and Machine Learning Toolbox

How can I apply the "lillietest" function to data from a grayscale image to see how the data fits a normal distribution?
 

Best Answer

In order to apply the "lillietest" function to your image data, please use the following workflow replacing 'download.jpg' with your image name:
img = imread('download.jpg'); % Read the image (either grayscale or not).
grayScaleImg = rgb2gray(img); % Convert to grayscale.
grayScaleImg = reshape(grayScaleImg,1,[]); % Reshape into a column vector.
grayScaleImg = double(grayScaleImg); % Convert to double since lillietest requires double or single.
[h,p,k,c] = lillietest(grayScaleImg); % Apply Lillefors test to get parameters.
 
It is important to know that the  "lillietest" function requires a single vector of raw data instead of separate vectors for the frequency of data points and the data points themselves.