Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

CUMHIST


Creates the combined grayscale cumulative histogram of one or more images.

Download Script

last modified: December 15, 2018



USAGE: cumhist [-f format ] [-L] [-C] [-g graph] [-m mode] [-P] [-i imgdir ] [infile1 infile2 ...]
USAGE: cumhist [-h or -help]

-f ... format .... grayscale format to use for processing; normal (n),
.................. ave (a) or global (g); default=gray
-L ............... use linear channels; default is non-linear channels
-C ............... complement cumulative histogram percent counts above 50%;
.................. default is normal cumulative histogram
-g ... graph ..... type of graph to create; simple (s) or gnuplot (g);
.................. default is no graph
-m ... mode ...... mode for graph; view (v) or save (s); default=view, if
.................. graph is requested
-P ............... progress report showing list of images as they are
.................. processed. The default is no progress report.
-i ... imgdir .... (full) path to directory of images

PURPOSE: To create the combined grayscale cumulative histogram of one or more images.

DESCRIPTION: CUMHIST creates the combined 256 bin grayscale cumulative histogram of one or more images. The results are listed to the terminal and optionally may be graphed. Images may be provided as a list in the command line or by providing a path to the image directory containing the images to be processed.

ARGUMENTS:

-f format ... FORMAT is the grayscale image format to use for processing. Choices are: normal (n), ave (a) or global (g). The default=gray. For format=normal, the R,B,B channnels will be converted to -colorspace gray. For format=ave, the R,G,B channels will be average. For format=global, the R,G,B channels will be appended.

-L ... use LINEAR channels. The default is non-linear channels.

-C ... COMPLEMENT the cumulative histogram percent counts above 50%. That for those percent counts above 50% convert them to (100-50)%. The default is a normal (non-complemented) cumulative histogram.

-g graph ... GRAPH is the type of graph to create. Choices are: simple (s) or gnuplot (g). The default is no graph.

-m mode ... MODE for the graph. Choices are: view (v) or save (s). The default=view, if a graph is requested. If mode=save, then an output image named cumhist_graph.png will be created.

-P ... PROGRESS report showing the list of images as they are processed. The default is no progress report.

-i imgdir ... IMGDIR is the (full) path to directory of images to be processed. If images are provided in the command line, this option will be ignored.

REQUIREMENTS: GNUPLOT must be installed when graph=gnuplot

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Example 1 - Normal Cumulative Histogram

Input Images

 

Textual Data

Arguments:
-g simple -m save

Arguments:
-g gnuplot -m save

