A recent release change has caused my scripts to fail

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

A recent release change has caused my scripts to fail

Post by fmw42 »


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

Re: A recent release change has caused my scripts to fail

Post by magick »

> 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

We cannot reproduce this problem with ImageMagick 6.3.5-8 the current release. The bins appear to be non-duplicate. Can you post a command line so we can reproduce the problem?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: A recent release change has caused my scripts to fail

Post by fmw42 »

My apologies.

I cannot reproduce it either.

When this was occurring, I was using IM v6.3.5.0

So I went back and reloaded that version, but cannot find any image that I might have been using at the time that fails. What I found was an image that looks grayscale, but upon closer inspection there were some bins that were off by a value between the r, g, b. I might have been focusing on simply the r channel as that was what my script was extracting (assuming that all channels had the same value). When you do -format %c -depth 8 histogram:info: on that image, you do get multiple bins with the same value but different counts. Of course my script will not be using that raw image, but converting it to grayscale, so the image that it actually uses will have only one bin per graylevel.

Nevertheless, you presentation is still not sorted and this is awkward to view and to use as I still need to sort it. Here is an example:

IM 6.3.5.7
convert lena_poor.jpg -colorspace HSL lena_hsl_%d.jpg
convert lena_hsl_2.jpg -format %c -depth 8 histogram:info:
298: (163,163,163) #A3A3A3 grey64
238: (167,167,167) #A7A7A7 rgb(167,167,167)
234: (162,162,162) #A2A2A2 rgb(162,162,162)
232: (164,164,164) #A4A4A4 rgb(164,164,164)
227: (168,168,168) #A8A8A8 grey66
213: (153,153,153) #999999 grey60
210: (170,170,170) #AAAAAA rgb(170,170,170)
200: (165,165,165) #A5A5A5 rgb(165,165,165)
197: (151,151,151) #979797 rgb(151,151,151)
196: (161,161,161) #A1A1A1 grey63
195: (159,159,159) #9F9F9F rgb(159,159,159)
192: (149,149,149) #959595 rgb(149,149,149)
184: (166,166,166) #A6A6A6 grey65
184: (169,169,169) #A9A9A9 DarkGray
178: (160,160,160) #A0A0A0 rgb(160,160,160)
177: (150,150,150) #969696 grey59
177: (152,152,152) #989898 rgb(152,152,152)
174: (171,171,171) #ABABAB grey67
169: (147,147,147) #939393 rgb(147,147,147)
169: (158,158,158) #9E9E9E grey62
160: (155,155,155) #9B9B9B rgb(155,155,155)
157: ( 61, 61, 61) #3D3D3D grey24
157: (157,157,157) #9D9D9D rgb(157,157,157)
151: ( 57, 57, 57) #393939 rgb(57,57,57)
149: (122,122,122) #7A7A7A grey48
149: (154,154,154) #9A9A9A rgb(154,154,154)
148: (120,120,120) #787878 grey47
147: ( 60, 60, 60) #3C3C3C rgb(60,60,60)
144: (121,121,121) #797979 rgb(121,121,121)
143: (177,177,177) #B1B1B1 rgb(177,177,177)
140: (172,172,172) #ACACAC rgb(172,172,172)
139: (156,156,156) #9C9C9C grey61
139: (179,179,179) #B3B3B3 grey70
136: (173,173,173) #ADADAD grey68
135: (178,178,178) #B2B2B2 rgb(178,178,178)
134: ( 56, 56, 56) #383838 grey22
126: (174,174,174) #AEAEAE rgb(174,174,174)
124: ( 59, 59, 59) #3B3B3B grey23
123: ( 64, 64, 64) #404040 grey25
123: (145,145,145) #919191 grey57
123: (148,148,148) #949494 grey58
120: ( 66, 66, 66) #424242 grey26
118: (176,176,176) #B0B0B0 grey69
116: (142,142,142) #8E8E8E rgb(142,142,142)
116: (175,175,175) #AFAFAF rgb(175,175,175)
115: (124,124,124) #7C7C7C rgb(124,124,124)
114: ( 63, 63, 63) #3F3F3F rgb(63,63,63)
114: (119,119,119) #777777 rgb(119,119,119)
114: (139,139,139) #8B8B8B rgb(139,139,139)
114: (181,181,181) #B5B5B5 grey71
113: ( 65, 65, 65) #414141 rgb(65,65,65)
113: (118,118,118) #767676 rgb(118,118,118)
110: (144,144,144) #909090 rgb(144,144,144)
109: ( 55, 55, 55) #373737 rgb(55,55,55)
109: (180,180,180) #B4B4B4 rgb(180,180,180)
108: (146,146,146) #929292 rgb(146,146,146)
105: (125,125,125) #7D7D7D grey49
105: (143,143,143) #8F8F8F grey56
104: ( 58, 58, 58) #3A3A3A rgb(58,58,58)
104: ( 62, 62, 62) #3E3E3E rgb(62,62,62)
104: (117,117,117) #757575 grey46
103: (114,114,114) #727272 rgb(114,114,114)
103: (126,126,126) #7E7E7E gray
103: (184,184,184) #B8B8B8 grey72
102: (137,137,137) #898989 rgb(137,137,137)
100: (136,136,136) #888888 rgb(136,136,136)
100: (202,202,202) #CACACA rgb(202,202,202)
99: (138,138,138) #8A8A8A grey54
98: (128,128,128) #808080 fractal
98: (141,141,141) #8D8D8D rgb(141,141,141)
97: (123,123,123) #7B7B7B rgb(123,123,123)
96: (203,203,203) #CBCBCB rgb(203,203,203)
95: ( 68, 68, 68) #444444 rgb(68,68,68)
94: (131,131,131) #838383 rgb(131,131,131)
93: (185,185,185) #B9B9B9 rgb(185,185,185)
89: (205,205,205) #CDCDCD rgb(205,205,205)
86: (182,182,182) #B6B6B6 rgb(182,182,182)
86: (188,188,188) #BCBCBC rgb(188,188,188)
85: ( 67, 67, 67) #434343 rgb(67,67,67)
85: (130,130,130) #828282 grey51
85: (183,183,183) #B7B7B7 rgb(183,183,183)
84: (129,129,129) #818181 rgb(129,129,129)
83: (127,127,127) #7F7F7F rgb(127,127,127)
82: (135,135,135) #878787 grey53
82: (186,186,186) #BABABA grey73
81: (140,140,140) #8C8C8C grey55
81: (206,206,206) #CECECE rgb(206,206,206)
80: (200,200,200) #C8C8C8 rgb(200,200,200)
79: (116,116,116) #747474 rgb(116,116,116)
79: (187,187,187) #BBBBBB rgb(187,187,187)
79: (201,201,201) #C9C9C9 grey79
77: (106,106,106) #6A6A6A rgb(106,106,106)
77: (195,195,195) #C3C3C3 rgb(195,195,195)
76: ( 69, 69, 69) #454545 grey27
76: (204,204,204) #CCCCCC grey80
74: ( 71, 71, 71) #474747 grey28
73: ( 53, 53, 53) #353535 rgb(53,53,53)
73: (115,115,115) #737373 grey45
72: (110,110,110) #6E6E6E grey43
71: (196,196,196) #C4C4C4 grey77
70: ( 70, 70, 70) #464646 rgb(70,70,70)
69: ( 72, 72, 72) #484848 rgb(72,72,72)
68: (198,198,198) #C6C6C6 rgb(198,198,198)
68: (199,199,199) #C7C7C7 grey78
67: ( 54, 54, 54) #363636 grey21
67: ( 85, 85, 85) #555555 rgb(85,85,85)
67: ( 90, 90, 90) #5A5A5A rgb(90,90,90)
67: (105,105,105) #696969 DimGray
66: (108,108,108) #6C6C6C rgb(108,108,108)
66: (207,207,207) #CFCFCF grey81
65: ( 95, 95, 95) #5F5F5F rgb(95,95,95)
65: (112,112,112) #707070 grey44
64: ( 74, 74, 74) #4A4A4A grey29
64: ( 76, 76, 76) #4C4C4C rgb(76,76,76)
64: (104,104,104) #686868 rgb(104,104,104)
64: (107,107,107) #6B6B6B grey42
64: (133,133,133) #858585 grey52
64: (190,190,190) #BEBEBE grey
62: (132,132,132) #848484 rgb(132,132,132)
61: ( 73, 73, 73) #494949 rgb(73,73,73)
61: ( 75, 75, 75) #4B4B4B rgb(75,75,75)
61: (194,194,194) #C2C2C2 grey76
61: (197,197,197) #C5C5C5 rgb(197,197,197)
59: ( 98, 98, 98) #626262 rgb(98,98,98)
59: (111,111,111) #6F6F6F rgb(111,111,111)
58: ( 82, 82, 82) #525252 grey32
58: (109,109,109) #6D6D6D rgb(109,109,109)
57: ( 93, 93, 93) #5D5D5D rgb(93,93,93)
57: (208,208,208) #D0D0D0 rgb(208,208,208)
56: ( 96, 96, 96) #606060 rgb(96,96,96)
55: ( 94, 94, 94) #5E5E5E grey37
55: (103,103,103) #676767 rgb(103,103,103)
54: ( 52, 52, 52) #343434 rgb(52,52,52)
54: ( 97, 97, 97) #616161 grey38
54: (113,113,113) #717171 rgb(113,113,113)
54: (191,191,191) #BFBFBF grey75
53: ( 79, 79, 79) #4F4F4F grey31
53: ( 80, 80, 80) #505050 rgb(80,80,80)
53: (192,192,192) #C0C0C0 silver
52: ( 78, 78, 78) #4E4E4E rgb(78,78,78)
52: ( 81, 81, 81) #515151 rgb(81,81,81)
52: ( 84, 84, 84) #545454 grey33
52: (102,102,102) #666666 grey40
51: (134,134,134) #868686 rgb(134,134,134)
51: (189,189,189) #BDBDBD grey74
51: (193,193,193) #C1C1C1 rgb(193,193,193)
49: ( 86, 86, 86) #565656 rgb(86,86,86)
48: ( 88, 88, 88) #585858 rgb(88,88,88)
47: (211,211,211) #D3D3D3 LightGray
45: ( 77, 77, 77) #4D4D4D grey30
45: (101,101,101) #656565 rgb(101,101,101)
45: (209,209,209) #D1D1D1 grey82
44: (210,210,210) #D2D2D2 rgb(210,210,210)
43: ( 89, 89, 89) #595959 grey35
43: ( 91, 91, 91) #5B5B5B rgb(91,91,91)
43: ( 92, 92, 92) #5C5C5C grey36
42: ( 87, 87, 87) #575757 grey34
40: (100,100,100) #646464 rgb(100,100,100)
39: ( 99, 99, 99) #636363 grey39
37: ( 49, 49, 49) #313131 rgb(49,49,49)
37: ( 51, 51, 51) #333333 grey20
37: ( 83, 83, 83) #535353 rgb(83,83,83)
34: (212,212,212) #D4D4D4 grey83
28: (214,214,214) #D6D6D6 grey84
25: (216,216,216) #D8D8D8 rgb(216,216,216)
23: (213,213,213) #D5D5D5 rgb(213,213,213)
22: ( 50, 50, 50) #323232 rgb(50,50,50)
22: (217,217,217) #D9D9D9 grey85
20: ( 48, 48, 48) #303030 grey19
19: (215,215,215) #D7D7D7 rgb(215,215,215)
17: ( 46, 46, 46) #2E2E2E grey18
14: ( 47, 47, 47) #2F2F2F rgb(47,47,47)
13: ( 45, 45, 45) #2D2D2D rgb(45,45,45)
13: (218,218,218) #DADADA rgb(218,218,218)
12: (227,227,227) #E3E3E3 grey89
11: (221,221,221) #DDDDDD rgb(221,221,221)
10: ( 44, 44, 44) #2C2C2C rgb(44,44,44)
10: (220,220,220) #DCDCDC gainsboro
10: (222,222,222) #DEDEDE grey87
9: (219,219,219) #DBDBDB grey86
9: (226,226,226) #E2E2E2 rgb(226,226,226)
6: ( 40, 40, 40) #282828 rgb(40,40,40)
6: ( 43, 43, 43) #2B2B2B grey17
6: (228,228,228) #E4E4E4 rgb(228,228,228)
5: (224,224,224) #E0E0E0 grey88
5: (230,230,230) #E6E6E6 rgb(230,230,230)
4: ( 41, 41, 41) #292929 grey16
3: (225,225,225) #E1E1E1 rgb(225,225,225)
2: (223,223,223) #DFDFDF rgb(223,223,223)
2: (229,229,229) #E5E5E5 grey90
1: ( 37, 37, 37) #252525 rgb(37,37,37)
1: ( 42, 42, 42) #2A2A2A rgb(42,42,42)
1: (237,237,237) #EDEDED grey93

The other suggestions is that perhaps one can have an option to fill in the empty bins so that one gets a sorted 8-bit grayscale histogram that displays all bins from 0-255. In some of my scripts (see my histog script), I have to fill out these empty bins.

Thanks for the reply and for the consideraton of my suggetions.

Sorry about the false alarm on the one issue.

Fred Weinhaus.

P.S.

Is it possible to get this system to automatically email me any replies that are made by you folks, so that I do not have to keep checking back all the time for replies.
Post Reply