MATLAB: Looping each pixel of matrix image

#looping #pdf

I

Best Answer

If input image is color image
X = imread('img.jpg');
Val = zeros(numel(X)); % initialize pdf values storing variable with zeros
k = 1; % counter variable in for loop
for cha = 1:size(X, 3) % loop of (3 RGB colors)
for r = 1:size(X, 1) % for number of rows of the image

for c = = 1:size(X, 2) % for number of columns of the image

Val(k) = pdf(X(r, c, cha),mu,sigma);
k = k+1; % increment counter loop
end
end
end
If the input image is grayscale image
for r = 1:size(X, 1) % for number of rows of the image
for c = = 1:size(X, 2) % for number of columns of the image
Val(k) = pdf(X(r, c),mu,sigma);
k = k+1; % increment counter loop
end
end