How can I get the mean of my rgb2gray image and show the new image?

2 次查看(过去 30 天)
so far, i have ....
RGB = imread('project1.png');
A = imresize(RGB, .25 );
figure(1)
imshow(A)
%%gray scale
I = rgb2gray(RGB);
B = imresize(I, .25);
figure(2)
imshow(B)
%%mean color
m = mean(B(:)); % how do i get the mean of the gray image and then show it
figure(3)
imshow(m)

回答(1 个)

Jatin
Jatin 2024-8-22
Hi Rebecca,
As per my understanding you are trying to display an image with the mean value of the gray image.
To do that you have to display an image where each pixel has same value equal to the mean. The “imshow” function expects an image matrix, but the code is providing a scalar value equal to the mean.
Here is something you can do:
%mean color
m = mean(B(:));
%creating an image array of pixel value equal to mean
meanImage = uint8(m * ones(size(B)));
figure(3)
imshow(meanImage)
Note: This is the code that does what you want but using this will give all pixels the same value.
Kindly refer this documentation about what “uint8” does:
Hope this helps!
  1 个评论
Walter Roberson
Walter Roberson 2024-8-22
Note that there are multiple ways of constructing the mean image, including
meanImage = repmat(uint8(m), size(B));
%or
meanImage = uint8(m) + zeros(size(B), 'uint8');
%or
meanImage = uint8(m) .* ones(size(B), 'uint8');

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by