1
$\begingroup$

I'm working with a large number of historical image files and am playing around with extracting dominant colours, faces, etc. with Mathematica 10. Occasionally, however, I am running into files that just plain out break the language - i.e. even Import[file,"Elements"] leads me to have to quit the kernel to get things going again.

Here's the workflow.

Often Import[file] will return

Import::fmterr : Cannot import data as GIF format.>>

So far so good.

But if you run it again, the whole kernel comes crashing down. Even if I decide not to run it again, things become unstable and the program begins to hang. The same context happens with Import[file,"Elements"] so I'm at a loss of how to debug it.

Is there any way to get Mathematica to skip these files - or any clue of what might be happening?

File here: https://www.dropbox.com/s/7x5qxlp6ybiqbxu/broken-image.gif

Screenshot of file in OS X preview:

enter image description here

In case it helps, here's the overall context of what I'm doing:

SetDirectory["/volumes/lacie/geocities-images/athens/"];
files = FileNames["*.*"];
hue = Reap[
   Do[input = Import[files[[x]]]; 
    Sow[If[Length[input] == 0, ImageMeasurements[input, "Mean"], 
      ImageMeasurements[input[[1]], "Mean"]]], {x, 1, 
     Length[files]}]];

This crashes when it hits the 'broken-image' GIF and needs to be restarted.

$\endgroup$
3
  • $\begingroup$ One workaround is to just run a bash script - for a in *.gif;do echo $a && convert $a $a.jpg; done - which converts the GIFs to JPGs and Mathematica imports them fine. But ideally there's be a native solution? Perhaps this question is far too specific.. :) $\endgroup$ Jul 30, 2014 at 14:25
  • 1
    $\begingroup$ don't know whats wrong with the file, but the hang i think results from "gif.exe" ( which mathematica evidently uses ) hanging. $\endgroup$
    – george2079
    Jul 30, 2014 at 18:23
  • 2
    $\begingroup$ Kernel crashing is never an acceptable behaviour, you should report this to Wolfram Technical Support. "Help" > "Give feedback" $\endgroup$
    – rhermans
    Aug 5, 2014 at 16:55

1 Answer 1

2
$\begingroup$

Try constraining the execution time to something reasonable

TimeConstrained[Import[filename, "Elements"], 1]

this will abort the Import function after 1 second allowing you to skip the offending files. A list of non-offending files can be obtained with this:

filelist = Select[FileNames["*.*"], (Length@TimeConstrained[Import[#, "Elements"], 1] > 0) &];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.