How to calculate single average of all rows and single average of all columns of image?

4 次查看(过去 30 天)
I am having a gray image of size 256 by 256 and want to calculate row and column mean. I am able to calculate column mean of image as follow im=imread('E:\xyz.jpg') cmean=mean(mean(im)); In order to take row mean I took transpose of im matrix and then calculated the mean. im1 = transpose(im); rmean=mean(mean(im1));
Column and row mean should be different. But gives the same answer for row and column mean. What is wrong?

回答(1 个)

Jan
Jan 2017-1-19
As explained in the documentation of doc mean, the dimension to operate on can be defined by the second input:
x = rand(10, 10);
m_dim1 = mean(x, 1);
m_dim2 = mean(x, 2);
If mean(X) and mean(X.') reply the same values, either X is a vector or the means are equal. mean(X) without specifying the dimension operates on the first non-singelton dimension. This is risky: You save half a second during typing, but might spend hours with debugging. So prefer to define the dimension explicitly, because sometime Matlab's smart decisions to guess what you want, are too smart.
  1 个评论
anu
anu 2017-1-19
Your solution is working. But when I applied my solution for following example, its working properly.
A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]
A =
0 1 1
2 3 2
1 3 2
4 2 2
mean(A)
ans =
1.7500 2.2500 1.7500
>> B=transpose(A)
B =
0 2 1 4
1 3 3 2
1 2 2 2
>> mean(B)
ans =
0.6667 2.3333 2.0000 2.6667
But when applied to image matrix not working properly. why?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by