Problem creating an array whose values are floats
Mostrar comentarios más antiguos
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
Respuestas (1)
Geoff Hayes
el 24 de Mayo de 2018
Editada: Geoff Hayes
el 24 de Mayo de 2018
RedRatio = cast(RedValue,'double') / ...
cast(RedValue + GreenValue + BlueValue, 'double');
Alternatively, you could try
RedRatio = double(RedValue) / ...
double(RedValue + GreenValue + BlueValue);
Categorías
Más información sobre Images en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!