What is the decimal RGB scale used in Matlab called?

182 ビュー (過去 30 日間)
P_L
P_L 2019 年 2 月 7 日
編集済み: Adam Danz 2019 年 2 月 8 日
Hi there,
I have been trying lots of websites to find colours for my plots. The colours i find on webistes that are RGB are ont on the decimal scale. Therefore is there another scale I should search for, or is there a way to convert them?
Example:
  • RGB: (37, 147, 174)
Many thanks!
  1 件のコメント
Rik
Rik 2019 年 2 月 7 日
The colors in Matlab are generally 8bit, meaning that the colors are scale 0-255. So I don't know what you would mean by converting.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 2 月 7 日
編集済み: Adam Danz 2019 年 2 月 8 日
As Rik Wisselink mentioned, RGB values are scaled to 0-255 (8 bit means 2^8 which equal 256). Matlab normalizes each RGB value to this 256 range. So a value of 0.5 means 50% of the 256 range.
For example, the color crimson is represented as [0.85938 0.078125 0.23438]. When you multiply this by 256,
[0.85938 0.078125 0.23438] * 256
ans =
[ 220 20 60]
Likewise, if you have an RBG value of [0, 250, 100], matlab will represent it as
[0, 250, 100] / 256
ans =
[ 0 0.97656 0.39063]
[UPDATE]
Scaling by 255 makes more sense than by 256 for reasons explained in the comment section below.
  5 件のコメント
Stephen23
Stephen23 2019 年 2 月 8 日
編集済み: Stephen23 2019 年 2 月 8 日
@ Adam Danz & Image Analyst: errrr... why divide by 256?
Why not just divide by 255 (that being the maximum value per channel, and is exactly what MATLAB's inbuilt functions do, e.g. im2double)? Is there a secret reason why you want to scale the colors a smidgen darker, and totally ignore white?
>> im2double(uint8(255)) % correct scaling
ans = 1
>> 255/255 % correct scaling
ans = 1
>> 255/256 % your suggestions
ans = 0.99609
See also the MATLAB documentation:
which explains:
"Conversely, divide by 255 after converting a uint8 RGB image to double:"
RGB64 = double(RGB8)/255
Adam Danz
Adam Danz 2019 年 2 月 8 日
That's a good point and the better scaler is 255 for that reason.
The rgb() FEX function scales all values < 240 using 256 and then essentially scales values 241:255 using 255. The author notes that scaling by 256 more often gives rounder numbers such as [0 128 0] / 256 = [0 .5 0] but that rarely matters.

サインインしてコメントする。

その他の回答 (2 件)

TADA
TADA 2019 年 2 月 7 日
some functions like plot use color intensity values (between 0 and 1) to represent RGB values, instead of what you are used to and is used in web browsers (values between 0 and 255).
you can just take your RGB vector and divide it by 255
also I found this rgb function very useful
  1 件のコメント
Stephen23
Stephen23 2019 年 2 月 8 日
+1 at least someone got the scaling right.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2019 年 2 月 7 日
uint8() the decimal values to get something that MATLAB will understand.

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by