In the question, Detecting "bad" images from the command line, there is an Octave script to detect bad images. I'm trying to run on Mac OSX with a homebrew Octave installation.
#!/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(100r));
dryrun || movefile(f, baddir);
else
printf("good-%02d\t", ceil(100r));
endif
endif
disp(f);
endfor
However I cannot get it to run and it gives a sourcing error. Is there a typo at line 4 as below?
files\n";
What should this line be? If I comment it out, I get "error: invalid empty index expression" at line 18 which is
f = fname{};
for fname = argv()(start:end)'
line looks suss to me. Maybe try it without the'
. – cas Apr 21 '21 at 06:59files\n";
on line 4 definitely needs to be deleted. It was probably some sort of copy-paste error in the original post....looking at the edit history, it was introduced in Edit number 6. – cas Apr 21 '21 at 07:10'
is the transpose operator in octave. so it might make sense to transpose argv in octave. i don't know. – cas Apr 21 '21 at 07:13