Effacer les filtres
Effacer les filtres

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

16 vues (au cours des 30 derniers jours)
Rebecca Navarro
Rebecca Navarro le 30 Sep 2015
Commenté : Walter Roberson le 22 Août 2024 à 4:43
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)

Réponses (1)

Jatin Singh
Jatin Singh le 22 Août 2024 à 3:49
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 commentaire
Walter Roberson
Walter Roberson le 22 Août 2024 à 4:43
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');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by