在问题中,从命令行检测“坏”图像,有一个 Octave 脚本来检测坏图像。我正在尝试在 Mac OSX 上运行自制的 Octave 安装。
#!/usr/bin/octave -qf
threshold = 0.25;
usage = "Usage is: badfiles <file...> OR badfiles <errdir> <baddir> <file...>\n";
files\n";
assert(nargin>0, usage);
dryrun = isfile(argv{1});
if !dryrun
errdir = argv{1};
baddir = argv{2};
assert(isfolder(errdir) && isfolder(baddir) && isfile(argv{3}), usage);
endif
start = 1 + 2*(!dryrun);
for fname = argv()(start:end)'
q = [];
f = fname{};
warning error
try
q = imread(fname{});
catch err
end_try_catch
warning on
if isempty(q)
printf("error\t");
dryrun || movefile(f, errdir);
else
qt = all(q == q(end,1,:) ,2);
qtt = squeeze(all(qt, 3));
r = 1 - find(qtt==0, 1, 'last') / size(q, 1);
if (r > threshold)
printf("bad--%02d\t", ceil(100*r));
dryrun || movefile(f, baddir);
else
printf("good-%02d\t", ceil(100*r));
endif
endif
disp(f);
endfor
但是我无法让它运行并且它给出了一个采购错误。下面第4行有错字吗?
文件\n";
这条线应该是什么?如果我将其注释掉,我会在第 18 行收到“错误:无效的空索引表达式”,即
f = fname{};
答案1
显然在最新版本的 Octave 中,索引表达式不能为空。在索引中放入“1”即可解决。
#!/usr/bin/octave -qf
threshold = 0.25;
usage = "Usage is: badfiles <file...> OR badfiles <errdir> <baddir> <file...>\n";
assert(nargin>0, usage);
dryrun = isfile(argv{1});
if !dryrun
errdir = argv{1};
baddir = argv{2};
assert(isfolder(errdir) && isfolder(baddir) && isfile(argv{3}), usage);
endif
start = 1 + 2*(!dryrun);
for fname = argv()(start:end)'
q = [];
f = fname{1};
warning error
try
q = imread(fname{1});
catch err
end_try_catch
warning on
if isempty(q)
printf("error\t");
dryrun || movefile(f, errdir);
else
qt = all(q == q(end,1,:) ,2);
qtt = squeeze(all(qt, 3));
r = 1 - find(qtt==0, 1, 'last') / size(q, 1);
if (r > threshold)
printf("bad--%02d\t", ceil(100*r));
dryrun || movefile(f, baddir);
else
printf("good-%02d\t", ceil(100*r));
endif
endif
disp(f);
endfor