How to use mean function for image analysis

18 visualizaciones (últimos 30 días)
Sarah Hicks
Sarah Hicks el 25 de Feb. de 2020
Comentada: Wesam Rezk el 3 de Nov. de 2021
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
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...
Wesam Rezk
Wesam Rezk el 3 de Nov. de 2021
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 Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by