Bin Count% Gray%
--- ------- -----
0 0.000 0.000
1 0.003 0.392
2 0.006 0.784
3 0.006 1.176
4 0.024 1.569
5 0.027 1.961
6 0.040 2.353
7 0.055 2.745
8 0.073 3.137
9 0.085 3.529
10 0.101 3.922
11 0.113 4.314
12 0.128 4.706
13 0.156 5.098
14 0.180 5.490
15 0.195 5.882
16 0.226 6.275
17 0.235 6.667
18 0.238 7.059
19 0.259 7.451
20 0.278 7.843
21 0.308 8.235
22 0.323 8.627
23 0.339 9.020
24 0.391 9.412
25 0.446 9.804
26 0.507 10.196
27 0.543 10.588
28 0.604 10.980
29 0.635 11.373
30 0.711 11.765
31 0.766 12.157
32 0.842 12.549
33 0.900 12.941
34 0.970 13.333
35 1.025 13.725
36 1.160 14.118
37 1.270 14.510
38 1.404 14.902
39 1.547 15.294
40 1.688 15.686
41 1.904 16.078
42 2.121 16.471
43 2.411 16.863
44 2.774 17.255
45 3.195 17.647
46 3.674 18.039
47 4.227 18.431
48 4.794 18.824
49 5.307 19.216
50 5.856 19.608
51 6.421 20.000
52 7.050 20.392
53 7.584 20.784
54 8.166 21.176
55 8.728 21.569
56 9.277 21.961
57 9.775 22.353
58 10.239 22.745
59 10.651 23.137
60 11.105 23.529
61 11.536 23.922
62 11.945 24.314
63 12.384 24.706
64 12.741 25.098
65 13.193 25.490
66 13.635 25.882
67 14.020 26.275
68 14.368 26.667
69 14.731 27.059
70 15.121 27.451
71 15.454 27.843
72 15.894 28.235
73 16.281 28.627
74 16.623 29.020
75 17.090 29.412
76 17.429 29.804
77 17.810 30.196
78 18.234 30.588
79 18.610 30.980
80 18.961 31.373
81 19.333 31.765
82 19.742 32.157
83 20.075 32.549
84 20.526 32.941
85 20.959 33.333
86 21.372 33.725
87 21.744 34.118
88 22.128 34.510
89 22.510 34.902
90 22.888 35.294
91 23.306 35.686
92 23.764 36.078
93 24.197 36.471
94 24.628 36.863
95 25.079 37.255
96 25.577 37.647
97 26.111 38.039
98 26.663 38.431
99 27.301 38.824
100 27.924 39.216
101 28.494 39.608
102 29.077 40.000
103 29.663 40.392
104 30.118 40.784
105 30.695 41.176
106 31.213 41.569
107 31.665 41.961
108 32.114 42.353
109 32.660 42.745
110 33.154 43.137
111 33.627 43.529
112 34.033 43.922
113 34.534 44.314
114 35.071 44.706
115 35.587 45.098
116 36.166 45.490
117 36.627 45.882
118 37.164 46.275
119 37.643 46.667
120 38.239 47.059
121 38.782 47.451
122 39.371 47.843
123 40.027 48.235
124 40.625 48.627
125 41.299 49.020
126 41.992 49.412
127 42.779 49.804
128 43.463 50.196
129 44.193 50.588
130 44.989 50.980
131 45.764 51.373
132 46.435 51.765
133 47.061 52.157
134 47.720 52.549
135 48.392 52.941
136 49.060 53.333
137 49.795 53.725
138 50.464 54.118
139 51.294 54.510
140 52.090 54.902
141 52.994 55.294
142 53.891 55.686
143 54.712 56.078
144 55.548 56.471
145 56.442 56.863
146 57.224 57.255
147 58.084 57.647
148 58.948 58.039
149 59.723 58.431
150 60.483 58.824
151 61.288 59.216
152 62.118 59.608
153 63.016 60.000
154 63.886 60.392
155 64.856 60.784
156 65.717 61.176
157 66.547 61.569
158 67.425 61.961
159 68.192 62.353
160 69.016 62.745
161 69.675 63.137
162 70.377 63.529
163 71.106 63.922
164 71.741 64.314
165 72.382 64.706
166 72.925 65.098
167 73.373 65.490
168 73.767 65.882
169 74.173 66.275
170 74.548 66.667
171 74.945 67.059
172 75.351 67.451
173 75.836 67.843
174 76.303 68.235
175 76.819 68.627
176 77.356 69.020
177 77.881 69.412
178 78.375 69.804
179 78.943 70.196
180 79.425 70.588
181 79.828 70.980
182 80.240 71.373
183 80.585 71.765
184 81.049 72.157
185 81.470 72.549
186 81.894 72.941
187 82.336 73.333
188 82.758 73.725
189 83.127 74.118
190 83.606 74.510
191 84.109 74.902
192 84.604 75.294
193 85.059 75.686
194 85.516 76.078
195 85.892 76.471
196 86.353 76.863
197 86.832 77.255
198 87.268 77.647
199 87.695 78.039
200 88.092 78.431
201 88.507 78.824
202 89.001 79.216
203 89.468 79.608
204 89.889 80.000
205 90.222 80.392
206 90.631 80.784
207 91.031 81.176
208 91.421 81.569
209 91.891 81.961
210 92.291 82.353
211 92.691 82.745
212 93.079 83.137
213 93.481 83.529
214 93.854 83.922
215 94.141 84.314
216 94.400 84.706
217 94.647 85.098
218 94.904 85.490
219 95.117 85.882
220 95.294 86.275
221 95.514 86.667
222 95.685 87.059
223 95.889 87.451
224 96.069 87.843
225 96.314 88.235
226 96.503 88.627
227 96.780 89.020
228 97.015 89.412
229 97.192 89.804
230 97.357 90.196
231 97.534 90.588
232 97.659 90.980
233 97.824 91.373
234 98.001 91.765
235 98.203 92.157
236 98.337 92.549
237 98.468 92.941
238 98.651 93.333
239 98.813 93.725
240 99.002 94.118
241 99.170 94.510
242 99.295 94.902
243 99.429 95.294
244 99.518 95.686
245 99.603 96.078
246 99.667 96.471
247 99.759 96.863
248 99.802 97.255
249 99.844 97.647
250 99.905 98.039
251 99.945 98.431
252 99.976 98.824
253 99.991 99.216
254 100.000 99.608
255 100.000 100.000


