summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m94
1 files changed, 94 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
new file mode 100755
index 0000000..d0f11cb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
@@ -0,0 +1,94 @@
1% function [par, rec_num] = jshincut(par,image_dir)
2% Input:
3% par = a structure with parameters for command_ncut.tex
4% image_dir = the directory where the imagefile is stored
5% Output:
6% par = parameters used
7% rec_num = record number in the NCut database
8% Jianbo Shi's ncut_IC is applied to the image
9% (If there is no .ppm format for the named image,
10% conversion from related files would be attempted.)
11% Results are organized according to the parameters.
12% Example: jshincut('240018s');
13% See also: jshincutdefpar; ncutcheckin
14% Set IS_PC according to your platform in globalenvar.m
15
16% Stella X. Yu, 2000.
17
18function [par,rec_num] = jshincut(par,image_dir)
19
20rec = jshincutdefpar;
21
22fields = fieldnames(rec);
23nf = length(fields);
24
25if ischar(par),
26 imagename = par;
27 par = rec;
28 par.fname_base = imagename;
29end
30
31globalenvar;
32
33if nargin<2 | isempty(image_dir),
34 image_dir = IMAGE_DIR;
35end
36
37imagename = getfield(par,fields{1});
38for i=2:nf,
39 t = getfield(par,fields{i});
40 if isempty(t),
41 par = setfield(par,fields{i},getfield(rec,fields{i}));
42 end
43end
44
45% dir and filename
46catchar = {'/','\'};
47catchar = catchar{IS_PC+1};
48
49% first check if there is a ppm file for this image
50if not(exist([image_dir,catchar,imagename,'.ppm'])),
51 j = getfnames(image_dir,[imagename,'.*']);
52 if isempty(j),
53 disp('Image not found.');
54 return;
55 end
56 k = 0;
57 for i=1:length(j),
58 k = k + not(isempty(im2ppm(j{i},image_dir)));
59 if k==1,
60 disp(sprintf('%s -> %s.ppm succeeded.',j{i},imagename));
61 break;
62 end
63 end
64 if k==0,
65 disp('Sorry. Attempt to convert your named image into ppm format failed.');
66 return;
67 end
68end
69
70cd(C_DIR);
71
72% generate command_ncut.tex file
73fn = 'command_ncut.tex';
74fid = fopen(fn,'w');
75fprintf(fid,'%21s\t%s%c%s\n',fields{1},image_dir,catchar,imagename);
76for i=2:nf,
77 t = getfield(par,fields{i});
78 if isnumeric(t),
79 t = num2str(t);
80 end
81 fprintf(fid,['%21s\t%s\n'],fields{i},t);
82end
83fclose(fid);
84%disp('You can check and modify command_ncut.tex before I run ncut_IC on it. Good?');pause(1);
85
86% run ncut_IC
87unix(['.',catchar,'ncut_IC']);
88cd(HOME_DIR);
89
90% check in
91copyfile([C_DIR,catchar,fn],[image_dir,catchar,fn]);
92rec_num = ncutcheckin(fn,image_dir,image_dir);
93%delete([image_dir,catchar,imagename,'.ppm']);
94%delete([image_dir,catchar,fn]);