0
votes

why we convert rgb image to double precision before applying the transformation formula that convert from rgb to ycbcr?

rgb = im2double(in);

% These equations transform RGB in [0,1] to YCBCR in [0, 255]
out(:,:,1) = 16 + 65.481 * rgb(:,:,1) + 128.553 * rgb(:,:,2) + 24.966 * rgb(:,:,3);
out(:,:,2) = 128 - 37.797 * rgb(:,:,1) - 74.203 * rgb(:,:,2) + 112 * rgb(:,:,3);
out(:,:,3) = 128 + 112 * rgb(:,:,1) - 93.786 * rgb(:,:,2) -18.214 * rgb(:,:,3);
1

1 Answers

3
votes

im2double scales the RGB image from a 0-255 range into a 0-1 range, which is needed by the conversion equations.

Also, the image should be in double format, rather than uint8, so that precision is not lost during calculation. If the image was not double, the result would be rounded and would be less accurate.