How to use mean function for image analysis

I have a question on an assignment that says:
Use the function mean to create a new variable that is a grayscale image of variable A.
I am aware of how to use the mean function, but confused on how to use it to make a grayscale image. Any help would be very appreciated.

3 comentarios

Adam
Adam el 25 de Feb. de 2020
I would guess it means take the mean over the 3rd dimension (R, G, B) of a true RGB image, though you should ask whoever set the assignment really as it is impossible for us to know for sure. It isn't unambiguously defined, though I can't think of any other sensible way to use mean in this context.
Guillaume
Guillaume el 25 de Feb. de 2020
Editada: Guillaume el 25 de Feb. de 2020
Yes, if that's the whole text of the assignment then you're entitled to complain as the assignment is completely meaningless (pun not intended).
If as Adam suspects the variable A is a true colour image, then note that taking the mean of the colour is a very poor way of converting to greyscale.
Of course, if the assignment doesn't specify what a valid greyscale image of variable A is supposed to be, then:
newvariable = mean(1);
would be a greyscale image of any variable. Not a very useful one, of course...
To convert RGB image to grayscale with mean function, you have to make sure to assign the output variable of mean function to uint8 since imshow takes this data type as input. Also, it is different when using mean function with matrices as it has different input arguments.
For example
Converting RGB bulitin image peppers in MATLAB to grayscale
A=imread('peppers.png');
% M=mean(A,dim) the input argument dim returns mean along dim
M=mean(A,3); % M has double as data type
N=uint8(M); % Now N is uint8 data type. Converting from double to uint8
imshow(N);

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Feb. de 2020

Comentada:

el 3 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by