Created
November 11, 2019 14:00
-
-
Save mcarletti/38789efb2d6adf610c39c4b490175b58 to your computer and use it in GitHub Desktop.
RGB-YUV color conversion (Matlab code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [Y,U,V] = cvtRGB2YUV(R,G,B) | |
R = double(R); | |
G = double(G); | |
B = double(B); | |
Y = 0.257 * R + 0.504 * G + 0.098 * B + 16; | |
U = -0.148 * R - 0.291 * G + 0.439 * B + 128; | |
V = 0.439 * R - 0.368 * G - 0.071 * B + 128; | |
Y = uint8(Y); | |
U = uint8(U); | |
V = uint8(V); | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [R,G,B] = cvtYUV2RGB(Y,U,V) | |
Y = double(Y) - 16; | |
U = double(U) - 128; | |
V = double(V) - 128; | |
R = 1.164 * Y + 1.596 * V; | |
G = 1.164 * Y - 0.392 * U - 0.813 * V; | |
B = 1.164 * Y + 2.017 * U; | |
R = uint8(R); | |
G = uint8(G); | |
B = uint8(B); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment