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!