Borrar filtros
Borrar filtros

Summation problem while lopping of an image

1 visualización (últimos 30 días)
Nimit Jain
Nimit Jain el 29 de Jun. de 2016
Comentada: Nimit Jain el 29 de Jun. de 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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Jun. de 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 comentario
Nimit Jain
Nimit Jain el 29 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by