Sample Header Ad - 728x90

Octave script - detecting bad images - error running

0 votes
1 answer
43 views
In the question, https://unix.stackexchange.com/questions/579164/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  OR badfiles   \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
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{};
Asked by Richard L (1 rep)
Apr 21, 2021, 06:48 AM
Last activity: Apr 21, 2021, 08:13 AM