Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: issue with MATLAB returning zero as result
Replies: 2   Last Post: Apr 4, 2013 9:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: issue with MATLAB returning zero as result
Posted: Apr 3, 2013 2:52 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"Tom " <thomasburrows@nhs.net> wrote in message
news:kjhi7l$jrm$1@newscl01ah.mathworks.com...
> Hi,
>
> This is probably really basic but I have the following code:


*snip*

> 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.

http://www.mathworks.com/help/matlab/matlab_prog/integers.html

When you typed in the values manually, they were treated as double precision
values and double precision CAN store negative values; there's no saturation
at 0.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.