summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/io/read422.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/io/read422.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read422.m45
1 files changed, 45 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read422.m b/SD-VBS/common/toolbox/toolbox_basic/io/read422.m
new file mode 100755
index 0000000..31a27f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read422.m
@@ -0,0 +1,45 @@
1function I = read422(fname,nc);
2%
3% I = read422(fname,width);
4%
5% read in a .422 file, need to pass image width, default = 640
6%
7
8% assume image width = 640
9if nargin<2,
10 nc = 640;
11end
12
13%% find the image size
14fid = fopen(fname);
15fseek(fid,0,1);
16fsize = ftell(fid);
17
18nr = fsize/nc/2;
19fseek(fid,0,-1);
20
21%% read in Ybr data
22data = fread(fid,fsize,'uchar');
23
24%%% extract Y, Cb, Cr
25Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)';
26Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)';
27Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)';
28
29Cb = zeros(size(Y1));
30Cr = zeros(size(Y1));
31
32Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1;
33%Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]);
34
35Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1;
36%Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]);
37
38%%% convert to r,g,b
39r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0);
40g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0);
41b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0);
42
43I = cat(3,r,g,b);
44I = max(0,min(I,255));
45I = I/255;