"Tom " <firstname.lastname@example.org> wrote in message news:email@example.com... > Hi, > > This is probably really basic but I have the following code:
> img=imread('calibration_020413.tif'); > > %individual pixel > %hr=2.7006e+04; > %hg=3.0236e+04; > %hb=1.9838e+04; > > hr=img(175,300,1); > hg=img(175,300,2); > hb=img(175,300,3); > > dr=((rc.*(hr-ra)))./((ra+rb)-hr) > dg=((gc.*(hg-ga)))./((ga+gb)-hg) > db=((bc.*(hb-ba)))./((ba+bb)-hb) > > The coefficient values were obtained from a previous programme and I need > to use them to calculate a value for the red green and blue channels for > each pixel of an image. I will be optimising between the 3 channels so > right now I am just working with one pixel. If I insert the RGB values for > a pixel after looking them up I get sensible results (the points marked > out with a % sign above) but if I try to have matlab look them up using > hr=img(175,300,1) etc the dr, dg and db values are returned as zero. This > doesnt make sense to me as they are the same value. Can anyone see > something I cant, its probably something basic enough but I dont > understand why it returns a zero value.
Check the class of img. I strongly suspect it will be one of:
uint8 uint16 uint32
Unsigned integers cannot store negative values; the smallest value representable in any of those types is 0. Because img is an unsigned integer class, all the variables hr, hg, and hb will be of that same class. Since ra, ga, and ba are all large values (larger than the corresponding commented out "individual pixel" values) the result of (hr-ra) [and the similar calculations for hg and hb] likely will saturate at 0.