Weird histogram Image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Glynbeard
Posts: 7
Joined: 2011-09-27T06:38:30-07:00
Authentication code: 8675308

Weird histogram Image

Post by Glynbeard »

Hello (sorry I forgot to resize the images before uploading)!

I'm trying to set up an automated process which takes a radar image:
Image

Crops to the watershed I need to view:
Image

Then outputs a histogram:
Image

So that the severity of the precipitation in the area can be determined quite quickly as each pixel represents a color which represents a magnitude of precipitation/hr.

But my histogram looks kind of funky. It has a big pink stripe first and doesn't at all resemble the one posted here:http://www.imagemagick.org/Usage/files/#histogram.

Image

Any advice, or is this image correct?

Thanks!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Weird histogram Image

Post by Bonzo »

It is probably correct as your image only has 7 colours.

Code: Select all

identify -vebose jyeO6.gif
Glynbeard
Posts: 7
Joined: 2011-09-27T06:38:30-07:00
Authentication code: 8675308

Re: Weird histogram Image

Post by Glynbeard »

Okay, that's what I thought. Thanks.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Weird histogram Image

Post by Bonzo »

Have you tried the bit of code I posted as you may be able to see some info in there that may be useful.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird histogram Image

Post by fmw42 »

what commands are you using to extract the subarea and generate its histogram? take a look at your text histogram and see how many colors and which ones you get. convert image -format %c histogram:info:

Can you post a link to the subarea you have extracted so others can look at it, if you still need help? Why do you need all the black area around jyeO6.gif?

convert jyeO6.gif -fuzz 10% -trim +repage -format %c histogram:info:


1348: ( 0,102, 0) #006600 rgb(0,102,0)
3154: ( 0,153, 0) #009900 rgb(0,153,0)
2027: ( 0,204, 0) #00CC00 rgb(0,204,0)
46: ( 0,255,102) #00FF66 rgb(0,255,102)
2: (255,204, 0) #FFCC00 rgb(255,204,0)
318: (255,255, 51) #FFFF33 rgb(255,255,51)
305: (255,255,255) #FFFFFF white


convert jyeO6.gif -fuzz 10% -trim +repage histogram:jyeO6_hist.gif

Image

gives a similar histogram with a couple more colors showing (at yellow and white at the right side), but the colors are spread over the width of the histogram. NOTE that IM histograms overlay the red, green and blue channels.

It is very odd to me that your largest spike is pink/magenta, which would be a mix of primarily red and blue. I don't see any color in the text histogram with a mix of primarily red and blue. And the largest spike should be green rgb(0,153,0) at 3154 counts. Something is not right. I would post this on the bugs forum and see what the IM developers say. Perhaps I am missing something here.
Last edited by fmw42 on 2011-09-27T10:14:29-07:00, edited 1 time in total.
Glynbeard
Posts: 7
Joined: 2011-09-27T06:38:30-07:00
Authentication code: 8675308

Re: Weird histogram Image

Post by Glynbeard »

I can confirm your findings for the colors are correct when I check the text histogram.

I don't know why, but when I tried to enter:

convert jyeO6.gif -fuzz 10% -trim +repage histogram:jyeO6_hist.gif

I received an error:
Magick: option requires an argument '-fuzz' @ error/convert.c/ConvertImageCommand/1549.

The current command I'm using is simply: convert radar2.gif histogram:histogram.gif

(image name is actually radar2).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird histogram Image

Post by fmw42 »

If you are on windows, then there are some syntax differences. Try -fuzz 10%%. See http://www.imagemagick.org/Usage/windows/

