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
Weird histogram Image
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Weird histogram Image
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.
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!
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.
This may actualy be a good output image type.I thought it was just the colors from the text histogram plotted in the order listed.
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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Weird histogram Image
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
Not a huge deal but if anyone would be able to convert the script fmw42 posted earlier:
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!
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
If anyone could help me out that would be excellent!
Thanks for the help so far guys!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Weird histogram Image
My first attempt at a "color histogram"...
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.
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
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Weird histogram Image
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Weird histogram Image
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Weird histogram Image
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Weird histogram Image
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/