All pastes #280348 Raw Edit

Stuff

public text v1 · immutable
·published 2006-12-15 21:09 UTC
rendered paste body
for y=1:size(I_rgb, 1)
    for x=1:size(I_rgb, 2)
               
        %RGB to XYZ
        I_XYZ(y,x,1:3) = rgb2XYZ * [I_rgb(y,x,1); I_rgb(y,x,2); I_rgb(y,x,3)];
        
        
        %XYZ to u' v'
        if (I_XYZ(y,x,1) == 0 && I_XYZ(y,x,2) == 0 && I_XYZ(y,x,3) == 0)
            I_uv(y,x,1)=0; I_uv(y,x,2)=0;
        else
            I_uv(y,x,1) = 4*I_XYZ(y,x,1) / (I_XYZ(y,x,1) + 15*I_XYZ(y,x,2) +3*I_XYZ(y,x,3)); % calculating u'
            I_uv(y,x,2) = 9*I_XYZ(y,x,2) / (I_XYZ(y,x,1) + 15*I_XYZ(y,x,2) +3*I_XYZ(y,x,3)); % calculating v'
        end
        
        
        %STUFF
            
        %u' v' to XYZ
        if (I_uv(y,x,2) == 0)
            I_XYZ(y,x,1) = 0; I_XYZ(y,x,3) = 0;
        else
            I_XYZ(y,x,1) = -9*I_XYZ(y,x,2)*I_uv(y,x,1) / ((I_uv(y,x,1)-4)*I_uv(y,x,2)-I_uv(y,x,1)*I_uv(y,x,2));
            I_XYZ(y,x,3) = (9*I_XYZ(y,x,2) - 15*I_uv(y,x,2)*I_XYZ(y,x,1) - I_uv(y,x,2)) / (3*I_uv(y,x,2));
        end
        
        %XYZ to RGB
        I_rgb(y,x,1:3) = XYZ2rgb * [I_XYZ(y,x,1); I_XYZ(y,x,2); I_XYZ(y,x,3)];

    end
end


u' = 4X / (X + 15Y + 3Z)
v' = 9Y / (X + 15Y + 3Z)

X = - 9Yu' / (( u' - 4 ) v' - u'v' )
Z = ( 9Y - 15v'Y - v'X ) / 3v'