But the histogram shows pink/magenta as the tallest peak (most frequent) which is a mix of red and blue (more precisely rgb(255, 0, 255) and you have no such color in your text histogram. I think something is wrong and would suggest that you post to the Bugs forum, unless you see some error I have made in analyzing your histogram.
Glynbeard
Posts: 7
Joined: 2011-09-27T06:38:30-07:00
Authentication code: 8675308

Re: Weird histogram Image

Post by Glynbeard »

That seemed to do the trick (windows command).

But yea, I'm still getting the same thing as you with the pink bar to the far left.

I'm fairly new to ImageMagick so I can't say if it's a bug or not. I'll stick by what I said earlier though and say it still looks weird.

If no one else has any advice, I'll try posting in the bug section sometime.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Weird histogram Image

Post by el_supremo »

The tallest peak on the left of the histogram represents those pixels which have a value of zero. Almost all the red and blue pixels have a zero component which gives rise to that line (e.g. there are over 3000 pixels in this one line from the histogram "3154: ( 0,153, 0) #009900 rgb(0,153,0)"). There are very few which have a 255 component, so the line on the extreme right isn't anywhere near as tall.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird histogram Image

Post by fmw42 »

el_supremo wrote:The tallest peak on the left of the histogram represents those pixels which have a value of zero. Almost all the red and blue pixels have a zero component which gives rise to that line (e.g. there are over 3000 pixels in this one line from the histogram "3154: ( 0,153, 0) #009900 rgb(0,153,0)"). There are very few which have a 255 component, so the line on the extreme right isn't anywhere near as tall.

Pete

But those values are all green, so why is the spike magenta? What am I missing?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird histogram Image

Post by fmw42 »

I wrote a quick bash script to actually graph the colors from the histogram separately (no overlap) without respect to counts, but sorted by count lowest count on the left. I will try to add the counts into the heights next.


infile="jyeO6.gif"
inname=`convert $infile -format %t info:`
ww=10
hh=100
string=""
colors=`convert $infile -format %c histogram:info:- | sort -k 1 | sed -n 's/^.*#.* \(.*\)$/\1/p'`
string=""
for color in $colors; do
string="$string xc:$color"
done
echo "string=$string"
convert -size ${ww}x${hh} $string +append ${inname}_colorspec.gif

Image

Seven colors and no magenta.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Weird histogram Image

Post by el_supremo »

But those values are all green, so why is the spike magenta? What am I missing?
Because their red and blue components are zero. If instead of rgb(0,153,0) that colour had been rgb(1,153,1) then there would be a large red/blue spike one pixel to the right of where it is now.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird histogram Image

Post by fmw42 »

Here is a color histogram by a similar script but it shows the height of each color corresponding to the count for the color:


infile="jyeO6.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}/$maxcount)]" info:`
string="$string -size ${ww}x${ht} xc:${colorArr}"
done
echo "string=$string"
convert -size ${ww}x${hh} $string -background black +append -flip ${inname}_colorhist.gif


Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Weird histogram Image

Post by fmw42 »

Because their red and blue components are zero. If instead of rgb(0,153,0) that colour had been rgb(1,153,1) then there would be a large red/blue spike one pixel to the right of where it is now.
If their red and blue components were zero, then all that should show is the green component. I believe that the histograms are drawn by channel. So to get magenta, one would have to have 0 for green and full intensity for red and blue. Or a red color rgb(255,0,0) count and a blue color rgb(0,0,255) count that was the same. Perhaps I am still missing something conceptual about how the histogram is formed.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Weird histogram Image

Post by el_supremo »

Hi Fred,
It is misleading to combine the three histograms together, especially when the colours are mixed.
Each colour component can have a value ranging from zero to 255. The X axis of the histogram represents this range, with zero at the left edge and 255 at the right edge. The height of the Y axis represents the number of pixels which have a given colour component.
So, in the red histogram, the leftmost column represents the number of pixels which have a red component of zero and the rightmost column is the number of pixels with a red component of 255. Similarly for the green and blue histograms.
The histogram you created is actually three separate histograms laid on top of each other which gives the odd-looking, and misleading, colours. If you create three separate histograms you will see that the red and blue histograms both have a large spike on the left edge because the vast majority of red and blue pixels have a zero component. The red histogram will also only have one other spike (at the right edge) because the only other component that occurs in the red channel is 255. The small blue spike in your histogram is due to the 318 pixels which have a component of 51. The larger green spike to its right is the 1348 pixels which have a green component of 102.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply