How to use mean function for image analysis
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Guillaume
am 25 Feb. 2020
Bearbeitet: Guillaume
am 25 Feb. 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
am 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);
Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!