Page 2 of 2

Re: Weird histogram Image

Posted: 2011-09-27T16:19:12-07:00
by fmw42
Thanks Pete,

I was misunderstanding the IM histogram process. My error was misunderstanding the X axis and what it represented. I thought it was just the colors from the text histogram plotted in the order listed. I see now what you mean by counting the number of pixels with 0 value as the first or left most column for each channel. Makes sense now, but that kind of histogram is not what I think this person needed in the case of just a few colors and seeing the actual color vs count. So I created a script to generate that, i.e. just sorting the colors by count.

I am making this into a formal script as I think it might be a useful alternate to the IM histogram.

Fred

Re: Weird histogram Image

Posted: 2011-09-27T16:58:15-07:00
by anthony
Histograms are really more designed for greyscale images, not color images. You must remember that the histogram is not a graph of colors (which is a 3-dimensional colortable) but three separate graphs of the values in each channel.


If you want a histogram of COLORS. What you may like to try is to convert the image to greyscale. With as few colors as this image has most likely each greyscale value will represent a unique color.

Another approach is to convert the image to a Hue colorspace, and get a histogram of just the hues. You can color the grayscale histogram by overlaying a rainbow gradient :-) Though it is likely that all the different shades of green may come out as the same hue, so that may not work very well.

There are other ways of representing image color counts other than histograms, and these may be better suited.
I thought it was just the colors from the text histogram plotted in the order listed.
This may actualy be a good output image type.


One thing that I have had on my ToDO list for some time is to expand "histogram:" into two different in-memory operators:
one to generate a 1-D image of value counts (histogram), and a separate operator to generate different sorts of profiles (graphs).

I want have them separate as you can get far more control of the two aspects. For example generate different profiles such as how various operators (like -negate, -level, -evaluate -function) work, graphing them in different ways. Or make histograms that use different numbers of 'bins' in its generation. Or even other sorts of histograms such as discussed above.

Fred you know where my ToDo list is!

Re: Weird histogram Image

Posted: 2011-09-27T17:22:57-07:00
by fmw42
Don't forget to make a third category as a cumulative histogram - useful for -equalize, redist and and a few other functions such as the many different auto thresholding methods I scripted.

Re: Weird histogram Image

Posted: 2011-09-29T05:58:42-07:00
by Glynbeard
Not a huge deal but if anyone would be able to convert the script fmw42 posted earlier:

Code: Select all

infile="radar1.gif"
inname=`convert $infile -format %t info:`
ww=10
hh=100
hist=`convert $infile -format %c histogram:info:- | sort -k 1 | sed -n 's/^ *\(.*\)$/\1/p'`
echo "hist=$hist"
string=""
colorArr=(`echo "$hist" | sed -n 's/^.*#.* \(.*\)$/\1/p'`)
echo "colors=${colorArr[*]}"
nc=${#colorArr[*]}
nc1=$((nc-1))
echo "nc=$nc"
countArr=(`echo "$hist" | sed -n 's/^\(.*\):.*$/\1/p'`)
echo "counts=${countArr[*]}"
maxcount=${countArr[$nc1]}
echo "maxcount=$maxcount"
string=""
for ((i=0; i<nc; i++)); do
ht=`convert xc: -format "%[fx:round(100*${countArr[i]}/$maxcount)]" info:`	
string="$string -size ${ww}x${ht} xc:${colorArr[i]}"
done
echo "string=$string"
convert -size ${ww}x${hh} $string -background black +append -flip ${inname}_colorhist.gif
from a unix shell to ms dos bat file compatible one I would really appreciate it. I'm not that experienced using either of their syntaxs so I'm kind of stuck.

If anyone could help me out that would be excellent!

Thanks for the help so far guys! :)

Re: Weird histogram Image

Posted: 2011-09-29T17:52:30-07:00
by anthony
My first attempt at a "color histogram"...

Code: Select all

convert rose: -colors 256 -format %c histogram:info:- | sed 's/:.*#/ #/' | 
  while read count color colorname; do
     convert -size 1x$count xc:$color miff:-
  done |
    convert - -alpha set -gravity south -background none +append  unique_color_histogram.png
Image
as you can see lots of greys, reds, and a strong white peak.

Note without the -colors color reduction, the image would be VERY long, and take a long time to produce as the built-in rose image contains 3020 unique colors.

A faster version could generate command line options in the while and the run one convert command.

you could also sort by count by adding a "sort -n" in the pre-processing pipeline, or even sort by other methods.

alternative outputs such as 2-dimensional red-blue / green-blue / red-green scatter plots (circles of size of count)
or bar charts. Or a fully 3-D view such as a color cubes with colored spheres for the binned color counts.

Re: Weird histogram Image

Posted: 2011-10-03T16:00:00-07:00
by fmw42
I have created a new bash unix script, spectrumhist, to do the things that I had posted the code above. It can be found on my web site listed below.

Re: Weird histogram Image

Posted: 2011-10-03T18:25:18-07:00
by anthony
Nice work Fred.

Though you can have other color sort methods. No method is good for all images.
histogram (or unique color) sorting is simply sort by red (then green and blue) (not good unless image is very red)
spectrum sorts by hue (fails when unsaturated colors (near greys) are present)

Others...
intensity (basically similar to histogram for gray images, but handls off-gray better)
by green value, then the other two
by blue value, then the other two.

or you can sort in multiple sections.
sort unsaturated colors by intensity
sort mid-tone-saturated colors by hue
(which area can be determine by dynamically reducing the color set to a map of primaries and grey)

or into sections such as I used in my display of named colors (white, light hues, mid-tone hues, dark hues and black)
http://www.imagemagick.org/Usage/color_ ... olor_names
(this may not handle lots of unsaturated colors).

Or you can 'bin' the original image colors to a special set of colors, EG a sequence of Greys and specific Hues
Note that in this case some bins may be zero, and these how be kept and a gap left in the display.

This last is a good one as a more general color finger print for image comparison as the same color set can be applied.

Re: Weird histogram Image

Posted: 2011-10-03T19:44:52-07:00
by fmw42
anthony wrote:Nice work Fred.

Though you can have other color sort methods. No method is good for all images.
histogram (or unique color) sorting is simply sort by red (then green and blue) (not good unless image is very red)
spectrum sorts by hue (fails when unsaturated colors (near greys) are present)

Others...
intensity (basically similar to histogram for gray images, but handls off-gray better)
by green value, then the other two
by blue value, then the other two.

or you can sort in multiple sections.
sort unsaturated colors by intensity
sort mid-tone-saturated colors by hue
(which area can be determine by dynamically reducing the color set to a map of primaries and grey)

or into sections such as I used in my display of named colors (white, light hues, mid-tone hues, dark hues and black)
http://www.imagemagick.org/Usage/color_ ... olor_names
(this may not handle lots of unsaturated colors).

Or you can 'bin' the original image colors to a special set of colors, EG a sequence of Greys and specific Hues
Note that in this case some bins may be zero, and these how be kept and a gap left in the display.

This last is a good one as a more general color finger print for image comparison as the same color set can be applied.

All good ideas. I may look into adding more sort options, esp, intensity.

Of course this is something I expect you already have on your list of histogram things for IM 7 as well as the "scaling" concept for any histograms and adjustable histogram graph sizes.

Re: Weird histogram Image

Posted: 2011-10-03T21:57:42-07:00
by anthony
Actually no I hadn't though of it before now. But they are possibility.

Remember a normal histogram is actually a histogram using fixed bin locations. Using actual colors of the image, or just reducing colors is really a dynamic binning method. The results can not be used to image compares, only for image analysis.