Page 1 of 1

Histogram By Channel

Posted: 2007-07-02T17:26:34-07:00
by fmw42
I have generated a histogram of the red channel of the logo: image and find that the order of the histogram is not sequential with the color values. Seems to me that it might be a important that the listing of the histogram be properly ordered. For example if one wants to extract the count for the lowest and highest color values, then it would be nice if one could count on them being the first and last in the list.

In the following, note that color value 1 comes before 0 and color value 255 comes before 254. Here is what I found:

~ fred$ convert logo: -channel Red -separate GIF:- | convert GIF: -format %c histogram:info:-
965: ( 1, 1, 1) #010101 rgb(1,1,1)
642: ( 0, 0, 0) #000000 black
10877: ( 2, 2, 2) #020202 rgb(2,2,2)
80: ( 4, 4, 4) #040404 rgb(4,4,4)
18: ( 6, 6, 6) #060606 rgb(6,6,6)
168: ( 8, 8, 8 ) #080808 grey3
701: ( 10, 10, 10) #0A0A0A grey4
148: ( 11, 11, 11) #0B0B0B rgb(11,11,11)
336: ( 12, 12, 12) #0C0C0C rgb(12,12,12)
25: ( 16, 16, 16) #101010 rgb(16,16,16)
362: ( 17, 17, 17) #111111 rgb(17,17,17)
631: ( 19, 19, 19) #131313 rgb(19,19,19)
151: ( 18, 18, 18) #121212 grey7
729: ( 21, 21, 21) #151515 rgb(21,21,21)
51: ( 22, 22, 22) #161616 rgb(22,22,22)
383: ( 25, 25, 25) #191919 rgb(25,25,25)
120: ( 24, 24, 24) #181818 rgb(24,24,24)
180: ( 26, 26, 26) #1A1A1A grey10
496: ( 27, 27, 27) #1B1B1B rgb(27,27,27)
1262: ( 28, 28, 28) #1C1C1C grey11
1721: ( 34, 34, 34) #222222 rgb(34,34,34)
1640: ( 36, 36, 36) #242424 grey14
380: ( 37, 37, 37) #252525 rgb(37,37,37)
411: ( 38, 38, 38) #262626 grey15
292: ( 39, 39, 39) #272727 rgb(39,39,39)
1336: ( 41, 41, 41) #292929 grey16
81: ( 43, 43, 43) #2B2B2B grey17
145: ( 42, 42, 42) #2A2A2A rgb(42,42,42)
462: ( 45, 45, 45) #2D2D2D rgb(45,45,45)
99: ( 46, 46, 46) #2E2E2E grey18
111: ( 47, 47, 47) #2F2F2F rgb(47,47,47)
769: ( 48, 48, 48) #303030 grey19
2244: ( 49, 49, 49) #313131 rgb(49,49,49)
169: ( 51, 51, 51) #333333 grey20
407: ( 50, 50, 50) #323232 rgb(50,50,50)
88: ( 53, 53, 53) #353535 rgb(53,53,53)
154: ( 55, 55, 55) #373737 rgb(55,55,55)
245: ( 56, 56, 56) #383838 grey22
164: ( 69, 69, 69) #454545 grey27
243: ( 72, 72, 72) #484848 rgb(72,72,72)
56: ( 75, 75, 75) #4B4B4B rgb(75,75,75)
52: ( 74, 74, 74) #4A4A4A grey29
181: ( 79, 79, 79) #4F4F4F grey31
48: ( 81, 81, 81) #515151 rgb(81,81,81)
625: ( 83, 83, 83) #535353 rgb(83,83,83)
252: ( 84, 84, 84) #545454 grey33
64: ( 86, 86, 86) #565656 rgb(86,86,86)
126: ( 88, 88, 88) #585858 rgb(88,88,88)
190: ( 89, 89, 89) #595959 grey35
8: ( 92, 92, 92) #5C5C5C grey36
256: (102,102,102) #666666 grey40
60: (105,105,105) #696969 DimGray
67: (106,106,106) #6A6A6A rgb(106,106,106)
180: (108,108,108) #6C6C6C rgb(108,108,108)
124: (110,110,110) #6E6E6E grey43
218: (115,115,115) #737373 grey45
107: (117,117,117) #757575 grey46
222: (118,118,118) #767676 rgb(118,118,118)
121: (119,119,119) #777777 rgb(119,119,119)
20: (120,120,120) #787878 grey47
17: (124,124,124) #7C7C7C rgb(124,124,124)
2: (128,128,128) #808080 fractal
31: (131,131,131) #838383 rgb(131,131,131)
224: (132,132,132) #848484 rgb(132,132,132)
598: (137,137,137) #898989 rgb(137,137,137)
51: (138,138,138) #8A8A8A grey54
102: (140,140,140) #8C8C8C grey55
377: (141,141,141) #8D8D8D rgb(141,141,141)
82: (143,143,143) #8F8F8F grey56
265: (145,145,145) #919191 grey57
103: (144,144,144) #909090 rgb(144,144,144)
236: (149,149,149) #959595 rgb(149,149,149)
413: (153,153,153) #999999 grey60
202: (157,157,157) #9D9D9D rgb(157,157,157)
18: (158,158,158) #9E9E9E grey62
251: (161,161,161) #A1A1A1 grey63
244: (164,164,164) #A4A4A4 rgb(164,164,164)
43: (167,167,167) #A7A7A7 rgb(167,167,167)
190: (169,169,169) #A9A9A9 DarkGray
214: (170,170,170) #AAAAAA rgb(170,170,170)
50: (171,171,171) #ABABAB grey67
157: (173,173,173) #ADADAD grey68
96: (174,174,174) #AEAEAE rgb(174,174,174)
89: (175,175,175) #AFAFAF rgb(175,175,175)
38: (176,176,176) #B0B0B0 grey69
204: (178,178,178) #B2B2B2 rgb(178,178,178)
96: (179,179,179) #B3B3B3 grey70
210: (180,180,180) #B4B4B4 rgb(180,180,180)
50: (184,184,184) #B8B8B8 grey72
159: (185,185,185) #B9B9B9 rgb(185,185,185)
206: (186,186,186) #BABABA grey73
147: (189,189,189) #BDBDBD grey74
17: (193,193,193) #C1C1C1 rgb(193,193,193)
3: (192,192,192) #C0C0C0 silver
215: (194,194,194) #C2C2C2 grey76
248: (196,196,196) #C4C4C4 grey77
5: (197,197,197) #C5C5C5 rgb(197,197,197)
27: (199,199,199) #C7C7C7 grey78
140: (198,198,198) #C6C6C6 rgb(198,198,198)
251: (201,201,201) #C9C9C9 grey79
342: (202,202,202) #CACACA rgb(202,202,202)
71: (205,205,205) #CDCDCD rgb(205,205,205)
118: (204,204,204) #CCCCCC grey80
182: (206,206,206) #CECECE rgb(206,206,206)
60: (208,208,208) #D0D0D0 rgb(208,208,208)
352: (210,210,210) #D2D2D2 rgb(210,210,210)
419: (212,212,212) #D4D4D4 grey83
155: (214,214,214) #D6D6D6 grey84
122: (217,217,217) #D9D9D9 grey85
262: (221,221,221) #DDDDDD rgb(221,221,221)
73: (220,220,220) #DCDCDC gainsboro
152: (222,222,222) #DEDEDE grey87
6: (225,225,225) #E1E1E1 rgb(225,225,225)
212: (226,226,226) #E2E2E2 rgb(226,226,226)
145: (227,227,227) #E3E3E3 grey89
341: (229,229,229) #E5E5E5 grey90
412: (233,233,233) #E9E9E9 rgb(233,233,233)
22: (232,232,232) #E8E8E8 grey91
1316: (235,235,235) #EBEBEB grey92
2184: (234,234,234) #EAEAEA rgb(234,234,234)
140: (237,237,237) #EDEDED grey93
14: (239,239,239) #EFEFEF rgb(239,239,239)
386: (238,238,238) #EEEEEE rgb(238,238,238)
1188: (241,241,241) #F1F1F1 rgb(241,241,241)
132: (240,240,240) #F0F0F0 grey94
533: (243,243,243) #F3F3F3 rgb(243,243,243)
100: (242,242,242) #F2F2F2 grey95
451: (244,244,244) #F4F4F4 rgb(244,244,244)
510: (247,247,247) #F7F7F7 grey97
966: (249,249,249) #F9F9F9 rgb(249,249,249)
2443: (251,251,251) #FBFBFB rgb(251,251,251)
531: (252,252,252) #FCFCFC grey99
219: (253,253,253) #FDFDFD rgb(253,253,253)
253491: (255,255,255) #FFFFFF white
616: (254,254,254) #FEFEFE rgb(254,254,254)

