help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:


From: soren
Subject: Re:
Date: Mon, 04 Aug 2008 09:16:20 +0200
User-agent: Internet Messaging Program (IMP) H3 (4.2-RC2)

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 <address@hidden>:
    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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]