RGB2YCBCR image convertion

2 ビュー (過去 30 日間)
eng m
eng m 2021 年 5 月 9 日
コメント済み: Walter Roberson 2021 年 5 月 9 日
i have this code i need to center Y,CB,CR around the center please show me what can i do.is truo?
I = imread('lena.tiff');
J2 = rgb2ycbcr((I));;
J2 =double(J2);
Y =((J2(:,:,1)));
cb=((J2(:,:,2)));
cr=((J2(:,:,3)));
Y=Y-128;
cb=cb-128;
cr=cr-128
T=dctmatx(8);
  2 件のコメント
DGM
DGM 2021 年 5 月 9 日
What do you mean "center" it? Cb and Cr should be centered about 128, since they're uint8. Also since they're uint8, subtracting 128 will truncate half the data.
eng m
eng m 2021 年 5 月 9 日
mean around to zero ,thanks

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 5 月 9 日
Y=Y-128;
cb=cb-128;
cr=cr-128
If you read the documentation for rgb2ycbcr
Converted YCbCr color values, returned as a numeric array of the same size as the input.
  • If the input is double or single, then Y is in the range [16/255, 235/255] and Cb and Cr are in the range [16/255, 240/255].
  • If the input is uint8, then Y is in the range [16, 235] and Cb and Cr are in the range [16, 240].
  • If the input is uint16, then Y is in the range [4112, 60395] and Cb and Cr are in the range [4112, 61680].
So if you wanted to center Y around 0 you would subtract (235-16)/2 + 16 = 125.5 and for Cb and Cr you would subtract (240-16)/2 + 16 = 128
  3 件のコメント
eng m
eng m 2021 年 5 月 9 日
thanks mr walter ,
and then can add again in the last code to repeat it ?
like this
Y = Y+125.5;
cb = cb+128;
cr = cr+128;
Walter Roberson
Walter Roberson 2021 年 5 月 9 日
yes

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 5 月 9 日
Do you mean like
cb = cb - mean(cb(:));
cr = cr - mean(cr(:));
or possibly rescale so the max is at 127 and the min is at -127?
cb = rescale(cb, -127, 127);
cr = rescale(cr, -127, 127);
Those are two different things of course. They shift and scale the gamut by different amounts. I don't really know what your intent is, or why it's even necessary.
  4 件のコメント
eng m
eng m 2021 年 5 月 9 日
please @Image Analyst i need to center y cb, cr around to zero
to do best compession and reduse storge .to do jpeg color image
Image Analyst
Image Analyst 2021 年 5 月 9 日
編集済み: Image Analyst 2021 年 5 月 9 日
@eng m, as Walter discussed "centered" is not a clear cut definition. You need to describe what centered means. We can think of at least 3 definitions based on range, mean, or median. But it looks like you are all set now (whatever the definition you used was) because you've accepted an answer.

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by