Summation problem while lopping of an image

1 vue (au cours des 30 derniers jours)
Nimit Jain
Nimit Jain le 29 Juin 2016
Commenté : Nimit Jain le 29 Juin 2016
close all
clear all
a = imread('lena.tif');
figure, imshow(a);
[r,c] = size(a);
sum = 0;
fileID = fopen('exp.txt','w');
fileID1 = fopen('totalValue.txt', 'w');
for i=1:r
for j=1:c
value = a(i,j);
sum = sum + value;
fprintf(fileID,'%d\n', value);
fprintf(fileID1, '%d\n' , sum);
disp(a(i,j));
end
end
fclose(fileID);
fclose(fileID1);
Total some coming is 255. I am trying to get the per pixel value. Image size is 255x255.
Please help.

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Juin 2016
value = double( a(i,j) );
and please rename your variable sum as you are interfering with the use of the important function sum which is likely to cause you problems as you keep developing your program (including the problem that it confuses the people you are asking to read your code.)
  1 commentaire
Nimit Jain
Nimit Jain le 29 Juin 2016
Thanks Walter now it is working fine. Actually from the total the sum I am trying to get the size contribution by each pixel (x,y) in the image.
Suppose I have 255x255 image and the image size is 400 KB. Now I am trying to calculate each pixel (x,y) size contribution (even in terms of RGB).
Can you please help me out in this.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by