spectrumhist and greyscales

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

spectrumhist and greyscales

Post by greengrass »

I'm trying to use spectrumhist with greyscale images. So far I've only been able to get different bars in the histograms I generate.

converted jpeg to jpeg with IM -colorspace Gray
generated histograms with ./spectrumhist -t histogram -s hue -h 500 -m 3 -w 15 -c 14 grayscale.jpg outfile.jpg

I know that I'm doing something stupid, but can't figure it out.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

This script was not really designed for grayscale image.

Grayscale image do not have any hue. You cannot use that sorting method.

The only options that may be applicable to grayscale images are

"$type" = "spectrum" -a "$sort" = "count"

"$type" = "spectrum" -a "$sort" = "lum"

"$type" = "histogram" -a "$sort" = "lum"


However, I have not tested these and any but the first may not work the way you expect.

Let me know what happens.

You might just want to create a simple IM histogram.
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

Re: spectrumhist and greyscales

Post by greengrass »

$type" = "histogram" -a "$sort" = "lum"

-t histogram -s lum output looks exactly like what I am looking for except only 8 bars.

What is the "-a" for. I don't see how to apply that particular option?

For the record, I'm trying to analyze some classical and modern paintings via their grayscales. The histograms your script generate are exactly what I need, but artists generally use a 9 level grayscale which is what I'm shooting for.

thanks again for your help and your great scripts.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

greengrass wrote:$type" = "histogram" -a "$sort" = "lum"

-t histogram -s lum output looks exactly like what I am looking for except only 8 bars.

What is the "-a" for. I don't see how to apply that particular option?

For the record, I'm trying to analyze some classical and modern paintings via their grayscales. The histograms your script generate are exactly what I need, but artists generally use a 9 level grayscale which is what I'm shooting for.

thanks again for your help and your great scripts.

There is no -a option. What I wrote was from the code conditionals.

-t histogram -s lum is the correct syntax.

As for 8 graylevels vs 9 graylevels, I am not sure what you mean. Can you upload an example image and the spectrum you get, so I can see what you are getting at? You can upload to dropbox.com (public folder) and put a link here. Or if you want send me direct email to my address fmw at alink dot net
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

Re: spectrumhist and greyscales

Post by greengrass »

Fred,

Original, converted to greyscale, and the histogram out put sent via dropbox to you. Sorry for 3 individual e-mails and links, but that's seems to be how dropbox works.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

greengrass wrote:Fred,

Original, converted to greyscale, and the histogram out put sent via dropbox to you. Sorry for 3 individual e-mails and links, but that's seems to be how dropbox works.
What was your exact command that generated the spectrum histogram? Did you do any other pre-processing besides converting it to grayscale image? Did you reduce the number of colors?

Fred
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

Re: spectrumhist and greyscales

Post by greengrass »

fmw42 wrote:What was your exact command that generated the spectrum histogram? Did you do any other pre-processing besides converting it to grayscale image? Did you reduce the number of colors?

Fred
./spectrumhist -t histogram -s lum -h 500 -m 3 -w 15 -c 14 graystarynight.jpg staroutgray.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

Those arguments do not correspond to the images you uploaded. Also I found some bugs in the script. Did you modify the script? If not, I do not see how you got even that result?

Nevertheless, I have uploaded a new script. However, the script uses the IM command -colors, which does not guarantee the exact number of colors specified. See http://www.imagemagick.org/script/comma ... php#colors

I would have to modify the script to use a very simple quantization so that you get the desired number of colors.
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

Re: spectrumhist and greyscales

Post by greengrass »

Fred,

The one minor modification I did make was at like 365 where I changed "....blackground black...." to ....blackground blue..." which allows me to see the blackest bar of the histogram.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

That should not matter. But there were other bugs that I had to fix.

Please clarify the issue about 8 vs 9 grayshades. Currently, the IM command -colors does not honor the exact number of colors you specify. It will not exceed the specified value, but can be less.

How does this affect what you are trying to do?
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

Re: spectrumhist and greyscales

Post by greengrass »

fmw42 wrote:Please clarify the issue about 8 vs 9 grayshades. Currently, the IM command -colors does not honor the exact number of colors you specify. It will not exceed the specified value, but can be less.

How does this affect what you are trying to do?
What I have found so far:
Using the grayscale image as input file, if I specify:
-c where c is less than 128 but greater than 64 I get a 64 bar histogram
if -c is less than 64 and greater than 32 I get a 32 bar histogram
if -c is less than 32 and greater than 16 I get a 16 bar histogram
if -c is less than 16 and greater than 8 I get a 8 bar histogram

I checked and there are 256 'unique colors' in the grayscale image.

None of the above results occur if I change to a full color image as input.

I've just started some systematic testing with your updated script so take the results with an 'imperial gallon of salt'
I've got a agenda tomorrow that is away from computers, so I won't get any testing done until late but I will try to put in
a couple of hour tomorrow evening and get you some quality testing results.

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

Re: spectrumhist and greyscales

Post by fmw42 »

What I have found so far:
Using the grayscale image as input file, if I specify:
-c where c is less than 128 but greater than 64 I get a 64 bar histogram
if -c is less than 64 and greater than 32 I get a 32 bar histogram
if -c is less than 32 and greater than 16 I get a 16 bar histogram
if -c is less than 16 and greater than 8 I get a 8 bar histogram

None of the above results occur if I change to a full color image as input.
It does seem strange, though I am getting some similar results for small number of grayscale values. I will have to look into this further, tomorrow.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

I just posted a potential bug report on color quantization of grayscale images.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: spectrumhist and greyscales

Post by fmw42 »

I have modified the script to use -posterize when color reducing grayscale images. I also added a background color argument. So give this a try and see if that gets what you want.
greengrass
Posts: 10
Joined: 2014-03-31T18:50:34-07:00
Authentication code: 6789

Re: spectrumhist and greyscales

Post by greengrass »

fmw42 wrote:I just posted a potential bug report on color quantization of grayscale images.
Hi Fred,

It might be of interest and germane to this problem. I was checking the number of 'colors' in a grayscale image using GIMP. I was comparing IM -colorspace Gray with GIMP desaturate. IM conversion had 251 unique colors according to GIMP. The desaturate GIMP image had 256.

I hope this helps.

I'll also give your new script a spin.
Post Reply