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

Risposte (1)

Geoff Hayes
Geoff Hayes il 24 Mag 2018
Modificato: Geoff Hayes il 24 Mag 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);

Categorie

Scopri di più su Images in Centro assistenza e File Exchange

Richiesto:

il 24 Mag 2018

Modificato:

il 24 Mag 2018

Community Treasure Hunt

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

Start Hunting!

Translated by