diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/io')
28 files changed, 731 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/convert422.m b/SD-VBS/common/toolbox/toolbox_basic/io/convert422.m new file mode 100755 index 0000000..919e82e --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/convert422.m | |||
@@ -0,0 +1,27 @@ | |||
1 | image_current = '/hid/jshi'; | ||
2 | |||
3 | image_dir = 'vr05_5 '; | ||
4 | pg_path = '/hid/jshi/422toppm/422toppm'; | ||
5 | |||
6 | cm = sprintf('cd %s',image_dir); | ||
7 | disp(cm); | ||
8 | eval(cm); | ||
9 | |||
10 | d = dir('seq*'); | ||
11 | filename = char(sort({d.name})); | ||
12 | |||
13 | for j=1:size(filename), | ||
14 | cm = sprintf('!%s %s',pg_path,deblank(filename(j,:))); | ||
15 | disp(cm); | ||
16 | eval(cm); | ||
17 | end | ||
18 | |||
19 | |||
20 | %%% change back | ||
21 | cm = sprintf('cd %s',image_current); | ||
22 | disp(cm);eval(cm); | ||
23 | |||
24 | |||
25 | if 0, | ||
26 | deblank(filename(f,:)); | ||
27 | end | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m b/SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m new file mode 100755 index 0000000..590cd9b --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m | |||
@@ -0,0 +1,6 @@ | |||
1 | function J = im_vd(I); | ||
2 | |||
3 | J(:,:,1) = I(1:2:end,1:2:end); | ||
4 | J(:,:,2) = I(2:2:end,1:2:end); | ||
5 | |||
6 | montage2(J); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/imread2.m b/SD-VBS/common/toolbox/toolbox_basic/io/imread2.m new file mode 100755 index 0000000..27a5e4b --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/imread2.m | |||
@@ -0,0 +1,45 @@ | |||
1 | function I = imread2(fname,im_dir); | ||
2 | % | ||
3 | % I = imread2(fname,im_dir); | ||
4 | % | ||
5 | |||
6 | cur_dir = pwd; | ||
7 | |||
8 | if nargin>1, | ||
9 | cd(im_dir); | ||
10 | end | ||
11 | |||
12 | %%% put on the necessary extension | ||
13 | d = dir(fname); | ||
14 | |||
15 | if isempty(d), | ||
16 | d = dir([fname,'*']); | ||
17 | end | ||
18 | |||
19 | if isempty(d), | ||
20 | I = []; | ||
21 | else | ||
22 | |||
23 | fname = d.name; | ||
24 | |||
25 | %%% find extension | ||
26 | k = findstr(fname,'.'); | ||
27 | ext = fname(k(end)+1:end); | ||
28 | |||
29 | if (ext == 'bz2'), | ||
30 | cm = sprintf('!bzip2 -d %s',fname); | ||
31 | disp(cm);eval(cm); | ||
32 | I = imread2(fname(1:k(end-1)-1)); | ||
33 | cm = sprintf('!bzip2 %s',fname(1:k(end)-1)); | ||
34 | disp(cm);eval(cm); | ||
35 | elseif (ext == 'ppm'); | ||
36 | I = readppm(fname); | ||
37 | elseif (ext == 'pgm'); | ||
38 | I = readpgm(fname); | ||
39 | else | ||
40 | I = imread(fname); | ||
41 | I = double(I)/255; | ||
42 | end | ||
43 | end | ||
44 | |||
45 | cd(cur_dir); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m b/SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m new file mode 100755 index 0000000..13e54cd --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m | |||
@@ -0,0 +1,19 @@ | |||
1 | function [nr,nc] = peek_pgm_size(filename) | ||
2 | % function [nr,nc] = peek_pgm_size(filename) | ||
3 | % this is my version of pgmread for the pgm file created by XV. | ||
4 | % | ||
5 | % this program also corrects for the shifts in the image from pm file. | ||
6 | |||
7 | |||
8 | fid = fopen(filename,'r'); | ||
9 | fscanf(fid, 'P5\n'); | ||
10 | cmt = '#'; | ||
11 | while findstr(cmt, '#'), | ||
12 | cmt = fgets(fid); | ||
13 | if length(findstr(cmt, '#')) ~= 1, | ||
14 | YX = sscanf(cmt, '%d %d'); | ||
15 | nc = YX(1); nr = YX(2); | ||
16 | end | ||
17 | end | ||
18 | |||
19 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m b/SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m new file mode 100755 index 0000000..49a35a8 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m | |||
@@ -0,0 +1,24 @@ | |||
1 | function [img,header] = pgmread(filename) | ||
2 | % | ||
3 | % [img,header] = pgmread(filename) | ||
4 | |||
5 | [fid, msg] = fopen(filename, 'r'); | ||
6 | if fid == -1, | ||
7 | error(msg) | ||
8 | end | ||
9 | |||
10 | head = []; | ||
11 | good = 0; | ||
12 | while (good == 0) , | ||
13 | l = fgetl(fid); | ||
14 | if (length(l) == 3), | ||
15 | if (l == '255'), | ||
16 | good = 1; | ||
17 | sze = sscanf(header,'%d'); | ||
18 | end | ||
19 | end | ||
20 | header= l; | ||
21 | end | ||
22 | |||
23 | img = fread(fid, sze', 'uchar')'; | ||
24 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m b/SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m new file mode 100755 index 0000000..ce47e45 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m | |||
@@ -0,0 +1,25 @@ | |||
1 | function []= ppm2jpg(fname,dlm,ori) | ||
2 | % | ||
3 | % ppm2jpg(fname,dlm,ori) | ||
4 | % | ||
5 | % dlm =1, remove the file extension from fname | ||
6 | % before convert | ||
7 | % ori =1, transpose the image | ||
8 | % | ||
9 | |||
10 | if dlm, | ||
11 | dlm = findstr(fname,'.'); | ||
12 | fname = fname(1:dlm(end)-1); | ||
13 | end | ||
14 | |||
15 | fname_1 = sprintf('%s.ppm',fname); | ||
16 | I = readppm(fname_1); | ||
17 | |||
18 | if ori == 1, | ||
19 | I = permute(I,[2 1 3]); | ||
20 | end | ||
21 | |||
22 | |||
23 | fname_2 = sprintf('%s.jpg',fname); | ||
24 | imwrite(I,fname_2,'jpeg','Quality',90); | ||
25 | |||
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 @@ | |||
1 | function 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 | ||
9 | if nargin<2, | ||
10 | nc = 640; | ||
11 | end | ||
12 | |||
13 | %% find the image size | ||
14 | fid = fopen(fname); | ||
15 | fseek(fid,0,1); | ||
16 | fsize = ftell(fid); | ||
17 | |||
18 | nr = fsize/nc/2; | ||
19 | fseek(fid,0,-1); | ||
20 | |||
21 | %% read in Ybr data | ||
22 | data = fread(fid,fsize,'uchar'); | ||
23 | |||
24 | %%% extract Y, Cb, Cr | ||
25 | Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)'; | ||
26 | Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)'; | ||
27 | Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)'; | ||
28 | |||
29 | Cb = zeros(size(Y1)); | ||
30 | Cr = zeros(size(Y1)); | ||
31 | |||
32 | Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1; | ||
33 | %Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]); | ||
34 | |||
35 | Cr(:,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 | ||
39 | r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0); | ||
40 | g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0); | ||
41 | b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0); | ||
42 | |||
43 | I = cat(3,r,g,b); | ||
44 | I = max(0,min(I,255)); | ||
45 | I = I/255; | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read422f.m b/SD-VBS/common/toolbox/toolbox_basic/io/read422f.m new file mode 100755 index 0000000..0063000 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read422f.m | |||
@@ -0,0 +1,50 @@ | |||
1 | function 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 | ||
9 | if nargin<2, | ||
10 | nc = 640; | ||
11 | end | ||
12 | |||
13 | %% find the image size | ||
14 | fid = fopen(fname); | ||
15 | fseek(fid,0,1); | ||
16 | fsize = ftell(fid); | ||
17 | |||
18 | nr = fsize/nc/2; | ||
19 | |||
20 | fseek(fid,0,-1); | ||
21 | |||
22 | %% read in Ybr data | ||
23 | data = fread(fid,fsize,'uchar'); | ||
24 | |||
25 | %%% extract Y, Cb, Cr | ||
26 | Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)'; | ||
27 | Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)'; | ||
28 | Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)'; | ||
29 | |||
30 | Cb = zeros(size(Y1)); | ||
31 | Cr = zeros(size(Y1)); | ||
32 | |||
33 | Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1; | ||
34 | %Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]); | ||
35 | |||
36 | Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1; | ||
37 | %Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]); | ||
38 | |||
39 | %%% convert to r,g,b | ||
40 | r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0); | ||
41 | g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0); | ||
42 | b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0); | ||
43 | |||
44 | r = flipud(max(0,min(r,255))); | ||
45 | g = flipud(max(0,min(g,255))); | ||
46 | b = flipud(max(0,min(b,255))); | ||
47 | |||
48 | I = cat(3,r,g,b); | ||
49 | |||
50 | I = permute(I/255,[2,1,3]); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m new file mode 100755 index 0000000..d5df7f5 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m | |||
@@ -0,0 +1,40 @@ | |||
1 | function Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) | ||
2 | % | ||
3 | % Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) | ||
4 | % | ||
5 | |||
6 | |||
7 | |||
8 | command = ['%s%s%s%.',num2str(digits),'d%s']; | ||
9 | |||
10 | fname = sprintf(command,homedir,imgdir,prename,startid,postname); | ||
11 | disp(fname); | ||
12 | if (strcmp('.ppm',postname)), | ||
13 | I1 = readppm(fname); | ||
14 | else | ||
15 | I1 = imread(fname); | ||
16 | end | ||
17 | |||
18 | |||
19 | Is = zeros(size(I1,1),size(I1,2),size(I1,3),1+floor((endid-startid)/step_img)); | ||
20 | Is(:,:,:,1) = I1; | ||
21 | im_id = 1; | ||
22 | for j = startid+step_img:step_img:endid, | ||
23 | command = ['%s%s%s%.',num2str(digits),'d%s']; | ||
24 | fname = sprintf(command,homedir,imgdir,prename,j,postname); | ||
25 | disp(fname); | ||
26 | im_id = im_id+1; | ||
27 | |||
28 | if (strcmp('.ppm',postname)), | ||
29 | Is(:,:,:,im_id) = readppm(fname); | ||
30 | else | ||
31 | a = imread(fname); | ||
32 | Is(:,:,:,im_id) = a; | ||
33 | end | ||
34 | end | ||
35 | |||
36 | |||
37 | |||
38 | |||
39 | |||
40 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m new file mode 100755 index 0000000..3f7b69d --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m | |||
@@ -0,0 +1,26 @@ | |||
1 | function [evs,ev_info] = read_ev_pgm(basename,start_id,end_id,neigs) | ||
2 | % | ||
3 | % evs = read_ev_pgm(basename,start_id,end_id,neigs) | ||
4 | % | ||
5 | % | ||
6 | |||
7 | fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1) | ||
8 | [nr,nc] = peek_pgm_size(fname); | ||
9 | |||
10 | evs = zeros(nr,nc,neigs-1,start_id-end_id+1); | ||
11 | ev_info = zeros(4,neigs-1,start_id-end_id+1); | ||
12 | |||
13 | for j=start_id:end_id, | ||
14 | for k=1:neigs-1, | ||
15 | |||
16 | fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k); | ||
17 | [I,info] = readpgm_evinfo(fname); | ||
18 | |||
19 | if (length(info)<4) | ||
20 | info = [0;0;0;0]; | ||
21 | end | ||
22 | |||
23 | evs(:,:,k,j-start_id+1) = I; | ||
24 | ev_info(:,k,j-start_id+1) = info'; | ||
25 | end | ||
26 | end | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m new file mode 100755 index 0000000..b0cc3f9 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m | |||
@@ -0,0 +1,29 @@ | |||
1 | function [evs,ev_info] = read_ev_pgm2(basename,start_id,end_id,neigs) | ||
2 | % | ||
3 | % evs = read_ev_pgm(basename,start_id,end_id,neigs) | ||
4 | % | ||
5 | % read_ev_pgm.m modified by SXY in Feb. 2001. | ||
6 | % The first eigenvector is also included | ||
7 | |||
8 | fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1) | ||
9 | [nr,nc] = peek_pgm_size(fname); | ||
10 | |||
11 | evs = zeros(nr,nc,neigs,start_id-end_id+1); | ||
12 | ev_info = zeros(4,neigs,start_id-end_id+1); | ||
13 | |||
14 | for j=start_id:end_id, | ||
15 | |||
16 | for k=1:neigs, | ||
17 | |||
18 | fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k-1); | ||
19 | |||
20 | [I,info] = readpgm_evinfo(fname); | ||
21 | |||
22 | if (length(info)<4) | ||
23 | info = [0;0;0;0]; | ||
24 | end | ||
25 | |||
26 | evs(:,:,k,j-start_id+1) = I; | ||
27 | ev_info(:,k,j-start_id+1) = info'; | ||
28 | end | ||
29 | end | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m new file mode 100755 index 0000000..d985679 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m | |||
@@ -0,0 +1,30 @@ | |||
1 | function [evs,ev_info] = read_ev_pgm(basename,start_id,end_id,neigs) | ||
2 | % | ||
3 | % evs = read_ev_pgm(basename,start_id,end_id,neigs) | ||
4 | % | ||
5 | % | ||
6 | |||
7 | fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1); | ||
8 | [nr,nc] = peek_pgm_size(fname); | ||
9 | |||
10 | evs = zeros(nr,nc,neigs-1,start_id-end_id+1); | ||
11 | ev_info = zeros(4,neigs-1,start_id-end_id+1); | ||
12 | |||
13 | for j=start_id:end_id, | ||
14 | for k=1:neigs, | ||
15 | |||
16 | fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k-1); | ||
17 | [I,info] = readpgm_evinfo(fname); | ||
18 | |||
19 | evs(:,:,k,j-start_id+1) = I; | ||
20 | ev_info(:,k,j-start_id+1) = info'; | ||
21 | end | ||
22 | end | ||
23 | |||
24 | evs = squeeze(evs); | ||
25 | |||
26 | for j=1:neigs, | ||
27 | evs(:,:,j) = (evs(:,:,j)/ev_info(3,j)) +ev_info(1,j); | ||
28 | %evs(:,:,j) = evs(:,:,j)/norm(reshape(evs(:,:,j),nr*nc,1)); | ||
29 | end | ||
30 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m new file mode 100755 index 0000000..f84486c --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m | |||
@@ -0,0 +1,47 @@ | |||
1 | function Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) | ||
2 | % | ||
3 | % Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) | ||
4 | % | ||
5 | |||
6 | |||
7 | |||
8 | command = ['%s%s%s%.',num2str(digits),'d%s']; | ||
9 | |||
10 | fname = sprintf(command,homedir,imgdir,prename,startid,postname); | ||
11 | disp(fname); | ||
12 | if (strcmp('.pgm',postname)), | ||
13 | I1 = readpgm(fname); | ||
14 | elseif (strcmp('.ppm',postname)) | ||
15 | a = readppm(fname); | ||
16 | I1 = sum(a,3); | ||
17 | else | ||
18 | a = imread(fname); a = sum(double(a),3); | ||
19 | I1 = a; | ||
20 | end | ||
21 | |||
22 | |||
23 | Is = zeros(size(I1,1),size(I1,2),1+floor((endid-startid)/step_img)); | ||
24 | Is(:,:,1) = I1; | ||
25 | im_id = 1; | ||
26 | for j = startid+step_img:step_img:endid, | ||
27 | command = ['%s%s%s%.',num2str(digits),'d%s']; | ||
28 | fname = sprintf(command,homedir,imgdir,prename,j,postname); | ||
29 | disp(fname); | ||
30 | im_id = im_id+1; | ||
31 | |||
32 | if (strcmp('.pgm',postname)), | ||
33 | Is(:,:,im_id) = readpgm(fname); | ||
34 | elseif (strcmp('.ppm',postname)) | ||
35 | a = readppm(fname); | ||
36 | Is(:,:,im_id) = sum(a,3); | ||
37 | else | ||
38 | a = imread(fname); a = sum(double(a),3); | ||
39 | Is(:,:,im_id) = a; | ||
40 | end | ||
41 | end | ||
42 | |||
43 | |||
44 | |||
45 | |||
46 | |||
47 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m new file mode 100755 index 0000000..9e2eed1 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m | |||
@@ -0,0 +1,12 @@ | |||
1 | function I = read_pmm(fname) | ||
2 | |||
3 | fid = fopen(fname,'r'); | ||
4 | |||
5 | [A] = fscanf(fid,'%d\n',3); | ||
6 | |||
7 | I = fscanf(fid,'%d',prod(A)); | ||
8 | |||
9 | |||
10 | I = reshape(I,A(2),A(1))'; | ||
11 | |||
12 | I = squeeze(I); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m new file mode 100755 index 0000000..6ad818a --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m | |||
@@ -0,0 +1,42 @@ | |||
1 | function [img,sizeinfo] = pgmread(filename) | ||
2 | % function img = pgmread(filename) | ||
3 | % this is my version of pgmread for the pgm file created by XV. | ||
4 | % | ||
5 | % this program also corrects for the shifts in the image from pm file. | ||
6 | |||
7 | |||
8 | fname_header = sprintf('%s.h01',filename); | ||
9 | fname_data = sprintf('%s.i01',filename); | ||
10 | |||
11 | fid = fopen(fname_header,'r'); | ||
12 | |||
13 | |||
14 | done = 0; | ||
15 | while done~=3, | ||
16 | cmt = fgets(fid) | ||
17 | if (findstr(cmt,'!matrix size[1]')), | ||
18 | nc = sscanf(cmt,'!matrix size[1] :=%d'); | ||
19 | done = done+1; | ||
20 | elseif (findstr(cmt,'!matrix size[2]')), | ||
21 | nr = sscanf(cmt,'!matrix size[2] :=%d'); | ||
22 | done = done+1; | ||
23 | elseif (findstr(cmt,'!matrix size[3]')), | ||
24 | ns = sscanf(cmt,'!matrix size[3] :=%d'); | ||
25 | done = done+1; | ||
26 | end | ||
27 | end | ||
28 | fclose(fid); | ||
29 | |||
30 | fid = fopen(fname_data,'r'); | ||
31 | |||
32 | %img = fscanf(fid,'%d',size); | ||
33 | %img = img'; | ||
34 | |||
35 | img = fread(fid,nc*nr*ns,'uint8'); | ||
36 | img = reshape(img,nc,nr,ns); | ||
37 | |||
38 | sizeinfo(1) = nr; | ||
39 | sizeinfo(2) = nc; | ||
40 | sizeinfo(3) = ns; | ||
41 | |||
42 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m new file mode 100755 index 0000000..a056ebc --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m | |||
@@ -0,0 +1,36 @@ | |||
1 | function [seg_map,seg] = read_seg(filename) | ||
2 | % | ||
3 | % function seg = read_seg(filename) | ||
4 | % | ||
5 | |||
6 | fid = fopen(filename,'r'); | ||
7 | if (fid < 0), | ||
8 | error(sprintf('can not find file: %s',filename)); | ||
9 | end | ||
10 | |||
11 | header_done =0; | ||
12 | while ~header_done, | ||
13 | |||
14 | cmt = fgets(fid); | ||
15 | if length(findstr(cmt,'#')) ~=1, | ||
16 | header_done = 1; | ||
17 | cmt = fgets(fid); | ||
18 | nc = sscanf(cmt,'width %d\n'); | ||
19 | cmt = fgets(fid); | ||
20 | nr = sscanf(cmt,'height %d\n'); | ||
21 | cmt = fgets(fid); | ||
22 | mseg = sscanf(cmt,'segments %d\n'); | ||
23 | cmt = fgets(fid); | ||
24 | end | ||
25 | end | ||
26 | |||
27 | seg = fscanf(fid,'%d',100*nr); | ||
28 | tmp = length(seg(:))/4; | ||
29 | seg = reshape(seg,4,tmp)'; | ||
30 | |||
31 | seg_map = zeros(nr,nc); | ||
32 | |||
33 | for j=1:tmp, | ||
34 | seg_map(seg(j,2)+1,1+seg(j,3):1+seg(j,4)) = seg(j,1); | ||
35 | end | ||
36 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readlines.m b/SD-VBS/common/toolbox/toolbox_basic/io/readlines.m new file mode 100755 index 0000000..90bc944 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readlines.m | |||
@@ -0,0 +1,30 @@ | |||
1 | function [lines,indexes] = readlines(fname) | ||
2 | % | ||
3 | % [lines,indexes] = readlines(fname) | ||
4 | % Read Edges points from .Ins file produced by "getlines" | ||
5 | % lines: a num_pointsx2 matrix of the edge points | ||
6 | % indexes: the braking point the lines | ||
7 | % | ||
8 | |||
9 | fid = fopen(fname,'r'); | ||
10 | |||
11 | done = 0; | ||
12 | lines = []; | ||
13 | indexes = []; | ||
14 | |||
15 | first_line = fscanf(fid,'%s',1); | ||
16 | |||
17 | while (~done), | ||
18 | num_lines = sscanf(first_line(3:length(first_line)),'%d'); | ||
19 | disp(num_lines); | ||
20 | indexes = [indexes,num_lines]; | ||
21 | a = fscanf(fid,'%f',[2,num_lines]); | ||
22 | lines = [lines;a']; | ||
23 | |||
24 | first_line = fscanf(fid,'%s',1); | ||
25 | if (first_line == []), | ||
26 | done = 1; | ||
27 | end | ||
28 | end | ||
29 | |||
30 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m new file mode 100755 index 0000000..c21fc48 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m | |||
@@ -0,0 +1,16 @@ | |||
1 | function I = readpdm(filename) | ||
2 | |||
3 | fid = fopen(filename,'r'); | ||
4 | |||
5 | A = fscanf(fid,'%d',3) | ||
6 | A(3) = max(1,A(3)); | ||
7 | |||
8 | I = fscanf(fid,'%d',[A(1)*A(2)*A(3)]); | ||
9 | |||
10 | %I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); | ||
11 | |||
12 | I = reshape(I,A(2),A(1),A(3)); | ||
13 | |||
14 | I = permute(I,[2,1,3]); | ||
15 | |||
16 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m new file mode 100755 index 0000000..37910b9 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m | |||
@@ -0,0 +1,12 @@ | |||
1 | function I = readpfm(filename) | ||
2 | |||
3 | fid = fopen(filename,'r'); | ||
4 | |||
5 | A = fscanf(fid,'%d',2); | ||
6 | I = fscanf(fid,'%d',[A(2),A(1)]); | ||
7 | %I = fscanf(fid,'%d',[300,1000]); | ||
8 | I = I'; | ||
9 | |||
10 | %I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); | ||
11 | |||
12 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m new file mode 100755 index 0000000..48ecd78 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m | |||
@@ -0,0 +1,10 @@ | |||
1 | function I = readpfm(filename) | ||
2 | |||
3 | fid = fopen(filename,'r'); | ||
4 | |||
5 | A = fscanf(fid,'%d',2); | ||
6 | I = fscanf(fid,'%f',[A(1),A(2)]); | ||
7 | |||
8 | %I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); | ||
9 | |||
10 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m new file mode 100755 index 0000000..15ba959 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m | |||
@@ -0,0 +1,17 @@ | |||
1 | function I = readpfm(filename) | ||
2 | |||
3 | fid = fopen(filename,'r'); | ||
4 | |||
5 | A = fscanf(fid,'%d',3); | ||
6 | A(3) = max(1,A(3)); | ||
7 | |||
8 | I = fscanf(fid,'%f',[A(1)*A(2)*A(3)]); | ||
9 | |||
10 | %I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); | ||
11 | |||
12 | I = reshape(I,A(2),A(1),A(3)); | ||
13 | I = permute(I,[2,1,3]); | ||
14 | |||
15 | I = squeeze(I); | ||
16 | |||
17 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m new file mode 100755 index 0000000..2039002 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m | |||
@@ -0,0 +1,11 @@ | |||
1 | function I = readpfm(filename) | ||
2 | |||
3 | fid = fopen(filename,'r'); | ||
4 | |||
5 | A = fscanf(fid,'%d',2); | ||
6 | I = fscanf(fid,'%f',[A(2),A(1)]); | ||
7 | I = I'; | ||
8 | |||
9 | %I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); | ||
10 | |||
11 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m new file mode 100755 index 0000000..7aaf998 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m | |||
@@ -0,0 +1,30 @@ | |||
1 | function img = pgmread(filename) | ||
2 | % function img = pgmread(filename) | ||
3 | % this is my version of pgmread for the pgm file created by XV. | ||
4 | % | ||
5 | % this program also corrects for the shifts in the image from pm file. | ||
6 | |||
7 | |||
8 | fid = fopen(filename,'r'); | ||
9 | if (fid < 0), | ||
10 | error(sprintf('can not find file: %s',filename)); | ||
11 | end | ||
12 | |||
13 | fscanf(fid, 'P5\n'); | ||
14 | cmt = '#'; | ||
15 | while findstr(cmt, '#'), | ||
16 | cmt = fgets(fid); | ||
17 | if length(findstr(cmt, '#')) ~= 1, | ||
18 | YX = sscanf(cmt, '%d %d'); | ||
19 | y = YX(1); x = YX(2); | ||
20 | end | ||
21 | end | ||
22 | |||
23 | fgets(fid); | ||
24 | |||
25 | %img = fscanf(fid,'%d',size); | ||
26 | %img = img'; | ||
27 | |||
28 | img = fread(fid,[y,x],'uint8'); | ||
29 | img = img'; | ||
30 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m new file mode 100755 index 0000000..69f80ba --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m | |||
@@ -0,0 +1,35 @@ | |||
1 | function [img,ev_info] = pgmread_evinfo(filename) | ||
2 | % function img = pgmread(filename) | ||
3 | % this is my version of pgmread for the pgm file created by XV. | ||
4 | % | ||
5 | % return the information in line # | ||
6 | |||
7 | |||
8 | fid = fopen(filename,'r'); | ||
9 | |||
10 | if (fid <0), | ||
11 | error(sprintf('can not find file %s',filename)); | ||
12 | end | ||
13 | |||
14 | fscanf(fid, 'P5\n'); | ||
15 | cmt = '#'; | ||
16 | while findstr(cmt, '#'), | ||
17 | cmt = fgets(fid); | ||
18 | if findstr(cmt,'#'), | ||
19 | ev_info = sscanf(cmt,'# minv: %f, maxv: %f, scale: %f, eigval: %f'); | ||
20 | end | ||
21 | if length(findstr(cmt, '#')) ~= 1, | ||
22 | YX = sscanf(cmt, '%d %d'); | ||
23 | y = YX(1); x = YX(2); | ||
24 | end | ||
25 | end | ||
26 | |||
27 | fgets(fid); | ||
28 | |||
29 | %img = fscanf(fid,'%d',size); | ||
30 | %img = img'; | ||
31 | |||
32 | img = fread(fid,[y,x],'uint8'); | ||
33 | img = img'; | ||
34 | fclose(fid); | ||
35 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m new file mode 100755 index 0000000..88fe907 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m | |||
@@ -0,0 +1,22 @@ | |||
1 | function I=readpmm(name) | ||
2 | % | ||
3 | % I=writepmm(name) | ||
4 | % | ||
5 | % I is a mul-band image | ||
6 | % | ||
7 | fid = fopen(name,'r'); | ||
8 | |||
9 | if (fid <0), | ||
10 | error(sprintf('can not find file %s',name)); | ||
11 | end | ||
12 | |||
13 | a = fscanf(fid,'%d',3); | ||
14 | nr = a(1);nc = a(2);nb = a(3); | ||
15 | |||
16 | |||
17 | I = fscanf(fid, '%f\n', nr*nc*nb); | ||
18 | |||
19 | I = reshape(I,nc,nr,nb)'; | ||
20 | I = squeeze(I); | ||
21 | |||
22 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readppm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readppm.m new file mode 100755 index 0000000..b9dd566 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/readppm.m | |||
@@ -0,0 +1,23 @@ | |||
1 | function [I,r, g, b] = readppm(name) | ||
2 | |||
3 | fid = fopen(name, 'r'); | ||
4 | fscanf(fid, 'P6\n'); | ||
5 | cmt = '#'; | ||
6 | while findstr(cmt, '#'), | ||
7 | cmt = fgets(fid); | ||
8 | if length(findstr(cmt, '#')) ~= 1 | ||
9 | YX = sscanf(cmt, '%d %d'); | ||
10 | y = YX(1); x = YX(2); | ||
11 | end | ||
12 | end | ||
13 | fgets(fid); | ||
14 | packed = fread(fid,[3*y,x],'uint8')'; | ||
15 | r = packed(:,1:3:3*y); | ||
16 | g = packed(:,2:3:3*y); | ||
17 | b = packed(:,3:3:3*y); | ||
18 | fclose(fid); | ||
19 | |||
20 | I(:,:,1) = r; | ||
21 | I(:,:,2) = g; | ||
22 | I(:,:,3) = b; | ||
23 | I = I/255; | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m b/SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m new file mode 100755 index 0000000..113cb18 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m | |||
@@ -0,0 +1,8 @@ | |||
1 | function I = writepgm(name,I) | ||
2 | |||
3 | [y,x] = size(I); | ||
4 | |||
5 | fid = fopen(name, 'w'); | ||
6 | fprintf(fid, 'P5\n%d %d\n255\n', x,y); | ||
7 | fwrite(fid, I', 'uint8'); | ||
8 | fclose(fid); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m b/SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m new file mode 100755 index 0000000..3d2fed1 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m | |||
@@ -0,0 +1,14 @@ | |||
1 | function writeppm(name,I) | ||
2 | |||
3 | [y,x,nb] = size(I); | ||
4 | |||
5 | fid = fopen(name, 'w'); | ||
6 | fprintf(fid, 'P6\n%d %d\n255\n', x,y); | ||
7 | |||
8 | I1 = reshape(I(:,:,1)',1,x*y); | ||
9 | I2 = reshape(I(:,:,2)',1,x*y); | ||
10 | I3 = reshape(I(:,:,3)',1,x*y); | ||
11 | |||
12 | fwrite(fid, [I1;I2;I3], 'uint8'); | ||
13 | fclose(fid); | ||
14 | |||