Borrar filtros
Borrar filtros

Getting wrong value of sum

2 visualizaciones (últimos 30 días)
Khawaja Asim
Khawaja Asim el 13 de Ag. de 2011
I am writing a code in matlab and dealing with images. I am basically finding the sum of value of each pixel, for this I am using code "sum=0; for i=1:584 for j=1:40 img(i,j) sum=sum+img(i,j) end end" here img(i,j) is any gray-scale image. the problem arises here is that the value of "sum" never accedes from 255. Hence I can't get correct value of sum. Someone please help me in finding correct values of sum

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 13 de Ag. de 2011
First of all don't use sum as a variable since it's a MATLAB function, next time you try to call the function it will be obfuscated by your variable.
Second img is a uint8 class which cannot store more than 256 values (zero included):
intmax('uint8')
Do the following
out = sum(double(img(:)))
Note that I am using the function sum to perform the summation and assignin the value to something else but any MATLAB function named variable.
  1 comentario
Khawaja Asim
Khawaja Asim el 13 de Ag. de 2011
Thank you dear!!! You have helped me alot.. :) I am working on it furthur, do help me whenever next time I have any problem

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by