Re: Histogram By Channel

Posted: 2007-07-02T21:35:44-07:00
by anthony
The order of the histogram is currently undefined. If you like to define an order. Please do.

Note histogram routine ouput may become more important in re-development of some of the contrast stretching and possible future auto-leveling operators. The current set of operators is a bit of a mess having been developed piecemeal over the years of IM development.

You may like to look at the source code for the 'histogram:' output coder as a starting point.
It graphs the histogram, and saves the text version of it in the comment of the image.
Sounds like a good starting point to trace the code and figure out the best way to add it.

Re: Histogram By Channel

Posted: 2007-07-03T10:40:40-07:00
by fmw42
Hello Anthony,

Thanks for the reply.

In my opinion the histogram should be presented channel by channel, individually, sorted by color value (0-255) or whatever is the scale.

As for looking at the code, I am not much of a programmer. I know a little C, but have not done a lot of programming per se. I have done a lot of scripting over the years (Applescript, Javascript, PHP, Lasso, etc). But I would be willing to help in any way with advice and algorithms.

How would I get a copy of the code, in any event, in order to see how you are implementing some of these functions?

I just started to use/learn ImageMagick and my goal is to develop some shell scripts to present new ways to interface to some of the enhancement, filtering and transformation funtions.

I have been doing image processing for nearly 30 years, 17 of which were at TRW, where we developed one of the very first image processing systems for the government and oil and mineral exploration industries (1970s - 1990s). My particular career interest at TRW was in persepective transformations.

