forked from zb12138/PointCloud-Octree-Compression-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.m
More file actions
64 lines (57 loc) · 1.69 KB
/
run.m
File metadata and controls
64 lines (57 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
clear
% Read file
filename = 'chair2851.ply';
quanfilePath = strcat(filename,'enc.ply');
binPath = strcat(filename,'bin');
p = pcread(filename);
pointNum = p.Count;
points = p.Location;
% Quantization
qs = 1;% qs must be integer
points = round((points - min(points))/qs);
pt = unique(points,'rows');
% Save file after quantization
if ~exist(quanfilePath,'file')
pcwrite(pointCloud(pt),quanfilePath);
end
fprintf('input file: %s\n',filename);
fprintf('quantized file Path: %s\n',quanfilePath);
fprintf('encoding points: %d\n',pointNum);
save('pathfile.mat','quanfilePath','filename','binPath');
% Generate octree
[code,Octree] = GenOctree(pt);
% Codes = dec2hex(code);
% disp(["codes:",Codes])
% dlmwrite(strcat(filename,'Octree.txt'),Codes,'delimiter','');
fprintf('bpp before entropy coding:%f bit\n',length(code)*8/pointNum);
% Entropy Coding
text = code;
binsize = entropyCoding(text,binPath);
fprintf('bpp after entropy coding:%f bit\n',binsize*8/pointNum);
fprintf('bin file: %s\n',binPath);
%% Decoding
% clear
disp('decoding...')
load('pathfile.mat')
disp(['binPath: ',binPath])
fileID = fopen(binPath);
lenthtext = fread(fileID,1,'uint32');
feqC = fread(fileID,255,'uint8');
bin = fread(fileID,'ubit1');
fclose(fileID);
% Entropy decoding
feq = double(feqC(feqC~=0));
dtext = arithdeco(bin,feq,lenthtext);
feqT = find(feqC);
dtext = feqT(dtext);
assert(isequal(dtext,text))
% Decode Octree
ptRec = qs*DeOctree(dtext);
% Evaluate
disp('evaluate...')
decodPath = strcat(filename,'dec.ply');
pcwrite(pointCloud(single(ptRec)),decodPath);
Cmd=['pc_error.exe' ,' -a ',quanfilePath ,' -b ',decodPath, ' -r ','1023']; %psnr = 10log10(3*p^2/max(mse)) e.g. p = 1023
system(Cmd);
%Show occupancy code
showOccupancyCode