choiseungmi

update preprocessing and postprocessing code

1 +clear all
2 +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"];
3 +
4 +resolution = {'2K','4K'};
5 +QP = {'qp22', 'qp27', 'qp32', 'qp37'};
6 +seq = sequence{1};
7 +qp = QP{1};
8 +
9 +Input_File = "dec_"+seq+"_"+qp+".rgb";
10 +Output_8bit = "dec_"+seq+"_"+qp+"_GBR8.rgb";
11 +Output_RGB = "dec_"+seq+"_"+qp+"_RGB8.rgb";
12 +Input_File_Origin="C:\Users\user\Desktop\HM-16.8\input\\"+seq+".rgb";
13 +
14 +BPP_path="C:\Users\user\Desktop\HM-16.8\output\encoder\\"+seq+"_"+qp+".log";
15 +
16 +numFrame = 3;
17 +channel=3;
18 +width = 768;
19 +height = 768;
20 +
21 +%------------- setting -------------
22 +
23 +finID = fopen(Input_File,'r');
24 +fileSize = width * height * channel * numFrame;
25 +%Data10 = uint16(zeros(fileSize,1));
26 +Data10 = fread(finID,[fileSize,1],'uint16=>uint16'); % From the 10 bit(2byte) input file, read it by 2bytes(uint16)
27 +% whos Data10
28 +fclose(finID);
29 +Data8 = uint8((Data10+2) ./ 4);
30 +% whos Data8
31 +foutID = fopen(Output_8bit,'w'); % Save the 8bit(1byte) variable Data8 to the output file
32 +fwrite(foutID, Data8);
33 +fclose(foutID);
34 +%------------- 10bit to 8bit -------------
35 +
36 +fileID = fopen(Output_8bit,'r');
37 +fileID_ori = fopen(Input_File_Origin,'r');
38 +fout = fopen(Output_RGB,'w');
39 +
40 +total_R_PSNR = 0;
41 +total_G_PSNR = 0;
42 +total_B_PSNR = 0;
43 +
44 +for frame = 1:numFrame
45 + G = uint8(zeros(height,width));
46 + B = uint8(zeros(height,width));
47 + R = uint8(zeros(height,width));
48 +
49 + R_Original = uint8(zeros(height,width));
50 + G_Original =uint8(zeros(height,width));
51 + B_Original = uint8(zeros(height,width));
52 +
53 + for j = 1:height
54 + G(:,j) = fread(fileID,width);
55 + end
56 + for j = 1:height
57 + B(:,j) = fread(fileID,width);
58 + end
59 + for j = 1:height
60 + R(:,j) = fread(fileID,width);
61 + end
62 +
63 + for j = 1:height
64 + R_Original(:,j) = fread(fileID_ori,width);
65 + end
66 + for j = 1:height
67 + G_Original(:,j) = fread(fileID_ori,width);
68 + end
69 + for j = 1:height
70 + B_Original(:,j) = fread(fileID_ori,width);
71 + end
72 +
73 + R_Original=im2double(R_Original);
74 + G_Original=im2double(G_Original);
75 + B_Original=im2double(B_Original);
76 + R_Test=im2double(R);
77 + G_Test=im2double(G);
78 + B_Test=im2double(B);
79 +
80 + R_ssimval = ssim(R_Test,R_Original);
81 + G_ssimval = ssim(G_Test,G_Original);
82 + B_ssimval = ssim(B_Test,B_Original);
83 +
84 + %R channel PSNR
85 + R_sse = 0; % sum of squared error
86 + for i = 1:height
87 + for j = 1:width
88 + d = abs(R_Original(i,j) - R_Test(i,j));
89 + R_sse = R_sse + (d^2);
90 + end
91 + end
92 + R_mse = R_sse / (height*width); % mean square error
93 + A=max(max(R_Original(:)), max( R_Test(:)));
94 +% R_psnr = 20 * log10(255) - 10 * log10(R_mse); % PSNR
95 + R_psnr = - 10 * log10(R_mse); % PSNR
96 + total_R_PSNR = total_R_PSNR + R_psnr;
97 +
98 + %G channel PSNR
99 + G_sse = 0; % sum of squared error
100 + for i = 1:height
101 + for j = 1:width
102 + d = abs(G_Original(i,j) - G_Test(i,j));
103 + G_sse = G_sse + (d^2);
104 + end
105 + end
106 + G_mse = G_sse / (height*width); % mean square error
107 + G_psnr = - 10 * log10(G_mse); % PSNR
108 + total_G_PSNR = total_G_PSNR + G_psnr;
109 +
110 + %B channel PSNR
111 + B_sse = 0; % sum of squared error
112 + for i = 1:height
113 + for j = 1:width
114 + d = abs(B_Original(i,j) - B_Test(i,j));
115 + B_sse = B_sse + (d^2);
116 + end
117 + end
118 + B_mse = B_sse / (height*width); % mean square error
119 + B_psnr = - 10 * log10(B_mse); % PSNR
120 + total_B_PSNR = total_B_PSNR + B_psnr;
121 +
122 + fwrite(fout, R);
123 + fwrite(fout, G);
124 + fwrite(fout, B);
125 +
126 +end
127 +fclose(fileID);
128 +fclose(fileID_ori);
129 +fclose(fout);
130 +
131 +m_R_PSNR = total_R_PSNR / numFrame;
132 +m_G_PSNR = total_G_PSNR / numFrame;
133 +m_B_PSNR = total_B_PSNR / numFrame;
134 +total = (m_R_PSNR + m_G_PSNR + m_B_PSNR) / 3;
135 +total_ssim=(R_ssimval+G_ssimval+B_ssimval)/3;
136 +fprintf("PSNR: \n%f\n\n", total);
137 +fprintf("SSIM: \n%f\n\n", total_ssim);
138 +
139 +BPP=get_BPP(BPP_path, width, height, channel, numFrame);
140 +fprintf("BPP: \n%f\n\n", BPP);
1 +function result=get_BPP(path, width, height, channel, numFrame)
2 +
3 + Target_File = path;
4 +
5 + fileId=fopen(Target_File);
6 + fseek(fileId, -200, 'eof');
7 + C=textscan(fileId, '%s');
8 +
9 + B=flip(C{1});
10 + A = B{7};
11 + A = str2double(A);
12 + result = A *8 / (width*height*channel*numFrame);
13 +
14 + fclose(fileId);
15 +end
No preview for this file type
1 +clear all;
2 +sequence=["CrowdRun","DucksTakeOff","OldTownCross","ParkJoy","ArenaOfValor","GlassHalf"];
3 +resolution = {'2K','4K'};
4 +QP=["1","2","3","4","5" ,"6"];
5 +
6 +seq = sequence{2};
7 +qp=QP{1};
8 +resolution = resolution{1};
9 +numFrame = 100;
10 +
11 +Base_path="C:\Users\user\Documents\KHU\Cap\compressai\examples\\"+seq+"\\";
12 +Target_folder =Base_path+"recon\\";
13 +Save_folder = Base_path+"rgb\\";
14 +%---- setting ----
15 +
16 +for frame = 1:numFrame
17 +% targetFileName = Target_folder +"recon"+(frame-1)+"_q"+qp+".png";
18 + targetFileName = Target_folder +"v1_recon"+(frame-1)+"_q"+qp+".png";
19 + RGB = imread(targetFileName);
20 + [height, width, color] = size(RGB);
21 + R = RGB(:,:,1);
22 + G = RGB(:,:,2);
23 + B = RGB(:,:,3);
24 +
25 + saveFileName = Save_folder + "recon"+(frame-1)+ ".rgb";
26 + fileID = fopen(saveFileName,'w');
27 + for j = 1:height
28 + fwrite(fileID,R(j,:));
29 + end
30 + for j = 1:height
31 + fwrite(fileID,G(j,:));
32 + end
33 + for j = 1:height
34 + fwrite(fileID,B(j,:));
35 + end
36 + fclose(fileID);
37 +end
38 +
39 +size = 768 * 768 * 3;
40 +% saveFileName = "C:\Users\user\Documents\KHU\Cap\compressai\examples\recon\\"+"recon"+"_q"+qp+ ".rgb";
41 +saveFileName = "C:\Users\user\Documents\KHU\Cap\compressai\examples\recon\\"+"v1_recon"+"_q"+qp+ ".rgb";
42 +fout = fopen(saveFileName,'w');
43 +for frame = 1:numFrame
44 + targetFileName = Save_folder +"recon"+(frame-1)+".rgb";
45 + RGB = fopen(targetFileName,'r');
46 + fin = fread(RGB,size);
47 + fclose(RGB);
48 + fwrite(fout, fin);
49 +end
...\ No newline at end of file ...\ No newline at end of file
1 +clear all;
2 +
3 +sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
4 + "OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
5 + "ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
6 +Cfg=["CrowdRun_RGB_8bit","DucksTakeOff_RGB_16bit",
7 + "OldTownCross_RGB_8bit","ParkJoy_RGB_8bit",
8 + "ArenaOfValor_RGB","GlassHalf_RGB_8bit"];
9 +QP=["22","27","32","37"];
10 +fr="60";
11 +f="120";
12 +i=3;
13 +seq=sequence{i};
14 +cfg=Cfg{i};
15 +for j=1:4
16 + qp=QP{j};
17 +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";
18 +
19 +dec="DecoderApp.exe -b output\\decoder\\str_"+seq+"_qp"+qp+".bin -o output\\decoder\\"+seq+"_qp"+qp+".rgb > output\\decoder\\"+seq+"_qp"+qp+".log";
20 +fprintf(enc,"\n");
21 +fprintf("\n\n");
22 +fprintf(dec,"\n");
23 +fprintf("\n\n");
24 +end
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
1 +clear all
2 +
3 +numFrame = 1;
4 +width = 768;
5 +height = 768;
6 +sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
7 + "OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
8 + "ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
9 +for i=1:6
10 + seq=sequence{i};
11 + % Target_folder = "ArenaOfValor_1920x1080_60_8bit_444.rgb";
12 + Target_folder=seq+"_frame0.rgb";
13 + Save_folder = "output";
14 + %---- setting ----
15 +
16 + fileID = fopen(Target_folder,'r');
17 +
18 + R8 = uint8(zeros(height,width));
19 + G8 = uint8(zeros(height,width));
20 + B8 = uint8(zeros(height,width));
21 +
22 + for j = 1:height
23 + R8(j,:) = fread(fileID,width);
24 + end
25 + for j = 1:height
26 + G8(j,:) = fread(fileID,width);
27 + end
28 + for j = 1:height
29 + B8(j,:) = fread(fileID,width);
30 + end
31 + fclose(fileID);
32 +
33 + RGB(:,:,1) = im2double(R8);
34 + RGB(:,:,2) = im2double(G8);
35 + RGB(:,:,3) = im2double(B8);
36 + saveFileName = seq + "_frame0.png";
37 + imwrite(RGB,saveFileName);
38 +end
...\ No newline at end of file ...\ No newline at end of file
1 +clear all;
2 +
3 +width = 768;
4 +height = 768;
5 +channel = 3;
6 +numFrame = 50;
7 +bitDepth=8;
8 +imageSize=width*height*channel;
9 +sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
10 + "OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
11 + "ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
12 +
13 +sequence=sequence{6};
14 +Target_folder = sequence+".rgb";
15 +% Target_folder="output2.rgb";
16 +Save_folder = "output";
17 +% ---- setting ----
18 +finID = fopen(Target_folder,'r');
19 +for frame = 1:1
20 + % 해당 frame의 data 읽어오기
21 +% if (bitDepth >= 9) && (bitDepth <= 16)
22 +% Data = fread(finID,[imageSize,1],'uint16=>uint16');
23 +% else
24 + Data = fread(finID,[imageSize,1],'uint8=>uint8');
25 +% end
26 +
27 +% Data=Data(768, 768,:);
28 + foutID = fopen(sequence+"_frame0"+".rgb",'w');
29 +
30 + % 해당 frame의 data를 출력 파일에 쓰기
31 + fwrite(foutID, Data);
32 + fclose(foutID);
33 +
34 +end
35 +fclose(finID);
1 +clear all
2 +
3 +numFrame = 48;
4 +width = 768;
5 +height = 768;
6 +sequence=["CrowdRun_768x768_50_8bit_444","DucksTakeOff_768x768_50_8bit_444",
7 + "OldTownCross_768x768_50_8bit_444","ParkJoy_768x768_50_8bit_444",
8 + "ArenaOfValor_768x768_60_8bit_444","GlassHalf_768x768_24_8bit_444"];
9 +for i=6:6
10 + seq=sequence{i};
11 + % Target_folder = "ArenaOfValor_1920x1080_60_8bit_444.rgb";
12 + Target_folder=seq+".rgb";
13 + %---- setting ----
14 +
15 + fileID = fopen(Target_folder,'r');
16 + for f = 1:numFrame
17 + R8 = uint8(zeros(height,width));
18 + G8 = uint8(zeros(height,width));
19 + B8 = uint8(zeros(height,width));
20 +
21 + for j = 1:height
22 + R8(j,:) = fread(fileID,width);
23 + end
24 + for j = 1:height
25 + G8(j,:) = fread(fileID,width);
26 + end
27 + for j = 1:height
28 + B8(j,:) = fread(fileID,width);
29 + end
30 +
31 +
32 + RGB(:,:,1) = im2double(R8);
33 + RGB(:,:,2) = im2double(G8);
34 + RGB(:,:,3) = im2double(B8);
35 + saveFileName = "GlassHalf\\"+seq + "_frame"+(f-1)+".png";
36 + imwrite(RGB,saveFileName);
37 + end
38 + fclose(fileID);
39 +
40 +end
...\ No newline at end of file ...\ No newline at end of file