aashay vanarase wrote:
> this doent seem to work, says unexpected {
> global m(index2)=mean2(y)
> global red(index2)=sum(sum(y(:,:,1)))/(256*256)
> global green(index2)=sum(sum(y(:,:,2)))/(256*256)
> global blue(index2)=sum(sum(y(:,:,3)))/(256*256)
global m
global red
global green
global blue
m(index2)=mean2(y)
red(index2)=sum(sum(y(:,:,1)))/(256*256)
green(index2)=sum(sum(y(:,:,2)))/(256*256)
blue(index2)=sum(sum(y(:,:,3)))/(256*256)
By the way, you can replace sum(sum(y(:,:,1)) by
sum(reshape(y(:,:,1),[],1))
which will be faster
I am not convinced that dividing the sum by 256 * 256 is correct, not unless
you are trying to take the mean value of a 256 x 256 array. If your array is
uint8 and you are trying to convert the 0 to 255 values into 0 to 1 values and
find the mean or "total power" of those, then your code is not correct.
Suppose you had a 3 x 3 array whose value was all uint8(1), then the mean
value would clearly be uint8(1), which would convert to 1/256 when adjusted to
the 0 to 1 scale; likewise, the "total power" would be 9/256 when adjust to
the 0 to 1 scale. The sum(sum()) would give 9 in this sample, which you would
then divide by 256*256, which would give completely the wrong value for the
mean, and would give an answer 1/256 too small for the "total power".
|