How to use mean function for image analysis

18 vues (au cours des 30 derniers jours)
Sarah Hicks
Sarah Hicks le 25 Fév 2020
Commenté : Wesam Rezk le 3 Nov 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 commentaires
Guillaume
Guillaume le 25 Fév 2020
Modifié(e) : Guillaume le 25 Fév 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 le 3 Nov 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);

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Convert Image Type 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