Borrar filtros
Borrar filtros

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

16 visualizaciones (últimos 30 días)
Rebecca Navarro
Rebecca Navarro el 30 de Sept. de 2015
Comentada: Walter Roberson el 22 de Ag. de 2024 a las 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)

Respuestas (1)

Jatin Singh
Jatin Singh el 22 de Ag. de 2024 a las 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 comentario
Walter Roberson
Walter Roberson el 22 de Ag. de 2024 a las 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');

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by