whats the meaning of this statement average = sum ( sum ( x(:,:) ) ) / n / n; ?

9 ビュー (過去 30 日間)
Gursheen
Gursheen 2014 年 3 月 3 日
コメント済み: Gursheen 2014 年 3 月 3 日
i am using this formula for increasing the contrast of the image. this is the formula used to calculate the average value of the after getting the size of the array of the image by using n=size(x,1); ? where x is the image on which we are working..

採用された回答

Daniel Shub
Daniel Shub 2014 年 3 月 3 日
The meaning of the statement
average = sum ( sum ( x(:,:) ) ) / n / n;
is that whoever wrote the code knows very little about MATLAB. Assuming x is an n x n matrix, the code calculates the average/mean by summing over all the columns to create a row of sums and then summing across the row to get the total sum of the matrix. It then divides by n twice to get the average. The same thing can be done much more clearly with
average = mean(x(:));
where (:) is needed to turn a matrix into a column vector.
  1 件のコメント
Gursheen
Gursheen 2014 年 3 月 3 日
wow..thanks a lot.. THERE IS ALSO A CODE THAT FOLLOWS WHICH NEEDS UNDERSTANDING...PLEASE HELP ME OUT WITH THIS AS WELL. HERE GRAY IS THE NAME OF THE IMAGE gray=double(gray);
gray3d(1,:,:) = circshift ( gray, [ -1, -1 ] ); gray3d(2,:,:) = circshift ( gray, [ -1, 0 ] ); gray3d(3,:,:) = circshift ( gray, [ -1, 1 ] ); gray3d(4,:,:) = circshift ( gray, [ 0, -1 ] ); gray3d(5,:,:) = circshift ( gray, [ 0, 1 ] ); gray3d(6,:,:) = circshift ( gray, [ 1, -1 ] ); gray3d(7,:,:) = circshift ( gray, [ 1, 0 ] ); gray3d(8,:,:) = circshift ( gray, [ 1, 1 ] );
gray_average = sum ( gray3d ) / 8.0;
% The SUM operation on an (L,M,N) array returns a (1,M,N) array.
gray_average_2d(1:m,1:n) = gray_average(1,1:m,1:n);
I AM UNABLE TO UNDERSTAND THE CODE...PLEASE HELP....THANKS ALOT

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Filtering and Enhancement についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by