From f618466c25d43f3bae9e40920273bf77de1e1149 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Mon, 19 Oct 2020 23:09:30 -0400 Subject: initial sd-vbs initial sd-vbs add sd-vbs sd-vbs --- .../common/toolbox/toolbox_basic/io/convert422.m | 27 ++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m | 6 +++ SD-VBS/common/toolbox/toolbox_basic/io/imread2.m | 45 +++++++++++++++++++ .../toolbox/toolbox_basic/io/peek_pgm_size.m | 19 ++++++++ SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m | 24 +++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m | 25 +++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/read422.m | 45 +++++++++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/read422f.m | 50 ++++++++++++++++++++++ .../common/toolbox/toolbox_basic/io/read_cimgs.m | 40 +++++++++++++++++ .../common/toolbox/toolbox_basic/io/read_ev_pgm.m | 26 +++++++++++ .../common/toolbox/toolbox_basic/io/read_ev_pgm2.m | 29 +++++++++++++ .../toolbox/toolbox_basic/io/read_ev_pgm_real.m | 30 +++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m | 47 ++++++++++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m | 12 ++++++ SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m | 42 ++++++++++++++++++ .../toolbox/toolbox_basic/io/read_seg_file.m | 36 ++++++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/readlines.m | 30 +++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m | 16 +++++++ SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m | 12 ++++++ SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m | 10 +++++ SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m | 17 ++++++++ SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m | 11 +++++ SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m | 30 +++++++++++++ .../toolbox/toolbox_basic/io/readpgm_evinfo.m | 35 +++++++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m | 22 ++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/readppm.m | 23 ++++++++++ SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m | 8 ++++ SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m | 14 ++++++ 28 files changed, 731 insertions(+) create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/convert422.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/imread2.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read422.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read422f.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readlines.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/readppm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m create mode 100755 SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m (limited to 'SD-VBS/common/toolbox/toolbox_basic/io') 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 @@ +image_current = '/hid/jshi'; + +image_dir = 'vr05_5 '; +pg_path = '/hid/jshi/422toppm/422toppm'; + +cm = sprintf('cd %s',image_dir); +disp(cm); +eval(cm); + +d = dir('seq*'); +filename = char(sort({d.name})); + +for j=1:size(filename), + cm = sprintf('!%s %s',pg_path,deblank(filename(j,:))); +disp(cm); +eval(cm); +end + + +%%% change back +cm = sprintf('cd %s',image_current); +disp(cm);eval(cm); + + +if 0, + deblank(filename(f,:)); +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 @@ +function J = im_vd(I); + +J(:,:,1) = I(1:2:end,1:2:end); +J(:,:,2) = I(2:2:end,1:2:end); + +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 @@ +function I = imread2(fname,im_dir); +% +% I = imread2(fname,im_dir); +% + +cur_dir = pwd; + +if nargin>1, + cd(im_dir); +end + +%%% put on the necessary extension +d = dir(fname); + +if isempty(d), + d = dir([fname,'*']); +end + +if isempty(d), + I = []; +else + + fname = d.name; + + %%% find extension + k = findstr(fname,'.'); + ext = fname(k(end)+1:end); + + if (ext == 'bz2'), + cm = sprintf('!bzip2 -d %s',fname); + disp(cm);eval(cm); + I = imread2(fname(1:k(end-1)-1)); + cm = sprintf('!bzip2 %s',fname(1:k(end)-1)); + disp(cm);eval(cm); + elseif (ext == 'ppm'); + I = readppm(fname); + elseif (ext == 'pgm'); + I = readpgm(fname); + else + I = imread(fname); +I = double(I)/255; + end +end + +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 @@ +function [nr,nc] = peek_pgm_size(filename) +% function [nr,nc] = peek_pgm_size(filename) +% this is my version of pgmread for the pgm file created by XV. +% +% this program also corrects for the shifts in the image from pm file. + + +fid = fopen(filename,'r'); +fscanf(fid, 'P5\n'); +cmt = '#'; +while findstr(cmt, '#'), + cmt = fgets(fid); + if length(findstr(cmt, '#')) ~= 1, + YX = sscanf(cmt, '%d %d'); + nc = YX(1); nr = YX(2); + end +end + +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 @@ +function [img,header] = pgmread(filename) +% +% [img,header] = pgmread(filename) + +[fid, msg] = fopen(filename, 'r'); +if fid == -1, + error(msg) +end + +head = []; +good = 0; +while (good == 0) , + l = fgetl(fid); + if (length(l) == 3), + if (l == '255'), + good = 1; + sze = sscanf(header,'%d'); + end + end + header= l; +end + +img = fread(fid, sze', 'uchar')'; +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 @@ +function []= ppm2jpg(fname,dlm,ori) +% +% ppm2jpg(fname,dlm,ori) +% +% dlm =1, remove the file extension from fname +% before convert +% ori =1, transpose the image +% + +if dlm, + dlm = findstr(fname,'.'); + fname = fname(1:dlm(end)-1); +end + +fname_1 = sprintf('%s.ppm',fname); +I = readppm(fname_1); + +if ori == 1, + I = permute(I,[2 1 3]); +end + + +fname_2 = sprintf('%s.jpg',fname); +imwrite(I,fname_2,'jpeg','Quality',90); + 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 @@ +function I = read422(fname,nc); +% +% I = read422(fname,width); +% +% read in a .422 file, need to pass image width, default = 640 +% + +% assume image width = 640 +if nargin<2, + nc = 640; +end + +%% find the image size +fid = fopen(fname); +fseek(fid,0,1); +fsize = ftell(fid); + +nr = fsize/nc/2; +fseek(fid,0,-1); + +%% read in Ybr data +data = fread(fid,fsize,'uchar'); + +%%% extract Y, Cb, Cr +Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)'; +Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)'; +Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)'; + +Cb = zeros(size(Y1)); +Cr = zeros(size(Y1)); + +Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1; +%Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]); + +Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1; +%Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]); + +%%% convert to r,g,b +r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0); +g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0); +b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0); + +I = cat(3,r,g,b); +I = max(0,min(I,255)); +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 @@ +function I = read422(fname,nc); +% +% I = read422(fname,width); +% +% read in a .422 file, need to pass image width, default = 640 +% + +% assume image width = 640 +if nargin<2, + nc = 640; +end + +%% find the image size +fid = fopen(fname); +fseek(fid,0,1); +fsize = ftell(fid); + +nr = fsize/nc/2; + +fseek(fid,0,-1); + +%% read in Ybr data +data = fread(fid,fsize,'uchar'); + +%%% extract Y, Cb, Cr +Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)'; +Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)'; +Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)'; + +Cb = zeros(size(Y1)); +Cr = zeros(size(Y1)); + +Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1; +%Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]); + +Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1; +%Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]); + +%%% convert to r,g,b +r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0); +g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0); +b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0); + +r = flipud(max(0,min(r,255))); +g = flipud(max(0,min(g,255))); +b = flipud(max(0,min(b,255))); + +I = cat(3,r,g,b); + +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 @@ +function Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) +% +% Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) +% + + + +command = ['%s%s%s%.',num2str(digits),'d%s']; + +fname = sprintf(command,homedir,imgdir,prename,startid,postname); +disp(fname); +if (strcmp('.ppm',postname)), + I1 = readppm(fname); +else + I1 = imread(fname); +end + + +Is = zeros(size(I1,1),size(I1,2),size(I1,3),1+floor((endid-startid)/step_img)); +Is(:,:,:,1) = I1; +im_id = 1; +for j = startid+step_img:step_img:endid, + command = ['%s%s%s%.',num2str(digits),'d%s']; + fname = sprintf(command,homedir,imgdir,prename,j,postname); + disp(fname); + im_id = im_id+1; + + if (strcmp('.ppm',postname)), + Is(:,:,:,im_id) = readppm(fname); + else + a = imread(fname); + Is(:,:,:,im_id) = a; + end +end + + + + + + 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 @@ +function [evs,ev_info] = read_ev_pgm(basename,start_id,end_id,neigs) +% +% evs = read_ev_pgm(basename,start_id,end_id,neigs) +% +% + +fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1) +[nr,nc] = peek_pgm_size(fname); + +evs = zeros(nr,nc,neigs-1,start_id-end_id+1); +ev_info = zeros(4,neigs-1,start_id-end_id+1); + +for j=start_id:end_id, + for k=1:neigs-1, + + fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k); + [I,info] = readpgm_evinfo(fname); + + if (length(info)<4) + info = [0;0;0;0]; + end + + evs(:,:,k,j-start_id+1) = I; + ev_info(:,k,j-start_id+1) = info'; + end +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 @@ +function [evs,ev_info] = read_ev_pgm2(basename,start_id,end_id,neigs) +% +% evs = read_ev_pgm(basename,start_id,end_id,neigs) +% +% read_ev_pgm.m modified by SXY in Feb. 2001. +% The first eigenvector is also included + +fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1) +[nr,nc] = peek_pgm_size(fname); + +evs = zeros(nr,nc,neigs,start_id-end_id+1); +ev_info = zeros(4,neigs,start_id-end_id+1); + +for j=start_id:end_id, + + for k=1:neigs, + + fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k-1); + + [I,info] = readpgm_evinfo(fname); + + if (length(info)<4) + info = [0;0;0;0]; + end + + evs(:,:,k,j-start_id+1) = I; + ev_info(:,k,j-start_id+1) = info'; + end +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 @@ +function [evs,ev_info] = read_ev_pgm(basename,start_id,end_id,neigs) +% +% evs = read_ev_pgm(basename,start_id,end_id,neigs) +% +% + +fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1); +[nr,nc] = peek_pgm_size(fname); + +evs = zeros(nr,nc,neigs-1,start_id-end_id+1); +ev_info = zeros(4,neigs-1,start_id-end_id+1); + +for j=start_id:end_id, + for k=1:neigs, + + fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k-1); + [I,info] = readpgm_evinfo(fname); + + evs(:,:,k,j-start_id+1) = I; + ev_info(:,k,j-start_id+1) = info'; + end +end + +evs = squeeze(evs); + +for j=1:neigs, + evs(:,:,j) = (evs(:,:,j)/ev_info(3,j)) +ev_info(1,j); + %evs(:,:,j) = evs(:,:,j)/norm(reshape(evs(:,:,j),nr*nc,1)); +end + 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 @@ +function Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) +% +% Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img) +% + + + +command = ['%s%s%s%.',num2str(digits),'d%s']; + +fname = sprintf(command,homedir,imgdir,prename,startid,postname); +disp(fname); +if (strcmp('.pgm',postname)), + I1 = readpgm(fname); +elseif (strcmp('.ppm',postname)) + a = readppm(fname); + I1 = sum(a,3); +else + a = imread(fname); a = sum(double(a),3); + I1 = a; +end + + +Is = zeros(size(I1,1),size(I1,2),1+floor((endid-startid)/step_img)); +Is(:,:,1) = I1; +im_id = 1; +for j = startid+step_img:step_img:endid, + command = ['%s%s%s%.',num2str(digits),'d%s']; + fname = sprintf(command,homedir,imgdir,prename,j,postname); + disp(fname); + im_id = im_id+1; + + if (strcmp('.pgm',postname)), + Is(:,:,im_id) = readpgm(fname); + elseif (strcmp('.ppm',postname)) + a = readppm(fname); + Is(:,:,im_id) = sum(a,3); + else + a = imread(fname); a = sum(double(a),3); + Is(:,:,im_id) = a; + end +end + + + + + + 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 @@ +function I = read_pmm(fname) + +fid = fopen(fname,'r'); + +[A] = fscanf(fid,'%d\n',3); + +I = fscanf(fid,'%d',prod(A)); + + +I = reshape(I,A(2),A(1))'; + +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 @@ +function [img,sizeinfo] = pgmread(filename) +% function img = pgmread(filename) +% this is my version of pgmread for the pgm file created by XV. +% +% this program also corrects for the shifts in the image from pm file. + + +fname_header = sprintf('%s.h01',filename); +fname_data = sprintf('%s.i01',filename); + +fid = fopen(fname_header,'r'); + + +done = 0; +while done~=3, + cmt = fgets(fid) + if (findstr(cmt,'!matrix size[1]')), + nc = sscanf(cmt,'!matrix size[1] :=%d'); + done = done+1; + elseif (findstr(cmt,'!matrix size[2]')), + nr = sscanf(cmt,'!matrix size[2] :=%d'); + done = done+1; + elseif (findstr(cmt,'!matrix size[3]')), + ns = sscanf(cmt,'!matrix size[3] :=%d'); + done = done+1; + end +end +fclose(fid); + +fid = fopen(fname_data,'r'); + +%img = fscanf(fid,'%d',size); +%img = img'; + +img = fread(fid,nc*nr*ns,'uint8'); +img = reshape(img,nc,nr,ns); + +sizeinfo(1) = nr; +sizeinfo(2) = nc; +sizeinfo(3) = ns; + +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 @@ +function [seg_map,seg] = read_seg(filename) +% +% function seg = read_seg(filename) +% + +fid = fopen(filename,'r'); +if (fid < 0), + error(sprintf('can not find file: %s',filename)); +end + +header_done =0; +while ~header_done, + + cmt = fgets(fid); + if length(findstr(cmt,'#')) ~=1, + header_done = 1; + cmt = fgets(fid); + nc = sscanf(cmt,'width %d\n'); + cmt = fgets(fid); + nr = sscanf(cmt,'height %d\n'); + cmt = fgets(fid); + mseg = sscanf(cmt,'segments %d\n'); + cmt = fgets(fid); + end +end + +seg = fscanf(fid,'%d',100*nr); +tmp = length(seg(:))/4; +seg = reshape(seg,4,tmp)'; + +seg_map = zeros(nr,nc); + +for j=1:tmp, + seg_map(seg(j,2)+1,1+seg(j,3):1+seg(j,4)) = seg(j,1); +end + 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 @@ +function [lines,indexes] = readlines(fname) +% +% [lines,indexes] = readlines(fname) +% Read Edges points from .Ins file produced by "getlines" +% lines: a num_pointsx2 matrix of the edge points +% indexes: the braking point the lines +% + +fid = fopen(fname,'r'); + +done = 0; +lines = []; +indexes = []; + +first_line = fscanf(fid,'%s',1); + +while (~done), + num_lines = sscanf(first_line(3:length(first_line)),'%d'); + disp(num_lines); + indexes = [indexes,num_lines]; + a = fscanf(fid,'%f',[2,num_lines]); + lines = [lines;a']; + + first_line = fscanf(fid,'%s',1); + if (first_line == []), + done = 1; + end +end + + 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 @@ +function I = readpdm(filename) + +fid = fopen(filename,'r'); + +A = fscanf(fid,'%d',3) +A(3) = max(1,A(3)); + +I = fscanf(fid,'%d',[A(1)*A(2)*A(3)]); + +%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); + +I = reshape(I,A(2),A(1),A(3)); + +I = permute(I,[2,1,3]); + +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 @@ +function I = readpfm(filename) + +fid = fopen(filename,'r'); + +A = fscanf(fid,'%d',2); +I = fscanf(fid,'%d',[A(2),A(1)]); +%I = fscanf(fid,'%d',[300,1000]); +I = I'; + +%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); + +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 @@ +function I = readpfm(filename) + +fid = fopen(filename,'r'); + +A = fscanf(fid,'%d',2); +I = fscanf(fid,'%f',[A(1),A(2)]); + +%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); + +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 @@ +function I = readpfm(filename) + +fid = fopen(filename,'r'); + +A = fscanf(fid,'%d',3); +A(3) = max(1,A(3)); + +I = fscanf(fid,'%f',[A(1)*A(2)*A(3)]); + +%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); + +I = reshape(I,A(2),A(1),A(3)); +I = permute(I,[2,1,3]); + +I = squeeze(I); + +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 @@ +function I = readpfm(filename) + +fid = fopen(filename,'r'); + +A = fscanf(fid,'%d',2); +I = fscanf(fid,'%f',[A(2),A(1)]); +I = I'; + +%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2)); + +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 @@ +function img = pgmread(filename) +% function img = pgmread(filename) +% this is my version of pgmread for the pgm file created by XV. +% +% this program also corrects for the shifts in the image from pm file. + + +fid = fopen(filename,'r'); +if (fid < 0), + error(sprintf('can not find file: %s',filename)); +end + +fscanf(fid, 'P5\n'); +cmt = '#'; +while findstr(cmt, '#'), + cmt = fgets(fid); + if length(findstr(cmt, '#')) ~= 1, + YX = sscanf(cmt, '%d %d'); + y = YX(1); x = YX(2); + end +end + +fgets(fid); + +%img = fscanf(fid,'%d',size); +%img = img'; + +img = fread(fid,[y,x],'uint8'); +img = img'; +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 @@ +function [img,ev_info] = pgmread_evinfo(filename) +% function img = pgmread(filename) +% this is my version of pgmread for the pgm file created by XV. +% +% return the information in line # + + +fid = fopen(filename,'r'); + +if (fid <0), + error(sprintf('can not find file %s',filename)); +end + +fscanf(fid, 'P5\n'); +cmt = '#'; +while findstr(cmt, '#'), + cmt = fgets(fid); + if findstr(cmt,'#'), + ev_info = sscanf(cmt,'# minv: %f, maxv: %f, scale: %f, eigval: %f'); + end + if length(findstr(cmt, '#')) ~= 1, + YX = sscanf(cmt, '%d %d'); + y = YX(1); x = YX(2); + end +end + +fgets(fid); + +%img = fscanf(fid,'%d',size); +%img = img'; + +img = fread(fid,[y,x],'uint8'); +img = img'; +fclose(fid); + 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 @@ +function I=readpmm(name) +% +% I=writepmm(name) +% +% I is a mul-band image +% + fid = fopen(name,'r'); + + if (fid <0), + error(sprintf('can not find file %s',name)); + end + + a = fscanf(fid,'%d',3); + nr = a(1);nc = a(2);nb = a(3); + + + I = fscanf(fid, '%f\n', nr*nc*nb); + + I = reshape(I,nc,nr,nb)'; + I = squeeze(I); + + 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 @@ +function [I,r, g, b] = readppm(name) + + fid = fopen(name, 'r'); + fscanf(fid, 'P6\n'); + cmt = '#'; + while findstr(cmt, '#'), + cmt = fgets(fid); + if length(findstr(cmt, '#')) ~= 1 + YX = sscanf(cmt, '%d %d'); + y = YX(1); x = YX(2); + end + end + fgets(fid); + packed = fread(fid,[3*y,x],'uint8')'; + r = packed(:,1:3:3*y); + g = packed(:,2:3:3*y); + b = packed(:,3:3:3*y); + fclose(fid); + + I(:,:,1) = r; + I(:,:,2) = g; + I(:,:,3) = b; + 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 @@ +function I = writepgm(name,I) + + [y,x] = size(I); + + fid = fopen(name, 'w'); + fprintf(fid, 'P5\n%d %d\n255\n', x,y); + fwrite(fid, I', 'uint8'); + 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 @@ +function writeppm(name,I) + + [y,x,nb] = size(I); + + fid = fopen(name, 'w'); + fprintf(fid, 'P6\n%d %d\n255\n', x,y); + + I1 = reshape(I(:,:,1)',1,x*y); + I2 = reshape(I(:,:,2)',1,x*y); + I3 = reshape(I(:,:,3)',1,x*y); + + fwrite(fid, [I1;I2;I3], 'uint8'); + fclose(fid); + -- cgit v1.2.2