diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m | 94 |
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 | |||
18 | function [par,rec_num] = jshincut(par,image_dir) | ||
19 | |||
20 | rec = jshincutdefpar; | ||
21 | |||
22 | fields = fieldnames(rec); | ||
23 | nf = length(fields); | ||
24 | |||
25 | if ischar(par), | ||
26 | imagename = par; | ||
27 | par = rec; | ||
28 | par.fname_base = imagename; | ||
29 | end | ||
30 | |||
31 | globalenvar; | ||
32 | |||
33 | if nargin<2 | isempty(image_dir), | ||
34 | image_dir = IMAGE_DIR; | ||
35 | end | ||
36 | |||
37 | imagename = getfield(par,fields{1}); | ||
38 | for 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 | ||
43 | end | ||
44 | |||
45 | % dir and filename | ||
46 | catchar = {'/','\'}; | ||
47 | catchar = catchar{IS_PC+1}; | ||
48 | |||
49 | % first check if there is a ppm file for this image | ||
50 | if 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 | ||
68 | end | ||
69 | |||
70 | cd(C_DIR); | ||
71 | |||
72 | % generate command_ncut.tex file | ||
73 | fn = 'command_ncut.tex'; | ||
74 | fid = fopen(fn,'w'); | ||
75 | fprintf(fid,'%21s\t%s%c%s\n',fields{1},image_dir,catchar,imagename); | ||
76 | for 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); | ||
82 | end | ||
83 | fclose(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 | ||
87 | unix(['.',catchar,'ncut_IC']); | ||
88 | cd(HOME_DIR); | ||
89 | |||
90 | % check in | ||
91 | copyfile([C_DIR,catchar,fn],[image_dir,catchar,fn]); | ||
92 | rec_num = ncutcheckin(fn,image_dir,image_dir); | ||
93 | %delete([image_dir,catchar,imagename,'.ppm']); | ||
94 | %delete([image_dir,catchar,fn]); | ||