convert somewhat non-deterministic...?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kjkrum

convert somewhat non-deterministic...?

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: convert somewhat non-deterministic...?

Post 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.
kjkrum

Re: convert somewhat non-deterministic...?

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert somewhat non-deterministic...?

Post by fmw42 »

Isn't the correct syntax, txt:- rather than text:-.

see http://www.imagemagick.org/Usage/files/#txt
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert somewhat non-deterministic...?

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply