Problem creating an array whose values are floats

I am new to MATLAB and I am trying to write a program which inputs an image and applies a filter based on the RGB values in each pixel. I am trying to linearize the RGB values so
RedRatio = RedValue/(RedValue + GreenValue + BlueValue)
GreenRatio = GreenValue/(RedValue + GreenValue + BlueValue)
BlueRatio = BlueValue/(RedValue + GreenValue + BlueValue)
Where RedValue, GreenValue, and BlueValue are all uint8.
The problem I am having is RedRatio, GreenRatio, and BlueRatio are all returning either a 0 or a 1, where the values should be a decimal between 0 and 1.
Can someone help me get these ratios to return a decimal value?
Thanks,
-Tyler

Réponses (1)

Geoff Hayes
Geoff Hayes le 24 Mai 2018
Modifié(e) : Geoff Hayes le 24 Mai 2018
Tyler - try casting your numbers to floats before doing the division. For example,
RedRatio = cast(RedValue,'double') / ...
cast(RedValue + GreenValue + BlueValue, 'double');
Alternatively, you could try
RedRatio = double(RedValue) / ...
double(RedValue + GreenValue + BlueValue);

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by