My condensed resume can be found at http://www.fmwconcepts.com/fmw/fmw.html. There you can find links to the image perspective transformation system that we developed at TRW and to my list of publications regarding image matching, image enhancement and perspective transformations. (If you would like any of my publications, let me know and I can mail them to you.)

I do not know ImageMagick well enough yet to know if you have the following capability, but there are some interesting ways to enhance an image if one has access to certain image statistics. These include: min value, max value, mean and standard deviation for the image as a whole and particularly per channel. These values can then be compared to desired values to set up a linear tranformation of the image to control brightness and contrast.

Also there are some better enhancements that can be made using the cumulative histogram, one of which is histogram equalization (something that was asked about in the online examples pages). This basically tries to change the distibution of colors (grayscale values per channel) so that the resulting histogram is uniformly flat or in other words has a linearly increasing cumulative histogram. A better approach is to redistribute the colors in each channel or all together such that the histogram is changed to a Gaussian distribution. Once again this is done using the cumulative histogram of the image and mapping it to the cumulative histogram of a Gaussian distribution where the user supplies the desired mean and standard deviation, for example.

With regard to your perspective transformation, a four corner input approach is only one way to do that and is rather limiting. I would suggest that you provide an alternate method that allows the user to provide the 8 coefficients directly. You must be computing them from the two sets of four corner points, so they must really be the basis of the transformation any way. In my list of publications, you will see several papers on doing perspective transformation or texture mapping and some of our algorithms that compute the 8 coefficients from the focal length of the camera and orientation angles.

By the way, I am on a Mac OS X system and am currently using ImageMagick 6.3.4. I understand that there is a beta of 6.3.5 that now has the four corner perspective transfomation function. I would like to experiment with it, but I cannot find a binary to install for the Macintosh. Can you tell me where to get it?

My goal is to develop some shell scripts for doing some of these kinds of things with a better user interface and to experiment with what I can do using -fx and/or distortion maps to achieve many of these things where not feasible in a more efficient way. In my list of publications, you will find two papers on distortion maps, what we called Look Up Table mapping. So I am glad to see that you have implemented that.

I would be happy to discuss any ideas you have about enhancements to ImageMagick and perhaps could provide mathematical support and suggestions on implementation.

Thanks

Fred Weinhaus

Re: Histogram By Channel

Posted: 2007-07-03T18:21:51-07:00
by anthony
The histogram you are describing does not list the histogram by color but
as a per-channel histogram. Than could be useful in the output of IM.

Perhaps you like to create a patch.

The code can be downloads either as a TAR, SRPM, or even a Subversion download. Upload however is restricted to developers of 'proven capability', which you get by submitting patches to Cristy, the development coordinator.
fmw42 wrote:I have been doing image processing for nearly 30 years, 17 of which were at TRW, where we developed one of the very first image processing systems for the government and oil and mineral exploration industries (1970s - 1990s). My particular career interest at TRW was in persepective transformations.
Wow! Sounds like you would be a good person to get on board.

However Developing C code from existing programs isn't difficult, especially if you have some programming experience in other languages. The trick is tracing though the other code to figure out what it is doing and making the appropriate calls.

I think I may send you some private mail on the forum too.