Average intensity of an image
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, an image is in unit8 or greyscale image and data in I(x_i,y_j) format. How will calculate average intensity of an image without using any function and the expression of avg intensity is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1179063/image.png)
0 Kommentare
Antworten (1)
KSSV
am 3 Nov. 2022
A = magic(5) ;
[m,n] = size(A) ;
iwant = 0 ;
for i = 1:m
for j = 1:n
iwant = iwant+A(i,j) ;
end
end
iwant = iwant/(m*n) ;
[iwant mean(A(:))]
4 Kommentare
DGM
am 3 Nov. 2022
If you're going to commit to doing things the hard way, you'll have to also commit to paying extra attention to variable class. If the image is an integer-class array (e.g. uint8), then the accumulated sum will also be implicitly uint8. It will immediately be truncated, so the sum will never exceed 255. In all probability, the product of the page geometry (i.e. m*n) will be much larger than 255, so the division step will round to a mean of 0, since that's the closest integer.
Make sure A is of an appropriate class.
A = double(A);
KSSV
am 3 Nov. 2022
@Surendra Ratnu I have thought about this question while answering. I left it for you to figure out. Any ways you have the answer from @DGM
Siehe auch
Kategorien
Mehr zu Logical 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!