summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/io
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/io')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/convert422.m27
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/im_vd.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/imread2.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/pgmread.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read422.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read422f.m50
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_scan.m42
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readlines.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpfm.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpgm.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m35
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpmm.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readppm.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/writepgm.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/writeppm.m14
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 @@
1image_current = '/hid/jshi';
2
3image_dir = 'vr05_5 ';
4pg_path = '/hid/jshi/422toppm/422toppm';
5
6cm = sprintf('cd %s',image_dir);
7disp(cm);
8eval(cm);
9
10d = dir('seq*');
11filename = char(sort({d.name}));
12
13for j=1:size(filename),
14 cm = sprintf('!%s %s',pg_path,deblank(filename(j,:)));
15disp(cm);
16eval(cm);
17end
18
19
20%%% change back
21cm = sprintf('cd %s',image_current);
22disp(cm);eval(cm);
23
24
25if 0,
26 deblank(filename(f,:));
27end
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 @@
1function J = im_vd(I);
2
3J(:,:,1) = I(1:2:end,1:2:end);
4J(:,:,2) = I(2:2:end,1:2:end);
5
6montage2(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 @@
1function I = imread2(fname,im_dir);
2%
3% I = imread2(fname,im_dir);
4%
5
6cur_dir = pwd;
7
8if nargin>1,
9 cd(im_dir);
10end
11
12%%% put on the necessary extension
13d = dir(fname);
14
15if isempty(d),
16 d = dir([fname,'*']);
17end
18
19if isempty(d),
20 I = [];
21else
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);
41I = double(I)/255;
42 end
43end
44
45cd(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 @@
1function [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
8fid = fopen(filename,'r');
9fscanf(fid, 'P5\n');
10cmt = '#';
11while 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
17end
18
19fclose(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 @@
1function [img,header] = pgmread(filename)
2%
3% [img,header] = pgmread(filename)
4
5[fid, msg] = fopen(filename, 'r');
6if fid == -1,
7 error(msg)
8end
9
10head = [];
11good = 0;
12while (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;
21end
22
23img = fread(fid, sze', 'uchar')';
24fclose(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 @@
1function []= 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
10if dlm,
11 dlm = findstr(fname,'.');
12 fname = fname(1:dlm(end)-1);
13end
14
15fname_1 = sprintf('%s.ppm',fname);
16I = readppm(fname_1);
17
18if ori == 1,
19 I = permute(I,[2 1 3]);
20end
21
22
23fname_2 = sprintf('%s.jpg',fname);
24imwrite(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 @@
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;
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 @@
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;
19
20fseek(fid,0,-1);
21
22%% read in Ybr data
23data = fread(fid,fsize,'uchar');
24
25%%% extract Y, Cb, Cr
26Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)';
27Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)';
28Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)';
29
30Cb = zeros(size(Y1));
31Cr = zeros(size(Y1));
32
33Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1;
34%Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]);
35
36Cr(:,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
40r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0);
41g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0);
42b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0);
43
44r = flipud(max(0,min(r,255)));
45g = flipud(max(0,min(g,255)));
46b = flipud(max(0,min(b,255)));
47
48I = cat(3,r,g,b);
49
50I = 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 @@
1function 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
8command = ['%s%s%s%.',num2str(digits),'d%s'];
9
10fname = sprintf(command,homedir,imgdir,prename,startid,postname);
11disp(fname);
12if (strcmp('.ppm',postname)),
13 I1 = readppm(fname);
14else
15 I1 = imread(fname);
16end
17
18
19Is = zeros(size(I1,1),size(I1,2),size(I1,3),1+floor((endid-startid)/step_img));
20Is(:,:,:,1) = I1;
21im_id = 1;
22for 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
34end
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 @@
1function [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
7fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1)
8[nr,nc] = peek_pgm_size(fname);
9
10evs = zeros(nr,nc,neigs-1,start_id-end_id+1);
11ev_info = zeros(4,neigs-1,start_id-end_id+1);
12
13for 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
26end
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 @@
1function [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
8fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1)
9[nr,nc] = peek_pgm_size(fname);
10
11evs = zeros(nr,nc,neigs,start_id-end_id+1);
12ev_info = zeros(4,neigs,start_id-end_id+1);
13
14for 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
29end
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 @@
1function [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
7fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1);
8[nr,nc] = peek_pgm_size(fname);
9
10evs = zeros(nr,nc,neigs-1,start_id-end_id+1);
11ev_info = zeros(4,neigs-1,start_id-end_id+1);
12
13for 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
22end
23
24evs = squeeze(evs);
25
26for 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));
29end
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 @@
1function 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
8command = ['%s%s%s%.',num2str(digits),'d%s'];
9
10fname = sprintf(command,homedir,imgdir,prename,startid,postname);
11disp(fname);
12if (strcmp('.pgm',postname)),
13 I1 = readpgm(fname);
14elseif (strcmp('.ppm',postname))
15 a = readppm(fname);
16 I1 = sum(a,3);
17else
18 a = imread(fname); a = sum(double(a),3);
19 I1 = a;
20end
21
22
23Is = zeros(size(I1,1),size(I1,2),1+floor((endid-startid)/step_img));
24Is(:,:,1) = I1;
25im_id = 1;
26for 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
41end
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 @@
1function I = read_pmm(fname)
2
3fid = fopen(fname,'r');
4
5[A] = fscanf(fid,'%d\n',3);
6
7I = fscanf(fid,'%d',prod(A));
8
9
10I = reshape(I,A(2),A(1))';
11
12I = 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 @@
1function [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
8fname_header = sprintf('%s.h01',filename);
9fname_data = sprintf('%s.i01',filename);
10
11fid = fopen(fname_header,'r');
12
13
14done = 0;
15while 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
27end
28fclose(fid);
29
30fid = fopen(fname_data,'r');
31
32%img = fscanf(fid,'%d',size);
33%img = img';
34
35img = fread(fid,nc*nr*ns,'uint8');
36img = reshape(img,nc,nr,ns);
37
38sizeinfo(1) = nr;
39sizeinfo(2) = nc;
40sizeinfo(3) = ns;
41
42fclose(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 @@
1function [seg_map,seg] = read_seg(filename)
2%
3% function seg = read_seg(filename)
4%
5
6fid = fopen(filename,'r');
7if (fid < 0),
8 error(sprintf('can not find file: %s',filename));
9end
10
11header_done =0;
12while ~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
25end
26
27seg = fscanf(fid,'%d',100*nr);
28tmp = length(seg(:))/4;
29seg = reshape(seg,4,tmp)';
30
31seg_map = zeros(nr,nc);
32
33for j=1:tmp,
34 seg_map(seg(j,2)+1,1+seg(j,3):1+seg(j,4)) = seg(j,1);
35end
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 @@
1function [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
9fid = fopen(fname,'r');
10
11done = 0;
12lines = [];
13indexes = [];
14
15first_line = fscanf(fid,'%s',1);
16
17while (~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
28end
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 @@
1function I = readpdm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',3)
6A(3) = max(1,A(3));
7
8I = 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
12I = reshape(I,A(2),A(1),A(3));
13
14I = permute(I,[2,1,3]);
15
16fclose(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 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%d',[A(2),A(1)]);
7%I = fscanf(fid,'%d',[300,1000]);
8I = I';
9
10%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
11
12fclose(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 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = 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
10fclose(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 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',3);
6A(3) = max(1,A(3));
7
8I = 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
12I = reshape(I,A(2),A(1),A(3));
13I = permute(I,[2,1,3]);
14
15I = squeeze(I);
16
17fclose(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 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%f',[A(2),A(1)]);
7I = I';
8
9%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
10
11fclose(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 @@
1function 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
8fid = fopen(filename,'r');
9if (fid < 0),
10 error(sprintf('can not find file: %s',filename));
11end
12
13fscanf(fid, 'P5\n');
14cmt = '#';
15while 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
21end
22
23fgets(fid);
24
25%img = fscanf(fid,'%d',size);
26%img = img';
27
28img = fread(fid,[y,x],'uint8');
29img = img';
30fclose(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 @@
1function [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
8fid = fopen(filename,'r');
9
10if (fid <0),
11 error(sprintf('can not find file %s',filename));
12end
13
14fscanf(fid, 'P5\n');
15cmt = '#';
16while 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
25end
26
27fgets(fid);
28
29%img = fscanf(fid,'%d',size);
30%img = img';
31
32img = fread(fid,[y,x],'uint8');
33img = img';
34fclose(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 @@
1function 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 @@
1function [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 @@
1function 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 @@
1function 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