soren at hauberg.org
soren at hauberg.org
Mon Aug 4 02:16:20 CDT 2008
Hmm, I'm surprised that your code is slow. You could try something
like this (untested code):
function ycbcr = rgb2ycbcr(rgb)
A = [77, 150, 29; -44, -87, 131; 131, -110, -21]/256;
tmp = round(A*[rgb(:,:,1)(:), rgb(:,:,2)(:), rgb(:,:,3)(:)].');
ycbcr = cat (3, reshape (tmp (1,:), s), reshape (tmp (2,:), s),
reshape (tmp (3,:), s));
endfunction
but I doubt it'll be much faster. Also, there is one detail about your code:
Quoting bharat pathak <bharat at arithos.com>:
> ycbcr(:,:,1) = y;
> ycbcr(:,:,2) = cb;
> ycbcr(:,:,3) = cr;
if you swap the order of these commands things will be slightly faster
because you don't have to resize 'ycbcr'.
Also, in the following part
> y = round((77*red + 150*grn + 29*blu)/256) + 16;
> cb = round((-44*red - 87*grn + 131*blu)/256) + 128;
> cr = round((131*red - 110*grn - 21*blu)/256) + 128;
Now, I can't remember my color conversions, but this looks wrong.
Shouldn't the translations [16, 128, 128] also be divided by 256?
Søren
More information about the Help-octave
mailing list