A recent release change has caused my scripts to fail
Posted: 2007-09-05T23:05:06-07:00
Hello,
I have fixed my scripts with a cleaner implementation of my function that does not rely upon the keyword that is sensitive to changes in the IM version. (see my notes below) The new script is:
function imagestats
{
data=`convert $1 -verbose info:`
min=`echo "$data" | sed -n 's/^.*Min:.*[(]\([0-9.]*\).*$/\1/p'`
max=`echo "$data" | sed -n 's/^.*Max:.*[(]\([0-9.]*\).*$/\1/p'`
mean=`echo "$data" | sed -n 's/^.*Mean:.*[(]\([0-9.]*\).*$/\1/p'`
std=`echo "$data" | sed -n 's/^.*Standard.*[(]\([0-9.]*\).*$/\1/p'`
#
# express as percent
min=`echo "scale=0; $min * 100 / 1" | bc`
max=`echo "scale=0; $max * 100 / 1" | bc`
mean=`echo "scale=0; $mean * 100 / 1" | bc`
std=`echo "scale=0; $std * 100 / 1" | bc`
}
Sorry to bother you about it. Nevertheless a direct method of getting the min, max, mean and std from IM would be a nice enhancement. Also fixing the grayscale histogram presentation so that it does not have multiple bins and the bins are sequential would also be a good idea in my opinion.
Fred Weinhaus
Hello,
I have spent the last 6-8 weeks creating some IM scripts and just posted them two days ago after upgrading from IM 6.3.5.0 to 6.3.5.7. Now certain portions of my scripts do not work. I have traced this to a function that I wrote to extract the min, max, mean and std values from the -verbose info: I use this function quite frequently in my scripts.
What seems to be happening is that the format for the data reported back has changed. In my function, I was using a keyword "Colors" to know when to stop processing. It appears that this has been removed or changed and what follows the section for these statistics is the the histogram which starts with a label of Histogram:. So my script works if I replace "Colors" with "Histogram".
Here is my old function which no longer works for IM 6.3.5.7, but worked for IM 6.3.5.0
function imagestats
{
data=`convert $1 -verbose info:- | sed -n '/statistics:/,/Colors/ p'`
min=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Min:.*[(]\([0-9.]*\).*Max.*$/\1/'`
max=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Max:.*[(]\([0-9.]*\).*Mean.*$/\1/'`
mean=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Mean:.*[(]\([0-9.]*\).*Standard.*$/\1/'`
std=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Standard:.*[(]\([0-9.]*\).*Colors.*$/\1/'`
#
# express as percent
min=`echo "scale=0; $min * 100 / 1" | bc`
max=`echo "scale=0; $max * 100 / 1" | bc`
mean=`echo "scale=0; $mean * 100 / 1" | bc`
std=`echo "scale=0; $std * 100 / 1" | bc`
}
Here is the new one that now works for IM 6.3.5.7
function imagestats
{
data=`convert $1 -verbose info:- | sed -n '/statistics:/,/Hist/ p'`
min=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Min:.*[(]\([0-9.]*\).*Max.*$/\1/'`
max=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Max:.*[(]\([0-9.]*\).*Mean.*$/\1/'`
mean=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Mean:.*[(]\([0-9.]*\).*Standard.*$/\1/'`
std=`echo $data | sed 's/^.*Channel statistics:.*Gray:.*Standard:.*[(]\([0-9.]*\).*Hist.*$/\1/'`
#
# express as percent
min=`echo "scale=0; $min * 100 / 1" | bc`
max=`echo "scale=0; $max * 100 / 1" | bc`
mean=`echo "scale=0; $mean * 100 / 1" | bc`
std=`echo "scale=0; $std * 100 / 1" | bc`
}
I checked the release notes for the various versions and found no indication of this change and so thought my scripts were OK.
First, I want to express my displeasure in these kinds of unannounced changes.
Second, I know that I can trap on the version number so that I can use my old version or the new version as appropriate, but I do NOT know in which release this occurred. Can someone provide me with that information.
Third, I would like to strongly recommend that some release independent method of getting to these statistics be implemented, such as using %character to get each one as you do with width (%w) and height (%h); or any other mechanism you want.
I am also not happy with the way you present the histogram data for a grayscale image when using -format %c -depth 8 histogram:info:. It has multiple occurrences of the same bin with different counts that I have to merge (sum) and also the bins are not well ordered sequentially, so I have to do a sort as well before merging. I have had to write a special (grayscale) histogram processing function to generate an orderly unified histogram.
I would like to fix my script as quickly as possible as they were just released and now I am caught with "egg on my face" regarding the fact that many do not work because of the change in IM info:
You can see some of my scripts and results at:
http://www.fmwconcepts.com/imagemagick/index.html
Thanks for your attention and prompt reply.
Fred Weinhaus
fmw@alink.net