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
回答 (1 件)
Geoff Hayes
2018 年 5 月 24 日
編集済み: Geoff Hayes
2018 年 5 月 24 日
RedRatio = cast(RedValue,'double') / ...
cast(RedValue + GreenValue + BlueValue, 'double');
Alternatively, you could try
RedRatio = double(RedValue) / ...
double(RedValue + GreenValue + BlueValue);
カテゴリ
ヘルプ センター および File Exchange で Images についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!