Summation problem while lopping of an image

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2016-6-29
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 个评论
Nimit Jain
Nimit Jain 2016-6-29
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by