Page 1 of 1

convert somewhat non-deterministic...?

Posted: 2009-11-22T18:47:35-07:00
by kjkrum
I'm having problems with a script using convert. It used to work reliably, but now it doesn't. The output from convert is unpredictable and seemingly somewhat non-deterministic. Here's the important line:

Code: Select all

pname_base=`/usr/bin/convert "$fname" -scale 8x8! -monochrome text:- | tail -n 64 | cut -c 30 | tr -d '\n' | tr 'w' '1' | tr 'b' '0' | sed 's/^/ibase=2; /' | sed 's/$/\n/' | bc`;
That's converting an image to a 8x8 monochrome version of itself, in text form, which is then manipulated and fed into bc to get a 64-bit value to serve as the image's "fingerprint" in a database.

Previously, scaled versions of the same image reliably produced exactly the same output. Now they don't. Even more frustrating, the same file might on one execution produce one output, and on another execution produce a totally different output. This happens even with lossless image formats, although it seems to happen more with lossy ones. (One .png I have will reliably produce one of two outputs; a .jpg version of the same file produces many different outputs, some of them repeating, some seemingly random.)

Code: Select all

kevin@aphrodite:~$ convert -version
Version: ImageMagick 6.5.1-0 2009-08-27 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
I'm running Kubuntu 9.10.

Re: convert somewhat non-deterministic...?

Posted: 2009-11-22T18:53:32-07:00
by magick
You have two options. Try building your version of ImageMagick without OpenMP support (configure with the --without-openmp option) or try the latest ImageMagick release, 6.5.7-10. If you have the same problem with ImageMagick 6.5.7-10, let us know and we will investigate further.

Re: convert somewhat non-deterministic...?

Posted: 2009-11-24T17:38:56-07:00
by kjkrum
Getting it built with jpg/png support and all that is more work than I'm willing to do right now. But for what it's worth, I partly solved the problem by manipulating my images in two separate steps: first scaling to 8x8, then converting to monochrome. It still doesn't reliably produce the same output for scaled versions of the same image, but at least the output for any given file is deterministic. Hopefully this provides a clue.

Re: convert somewhat non-deterministic...?

Posted: 2009-11-24T18:04:47-07:00
by fmw42
Isn't the correct syntax, txt:- rather than text:-.

see http://www.imagemagick.org/Usage/files/#txt

Re: convert somewhat non-deterministic...?

Posted: 2009-11-24T20:26:19-07:00
by anthony
Using tail -n 64 with txt: output is also a very fragile combination.

If you want to remove the first line use tail -n +2 (start at second line) instead. OR you can use sed '1d' to 'delete the first line.

For more hints like this see my shell script file hints file...
http://hobbit.ict.griffith.edu.au/~anth ... file.hints
and search for 'range'.

Or see the 'BASH' advanced shell programming guide