i want to convert an image from rgb to xyz and want to get the values of x and y and z separately. so i am having a problem. how can i encounter the problem?????

3 ビュー (過去 30 日間)
pritha Das
pritha Das 2014 年 11 月 20 日
編集済み: Thorsten 2014 年 11 月 20 日
RGB = [255; 255; 255 ];
rRGB=RGB(:,:,1);
gRGB=(RGB(:,:,2)./RGB(2)) * 100;
bRGB=RGB(:,:,3);
M = [0.4124564 0.3575761 0.1804375
0.2126729 0.7151522 0.0721750
0.0193339 0.1191920 0.9503041] ;
X = rRGB * 0.4124564 + gRGB * 0.2126729 + bRGB* 0.0193339;
Y = rRGB * 0.3575761 + gRGB * 0.7151522 + bRGB* 0.1191920;
Z= rRGB * 0.0193339 + gRGB * 0.1191920 + bRGB* 0.9503041 ;
so when i am running the programme i am getting this error
??? Index exceeds matrix dimensions.
Error in ==> pd at 3 gRGB=RGB(:,:,2)./RGB(2);
by d way when i am putting RGB=imread('F:\47.jpg', 'jpg') then i m getting a result..... what is the problem in the code???
  1 件のコメント
Thorsten
Thorsten 2014 年 11 月 20 日
編集済み: Thorsten 2014 年 11 月 20 日
A more elegant way to compute XYZ is
XYZ = M*squeeze(RGB)
(given that RGB is a 1x1x3 matrix.)

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

回答 (1 件)

Guillaume
Guillaume 2014 年 11 月 20 日
Your RGB is a 3x1x1 matrix. There's only one valid value for the index in the third dimension (1), so
RGB(:, :, 2)
RGB(:, :, 3)
are both invalid.
Probably, you meant to declare RGB as
RGB(1, 1, :) = [255 255 255];

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by