MATLAB: How to create an image by replacing each pixel with mean RGB value.

imageMATLABmeanrgb

I need to create an image by replacing each pixel with the mean value of its RGB components.

Best Answer

Specify the dimension to the mean function. It will create a grayscale image
img = im2double(imread('peacock.jpg'));
img_mean = mean(img, 3);
fig = figure();
subplot(1, 2, 1);
imshow(img);
subplot(1, 2, 2);
imshow(img_mean);