choiseungmi

update preprocessing and postprocessing code

clear all
sequence = ["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444", "OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444", "ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
resolution = {'2K','4K'};
QP = {'qp22', 'qp27', 'qp32', 'qp37'};
seq = sequence{1};
qp = QP{1};
Input_File = "dec_"+seq+"_"+qp+".rgb";
Output_8bit = "dec_"+seq+"_"+qp+"_GBR8.rgb";
Output_RGB = "dec_"+seq+"_"+qp+"_RGB8.rgb";
Input_File_Origin="C:\Users\user\Desktop\HM-16.8\input\\"+seq+".rgb";
BPP_path="C:\Users\user\Desktop\HM-16.8\output\encoder\\"+seq+"_"+qp+".log";
numFrame = 3;
channel=3;
width = 768;
height = 768;
%------------- setting -------------
finID = fopen(Input_File,'r');
fileSize = width * height * channel * numFrame;
%Data10 = uint16(zeros(fileSize,1));
Data10 = fread(finID,[fileSize,1],'uint16=>uint16'); % From the 10 bit(2byte) input file, read it by 2bytes(uint16)
% whos Data10
fclose(finID);
Data8 = uint8((Data10+2) ./ 4);
% whos Data8
foutID = fopen(Output_8bit,'w'); % Save the 8bit(1byte) variable Data8 to the output file
fwrite(foutID, Data8);
fclose(foutID);
%------------- 10bit to 8bit -------------
fileID = fopen(Output_8bit,'r');
fileID_ori = fopen(Input_File_Origin,'r');
fout = fopen(Output_RGB,'w');
total_R_PSNR = 0;
total_G_PSNR = 0;
total_B_PSNR = 0;
for frame = 1:numFrame
G = uint8(zeros(height,width));
B = uint8(zeros(height,width));
R = uint8(zeros(height,width));
R_Original = uint8(zeros(height,width));
G_Original =uint8(zeros(height,width));
B_Original = uint8(zeros(height,width));
for j = 1:height
G(:,j) = fread(fileID,width);
end
for j = 1:height
B(:,j) = fread(fileID,width);
end
for j = 1:height
R(:,j) = fread(fileID,width);
end
for j = 1:height
R_Original(:,j) = fread(fileID_ori,width);
end
for j = 1:height
G_Original(:,j) = fread(fileID_ori,width);
end
for j = 1:height
B_Original(:,j) = fread(fileID_ori,width);
end
R_Original=im2double(R_Original);
G_Original=im2double(G_Original);
B_Original=im2double(B_Original);
R_Test=im2double(R);
G_Test=im2double(G);
B_Test=im2double(B);
R_ssimval = ssim(R_Test,R_Original);
G_ssimval = ssim(G_Test,G_Original);
B_ssimval = ssim(B_Test,B_Original);
%R channel PSNR
R_sse = 0; % sum of squared error
for i = 1:height
for j = 1:width
d = abs(R_Original(i,j) - R_Test(i,j));
R_sse = R_sse + (d^2);
end
end
R_mse = R_sse / (height*width); % mean square error
A=max(max(R_Original(:)), max( R_Test(:)));
% R_psnr = 20 * log10(255) - 10 * log10(R_mse); % PSNR
R_psnr = - 10 * log10(R_mse); % PSNR
total_R_PSNR = total_R_PSNR + R_psnr;
%G channel PSNR
G_sse = 0; % sum of squared error
for i = 1:height
for j = 1:width
d = abs(G_Original(i,j) - G_Test(i,j));
G_sse = G_sse + (d^2);
end
end
G_mse = G_sse / (height*width); % mean square error
G_psnr = - 10 * log10(G_mse); % PSNR
total_G_PSNR = total_G_PSNR + G_psnr;
%B channel PSNR
B_sse = 0; % sum of squared error
for i = 1:height
for j = 1:width
d = abs(B_Original(i,j) - B_Test(i,j));
B_sse = B_sse + (d^2);
end
end
B_mse = B_sse / (height*width); % mean square error
B_psnr = - 10 * log10(B_mse); % PSNR
total_B_PSNR = total_B_PSNR + B_psnr;
fwrite(fout, R);
fwrite(fout, G);
fwrite(fout, B);
end
fclose(fileID);
fclose(fileID_ori);
fclose(fout);
m_R_PSNR = total_R_PSNR / numFrame;
m_G_PSNR = total_G_PSNR / numFrame;
m_B_PSNR = total_B_PSNR / numFrame;
total = (m_R_PSNR + m_G_PSNR + m_B_PSNR) / 3;
total_ssim=(R_ssimval+G_ssimval+B_ssimval)/3;
fprintf("PSNR: \n%f\n\n", total);
fprintf("SSIM: \n%f\n\n", total_ssim);
BPP=get_BPP(BPP_path, width, height, channel, numFrame);
fprintf("BPP: \n%f\n\n", BPP);
function result=get_BPP(path, width, height, channel, numFrame)
Target_File = path;
fileId=fopen(Target_File);
fseek(fileId, -200, 'eof');
C=textscan(fileId, '%s');
B=flip(C{1});
A = B{7};
A = str2double(A);
result = A *8 / (width*height*channel*numFrame);
fclose(fileId);
end
No preview for this file type
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\Cap\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 +"v1_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\Cap\compressai\examples\recon\\"+"v1_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
\ No newline at end of file
clear all;
sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
"OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
"ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
Cfg=["CrowdRun_RGB_8bit","DucksTakeOff_RGB_16bit",
"OldTownCross_RGB_8bit","ParkJoy_RGB_8bit",
"ArenaOfValor_RGB","GlassHalf_RGB_8bit"];
QP=["22","27","32","37"];
fr="60";
f="120";
i=3;
seq=sequence{i};
cfg=Cfg{i};
for j=1:4
qp=QP{j};
enc="EncoderApp.exe -c encoder_randomaccess_vtm.cfg -c "+cfg+".cfg -i input\\"+seq+".rgb -b output\\decoder\\str_"+seq+"_qp"+qp+".bin -q "+qp+" -fr "+fr+" -f "+f+" --ReconFile=output\\decoder\\rec_"+seq+"_qp"+qp+".bin -fs 0 > output\\encoder\\"+seq+"_qp"+qp+".log";
dec="DecoderApp.exe -b output\\decoder\\str_"+seq+"_qp"+qp+".bin -o output\\decoder\\"+seq+"_qp"+qp+".rgb > output\\decoder\\"+seq+"_qp"+qp+".log";
fprintf(enc,"\n");
fprintf("\n\n");
fprintf(dec,"\n");
fprintf("\n\n");
end
\ No newline at end of file
No preview for this file type
clear all
numFrame = 1;
width = 768;
height = 768;
sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
"OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
"ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
for i=1:6
seq=sequence{i};
% Target_folder = "ArenaOfValor_1920x1080_60_8bit_444.rgb";
Target_folder=seq+"_frame0.rgb";
Save_folder = "output";
%---- setting ----
fileID = fopen(Target_folder,'r');
R8 = uint8(zeros(height,width));
G8 = uint8(zeros(height,width));
B8 = uint8(zeros(height,width));
for j = 1:height
R8(j,:) = fread(fileID,width);
end
for j = 1:height
G8(j,:) = fread(fileID,width);
end
for j = 1:height
B8(j,:) = fread(fileID,width);
end
fclose(fileID);
RGB(:,:,1) = im2double(R8);
RGB(:,:,2) = im2double(G8);
RGB(:,:,3) = im2double(B8);
saveFileName = seq + "_frame0.png";
imwrite(RGB,saveFileName);
end
\ No newline at end of file
clear all;
width = 768;
height = 768;
channel = 3;
numFrame = 50;
bitDepth=8;
imageSize=width*height*channel;
sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
"OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
"ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
sequence=sequence{6};
Target_folder = sequence+".rgb";
% Target_folder="output2.rgb";
Save_folder = "output";
% ---- setting ----
finID = fopen(Target_folder,'r');
for frame = 1:1
% 해당 frame의 data 읽어오기
% if (bitDepth >= 9) && (bitDepth <= 16)
% Data = fread(finID,[imageSize,1],'uint16=>uint16');
% else
Data = fread(finID,[imageSize,1],'uint8=>uint8');
% end
% Data=Data(768, 768,:);
foutID = fopen(sequence+"_frame0"+".rgb",'w');
% 해당 frame의 data를 출력 파일에 쓰기
fwrite(foutID, Data);
fclose(foutID);
end
fclose(finID);
clear all
numFrame = 48;
width = 768;
height = 768;
sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
"OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
"ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
for i=6:6
seq=sequence{i};
% Target_folder = "ArenaOfValor_1920x1080_60_8bit_444.rgb";
Target_folder=seq+".rgb";
%---- setting ----
fileID = fopen(Target_folder,'r');
for f = 1:numFrame
R8 = uint8(zeros(height,width));
G8 = uint8(zeros(height,width));
B8 = uint8(zeros(height,width));
for j = 1:height
R8(j,:) = fread(fileID,width);
end
for j = 1:height
G8(j,:) = fread(fileID,width);
end
for j = 1:height
B8(j,:) = fread(fileID,width);
end
RGB(:,:,1) = im2double(R8);
RGB(:,:,2) = im2double(G8);
RGB(:,:,3) = im2double(B8);
saveFileName = "GlassHalf\\"+seq + "_frame"+(f-1)+".png";
imwrite(RGB,saveFileName);
end
fclose(fileID);
end
\ No newline at end of file