Example 2 - Complemented Cumulative Histogram

Input Images

 

Textual Data

Arguments:
-g simple -m save -C

Arguments:
-g gnuplot -m save -C

Bin Count% Gray%
--- ------- -----
0 0.000 0.000
1 0.003 0.392
2 0.006 0.784
3 0.006 1.176
4 0.024 1.569
5 0.027 1.961
6 0.040 2.353
7 0.055 2.745
8 0.073 3.137
9 0.085 3.529
10 0.101 3.922
11 0.113 4.314
12 0.128 4.706
13 0.156 5.098
14 0.180 5.490
15 0.195 5.882
16 0.226 6.275
17 0.235 6.667
18 0.238 7.059
19 0.259 7.451
20 0.278 7.843
21 0.308 8.235
22 0.323 8.627
23 0.339 9.020
24 0.391 9.412
25 0.446 9.804
26 0.507 10.196
27 0.543 10.588
28 0.604 10.980
29 0.635 11.373
30 0.711 11.765
31 0.766 12.157
32 0.842 12.549
33 0.900 12.941
34 0.970 13.333
35 1.025 13.725
36 1.160 14.118
37 1.270 14.510
38 1.404 14.902
39 1.547 15.294
40 1.688 15.686
41 1.904 16.078
42 2.121 16.471
43 2.411 16.863
44 2.774 17.255
45 3.195 17.647
46 3.674 18.039
47 4.227 18.431
48 4.794 18.824
49 5.307 19.216
50 5.856 19.608
51 6.421 20.000
52 7.050 20.392
53 7.584 20.784
54 8.166 21.176
55 8.728 21.569
56 9.277 21.961
57 9.775 22.353
58 10.239 22.745
59 10.651 23.137
60 11.105 23.529
61 11.536 23.922
62 11.945 24.314
63 12.384 24.706
64 12.741 25.098
65 13.193 25.490
66 13.635 25.882
67 14.020 26.275
68 14.368 26.667
69 14.731 27.059
70 15.121 27.451
71 15.454 27.843
72 15.894 28.235
73 16.281 28.627
74 16.623 29.020
75 17.090 29.412
76 17.429 29.804
77 17.810 30.196
78 18.234 30.588
79 18.610 30.980
80 18.961 31.373
81 19.333 31.765
82 19.742 32.157
83 20.075 32.549
84 20.526 32.941
85 20.959 33.333
86 21.372 33.725
87 21.744 34.118
88 22.128 34.510
89 22.510 34.902
90 22.888 35.294
91 23.306 35.686
92 23.764 36.078
93 24.197 36.471
94 24.628 36.863
95 25.079 37.255
96 25.577 37.647
97 26.111 38.039
98 26.663 38.431
99 27.301 38.824
100 27.924 39.216
101 28.494 39.608
102 29.077 40.000
103 29.663 40.392
104 30.118 40.784
105 30.695 41.176
106 31.213 41.569
107 31.665 41.961
108 32.114 42.353
109 32.660 42.745
110 33.154 43.137
111 33.627 43.529
112 34.033 43.922
113 34.534 44.314
114 35.071 44.706
115 35.587 45.098
116 36.166 45.490
117 36.627 45.882
118 37.164 46.275
119 37.643 46.667
120 38.239 47.059
121 38.782 47.451
122 39.371 47.843
123 40.027 48.235
124 40.625 48.627
125 41.299 49.020
126 41.992 49.412
127 42.779 49.804
128 43.463 50.196
129 44.193 50.588
130 44.989 50.980
131 45.764 51.373
132 46.435 51.765
133 47.061 52.157
134 47.720 52.549
135 48.392 52.941
136 49.060 53.333
137 49.795 53.725
138 49.536 54.118
139 48.706 54.510
140 47.910 54.902
141 47.006 55.294
142 46.109 55.686
143 45.288 56.078
144 44.452 56.471
145 43.558 56.863
146 42.776 57.255
147 41.916 57.647
148 41.052 58.039
149 40.277 58.431
150 39.517 58.824
151 38.712 59.216
152 37.882 59.608
153 36.984 60.000
154 36.114 60.392
155 35.144 60.784
156 34.283 61.176
157 33.453 61.569
158 32.575 61.961
159 31.808 62.353
160 30.985 62.745
161 30.325 63.137
162 29.623 63.529
163 28.894 63.922
164 28.259 64.314
165 27.618 64.706
166 27.075 65.098
167 26.627 65.490
168 26.233 65.882
169 25.827 66.275
170 25.452 66.667
171 25.055 67.059
172 24.649 67.451
173 24.164 67.843
174 23.697 68.235
175 23.181 68.627
176 22.644 69.020
177 22.119 69.412
178 21.625 69.804
179 21.057 70.196
180 20.575 70.588
181 20.172 70.980
182 19.760 71.373
183 19.415 71.765
184 18.951 72.157
185 18.530 72.549
186 18.106 72.941
187 17.664 73.333
188 17.242 73.725
189 16.873 74.118
190 16.394 74.510
191 15.890 74.902
192 15.396 75.294
193 14.941 75.686
194 14.484 76.078
195 14.108 76.471
196 13.648 76.863
197 13.168 77.255
198 12.732 77.647
199 12.305 78.039
200 11.908 78.431
201 11.493 78.824
202 10.998 79.216
203 10.532 79.608
204 10.111 80.000
205 9.778 80.392
206 9.369 80.784
207 8.969 81.176
208 8.579 81.569
209 8.108 81.961
210 7.709 82.353
211 7.309 82.745
212 6.921 83.137
213 6.519 83.529
214 6.146 83.922
215 5.859 84.314
216 5.600 84.706
217 5.353 85.098
218 5.096 85.490
219 4.883 85.882
220 4.706 86.275
221 4.486 86.667
222 4.315 87.059
223 4.111 87.451
224 3.931 87.843
225 3.687 88.235
226 3.497 88.627
227 3.220 89.020
228 2.985 89.412
229 2.808 89.804
230 2.643 90.196
231 2.466 90.588
232 2.341 90.980
233 2.176 91.373
234 1.999 91.765
235 1.798 92.157
236 1.663 92.549
237 1.532 92.941
238 1.349 93.333
239 1.187 93.725
240 0.998 94.118
241 0.830 94.510
242 0.705 94.902
243 0.571 95.294
244 0.482 95.686
245 0.397 96.078
246 0.333 96.471
247 0.241 96.863
248 0.198 97.255
249 0.156 97.647
250 0.095 98.039
251 0.055 98.431
252 0.024 98.824
253 0.009 99.216
254 0.000 99.608
255 0.000 100.000


What the script does is as follows:

  • Generates the textual histogram and computes the total pixels for each image
  • Sums the histograms bin-by-bin and the total pixels
  • Sums the bins sequentially to compute the cumulative histogram
  • Multiples each cumulated bin by 100/(total of all pixels from all images)
    so that the range of percent counts is 0 to 100
  • Converts the 8-bit bin values to percent graylevel by
    multiplying by 100/255
  • Lists the bin, count% and gray% to the terminal
  • Optionally graphs the count% vs gray%

See the script for actual code details.