scaling - Matlab Bug -- Matrix Elements Keep Maxing Out -


there's peculiar bug in code can't seem figure out. context, image, matrix, consisting of scaled values 0 255. getspatavg function not included here. problem i'm facing elements in ngtdm max out @ 255. when function finishes, matrix ngtdm consisting of many many values 255. code below shows on computer.

function ngtdm = getngtdm(i,d)     [rowi, coli] = size(i);      ngtdm = zeros(256, 1);      r=1+d:rowi-d           c=1+d:coli-d             term = i(r,c)-getspatavg(r,c);              ngtdm(i(r,c)+1)=ngtdm(i(r,c)+1)+term;          end      end end  

i isolated specific value in i, 254, in code below.

function ngtdm = getngtdm(i,d)     [rowi, coli] = size(i);      ngtdm = zeros(256, 1);      r=1+d:rowi-d           c=1+d:coli-d             if(i(r,c)==254)                 term = i(r,c)-getspatavg(r,c);                  disp(term);                  ngtdm(i(r,c)+1)=ngtdm(i(r,c)+1)+term;             end          end      end  end  

the variable 'term', in instance 222. there 369 instances of 222. therefore value @ ngtdm(255) (254+1=255) should larger 255, yet element still maxed out @ 255. when replace term 222 shown below:

ngtdm(i(r,c)+1)=ngtdm(i(r,c)+1)+222;  

i correct value, number larger 255.

i can't seem figure out why element maxing out @ 255. fact values of scaled between 0 , 255. i'm pretty positive getspatavg not issue because correct value being returned.

thank you

it's not bug - sounds using uint8 datatype. if convert datatype more bits - e.g. uint16, uint32, single, double, etc - not run problem. guess working images, images read using imread read in uint8 default save memory. quickest fix: use i=double(i); either @ start of function, or on variable before put functions.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -