png_to_rgb.m 1.42 KB
clear all;
sequence=["CrowdRun","DucksTakeOff","OldTownCross","ParkJoy","ArenaOfValor","GlassHalf"];
resolution = {'2K','4K'};
QP=["1","2","3","4","5" ,"6"];

seq = sequence{2};
qp=QP{1};
resolution = resolution{1};
numFrame = 100;

Base_path="C:\Users\user\Documents\KHU\compressai\examples\\"+seq+"\\";
Target_folder =Base_path+"recon\\";
Save_folder = Base_path+"rgb\\";
%---- setting ----

for frame = 1:numFrame
%     targetFileName = Target_folder +"recon"+(frame-1)+"_q"+qp+".png";
    targetFileName = Target_folder +"recon"+(frame-1)+"_q"+qp+".png";
    RGB = imread(targetFileName);
    [height, width, color] = size(RGB);
    R = RGB(:,:,1);
    G = RGB(:,:,2);
    B = RGB(:,:,3);

    saveFileName = Save_folder + "recon"+(frame-1)+ ".rgb";
    fileID = fopen(saveFileName,'w');
    for j = 1:height
      fwrite(fileID,R(j,:)); 
    end
    for j = 1:height
      fwrite(fileID,G(j,:)); 
    end
    for j = 1:height
      fwrite(fileID,B(j,:)); 
    end
    fclose(fileID);    
end

size = 768 * 768 * 3;
% saveFileName = "C:\Users\user\Documents\KHU\Cap\compressai\examples\recon\\"+"recon"+"_q"+qp+ ".rgb";
saveFileName = "C:\Users\user\Documents\KHU\compressai\examples\recon\\"+seq+"_recon"+"_q"+qp+ ".rgb";
fout = fopen(saveFileName,'w');
for frame = 1:numFrame
    targetFileName = Save_folder +"recon"+(frame-1)+".rgb";
    RGB = fopen(targetFileName,'r');
    fin = fread(RGB,size);
    fclose(RGB);
    fwrite(fout, fin);
end