Why my doesn't work well?
Afficher commentaires plus anciens
Hello,
I am writing a program for my thesis. The goal is to draw a vertical line on an image (in my case all images has 2 colors: white, another color and all possible combinations of the 2 colors) and get the color intensity of each pixel on the image along this line. Also it is possible to choose a number of lines (columns) left and right of the drawn line and then we build the average... My algorithm works that way: after uploading the image on th GUI, a function will convert it in a gray image and save all pixel color values (that means values between 0 and 255) in a matrix value_matrix. Then the user can choose how many lines he want to select left and right of the drawn line. And then a new_matrix will be built, that contains all relevant columns from value_matrix. Now I want to calculate the average of each line of new_matrix. I used this code:
%calculate the averages of pixel values on the same line
new_dim = size (new_matrix);
sum = 0;
for i = 1 : new_dim(1)
for j = 1 : new_dim(2)
sum = sum + new_matrix(i,j)
end
average(i) = sum/new_dim(2);
sum = 0;
end
The problem is that sum can't have a value greater than 255. I don't understand why. For example, if new_matrix is a 200x3 matrix. and on the line 5 we have the values 150, 200 and 50. Normally sum should be 400. But it doesn't work that way. When the summe is greater then 255, sum will have automatically the value 255. Why?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!