Page 1 of 1

My scripts are breaking due to a change in the -verbose info

Posted: 2008-04-03T15:43:00-07:00
by fmw42
Hello,

Many of my scripts are breaking when I try to extract the min, max, mean and standard deviation from the -verbose info: for a grayscale image. (I found this with the current IM 6.4.0-3 running Q16-hdri). This appears to be due to a change in capitalization of these words in the -verbose info:

Currently they are reported as:

Channel statistics:
gray:
min: 7196 (0.109804)
max: 59881 (0.913725)
mean: 31955.3 (0.487606)
standard deviation: 12012.7 (0.183302)


But in previous versions of IM at least around and before IM 6.3.8-11, they were reported as:

Channel statistics:
gray:
Min: 7196 (0.109804)
Max: 59881 (0.913725)
Mean: 31955.3 (0.487606)
Standard deviation: 12012.7 (0.183302)

Note the words start with a capital letter and not the current lower case letter.

My scripts had been using the following sed commands to extract this information.

data=`convert $tmp2 -verbose info:`
min=`echo "$data" | sed -n '/^.*Min:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$min" = "" ] && errMsg "--- MIN NOT FOUND --- "
max=`echo "$data" | sed -n '/^.*Max:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$max" = "" ] && errMsg "--- MAX NOT FOUND --- "
mean=`echo "$data" | sed -n '/^.*Mean:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$mean" = "" ] && errMsg "--- MEAN NOT FOUND --- "
std=`echo "$data" | sed -n '/^.*Standard.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$std" = "" ] && errMsg "--- STD NOT FOUND --- "

Now, I find this only works as:

data=`convert $tmp2 -verbose info:`
min=`echo "$data" | sed -n '/^.*min:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$min" = "" ] && errMsg "--- MIN NOT FOUND --- "
max=`echo "$data" | sed -n '/^.*max:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$max" = "" ] && errMsg "--- MAX NOT FOUND --- "
mean=`echo "$data" | sed -n '/^.*mean:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$mean" = "" ] && errMsg "--- MEAN NOT FOUND --- "
std=`echo "$data" | sed -n '/^.*standard.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
[ "$std" = "" ] && errMsg "--- STD NOT FOUND --- "


where the key words are not first letter cap.

I want to update my scripts to trap on the exact minor version where this change has first occurred, so that I can support previous as well as current versions of IM. I also want to update my script with a version trap to use the new string formats, such as

convert image -format "%[mean]"

I believe this latter occurred at IM 6.3.9-1

So I would appreciate it if someone could confirm the latter and more important tell me at which minor release the capitalization change occurred.

Thanks

Fred

Re: My scripts are breaking due to a change in the -verbose info

Posted: 2008-04-03T17:36:07-07:00
by magick
For Min/Min you should be able to use something like [Mm] in sed to match either Min or min. That should solve the problem for all versions of ImageMagick.

Re: My scripts are breaking due to a change in the -verbose info

Posted: 2008-04-03T18:09:46-07:00
by fmw42
Thanks. That works fine. I should have thought of that. Sorry. I cannot see the forest for the trees! :oops: