0

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{};

  • Octave seems to be a very strange choice of language for detecting corrupted files (perl or python or ruby or whatever with libmagick bindings seem more appropriate)....but if it works, it works, I guess. Anyway, I'm certainly no expert in octave's syntax, but that single-quote at the end of the for fname = argv()(start:end)' line looks suss to me. Maybe try it without the '. – cas Apr 21 '21 at 06:59
  • 2
    BTW, the files\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
  • I spoke too soon - still getting "error: invalid empty index expression" in line 18 – Richard L Apr 21 '21 at 07:13
  • also btw, further reading indicates that ' 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
  • apologies - I spoke too soon - still getting "error: invalid empty index expression" in line 18 – Richard L Apr 21 '21 at 07:21
  • unfortunately not, end seems to be a restricted word – Richard L Apr 21 '21 at 07:40
  • ok. i've more than exhausted my knowledge of octave syntax, and am just making hacky guesses. you might have more luck on stackoverflow.com or scicomp.stackexchange.com or one of the other stack exchange sites where octave use is more common than here on U&L. – cas Apr 21 '21 at 07:44

1 Answers1

0

Apparently in recent versions of Octave, index expressions cannot be empty. Putting a "1" in the index solves.

#!/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(100r)); dryrun || movefile(f, baddir); else printf("good-%02d\t", ceil(100r)); endif endif

disp(f); endfor