Azzera filtri
Azzera filtri

Summation problem while lopping of an image

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 29 Giu 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 Commento
Nimit Jain
Nimit Jain il 29 Giu 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by