pkg load image imdata = imread('image.jpg'); R = imdata(:,:,1); G = imdata(:,:,2); B = imdata(:,:,3); R_int = int16(R); G_int = int16(G); B_int = int16(B); U_int = B_int - round(87*R_int/256.0 + 169*G_int/256.0); V_int = R_int - G_int; Y_int = G_int + round(86*V_int/256.0 + 29*U_int/256.0); U_int = U_int + 256; V_int = V_int + 256; fp = fopen('yuv_data/Y.dat','w'); fwrite(fp, Y_int, 'int16'); fclose(fp); fp = fopen('yuv_data/U.dat','w'); fwrite(fp, U_int, 'int16'); fclose(fp); fp = fopen('yuv_data/V.dat','w'); fwrite(fp, V_int, 'int16'); fclose(fp);