/
loadFileYUV.m
92 lines (80 loc) · 3.21 KB
/
loadFileYUV.m
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
% loadFileYUV(width,height,Frame_Number,File,fheight,fwidth)
function YUV = loadFileYUV(width,heigth,Frame,fileName,Teil_h,Teil_b)
% get size of U and V
fileId = fopen(fileName,'r');
width_h = width*Teil_b;
heigth_h = heigth*Teil_h;
% compute factor for framesize
factor = 1+(Teil_h*Teil_b)*2;
% compute framesize
framesize = width*heigth;
fseek(fileId,(Frame-1)*factor*framesize, 'bof');
% create Y-Matrix
YMatrix = fread(fileId, width * heigth, 'uchar');
YMatrix = int16(reshape(YMatrix,width,heigth)');
% create U- and V- Matrix
if Teil_h == 0
UMatrix = 0;
VMatrix = 0;
else
UMatrix = fread(fileId,width_h * heigth_h, 'uchar');
UMatrix = int16(UMatrix);
UMatrix = reshape(UMatrix,width_h, heigth_h).';
VMatrix = fread(fileId,width_h * heigth_h, 'uchar');
VMatrix = int16(VMatrix);
VMatrix = reshape(VMatrix,width_h, heigth_h).';
end
% compose the YUV-matrix:
YUV(1:heigth,1:width,1) = YMatrix;
if Teil_h == 0
YUV(:,:,2) = 127;
YUV(:,:,3) = 127;
end
% consideration of the subsampling of U and V
if Teil_b == 1
UMatrix1(:,:) = UMatrix(:,:);
VMatrix1(:,:) = VMatrix(:,:);
elseif Teil_b == 0.5
UMatrix1(1:heigth_h,1:width) = int16(0);
UMatrix1(1:heigth_h,1:2:end) = UMatrix(:,1:1:end);
UMatrix1(1:heigth_h,2:2:end) = UMatrix(:,1:1:end);
VMatrix1(1:heigth_h,1:width) = int16(0);
VMatrix1(1:heigth_h,1:2:end) = VMatrix(:,1:1:end);
VMatrix1(1:heigth_h,2:2:end) = VMatrix(:,1:1:end);
elseif Teil_b == 0.25
UMatrix1(1:heigth_h,1:width) = int16(0);
UMatrix1(1:heigth_h,1:4:end) = UMatrix(:,1:1:end);
UMatrix1(1:heigth_h,2:4:end) = UMatrix(:,1:1:end);
UMatrix1(1:heigth_h,3:4:end) = UMatrix(:,1:1:end);
UMatrix1(1:heigth_h,4:4:end) = UMatrix(:,1:1:end);
VMatrix1(1:heigth_h,1:width) = int16(0);
VMatrix1(1:heigth_h,1:4:end) = VMatrix(:,1:1:end);
VMatrix1(1:heigth_h,2:4:end) = VMatrix(:,1:1:end);
VMatrix1(1:heigth_h,3:4:end) = VMatrix(:,1:1:end);
VMatrix1(1:heigth_h,4:4:end) = VMatrix(:,1:1:end);
end
if Teil_h == 1
YUV(:,:,2) = UMatrix1(:,:);
YUV(:,:,3) = VMatrix1(:,:);
elseif Teil_h == 0.5
YUV(1:heigth,1:width,2) = int16(0);
YUV(1:2:end,:,2) = UMatrix1(:,:);
YUV(2:2:end,:,2) = UMatrix1(:,:);
YUV(1:heigth,1:width,3) = int16(0);
YUV(1:2:end,:,3) = VMatrix1(:,:);
YUV(2:2:end,:,3) = VMatrix1(:,:);
elseif Teil_h == 0.25
YUV(1:heigth,1:width,2) = int16(0);
YUV(1:4:end,:,2) = UMatrix1(:,:);
YUV(2:4:end,:,2) = UMatrix1(:,:);
YUV(3:4:end,:,2) = UMatrix1(:,:);
YUV(4:4:end,:,2) = UMatrix1(:,:);
YUV(1:heigth,1:width) = int16(0);
YUV(1:4:end,:,3) = VMatrix1(:,:);
YUV(2:4:end,:,3) = VMatrix1(:,:);
YUV(3:4:end,:,3) = VMatrix1(:,:);
YUV(4:4:end,:,3) = VMatrix1(:,:);
end
YUV = uint8(YUV);
fclose(fileId);
end