How to Write Histogram to Text File?

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?".
Post Reply
stowball

How to Write Histogram to Text File?

Post by stowball »

How do you write the histogram of an image to a text file?

Taking the examples in the docs...

Code: Select all

convert  tree.gif  -format %c histogram:info:-
shows the histogram, which is 6 different colours on 6 lines, however, using

Code: Select all

convert  tree.gif  -format %c histogram:info:- file.txt
creates a 1026 line file, containing a line for each pixel in the 32x32 image.

Can somebody enlighten me please?

Thanks

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

Re: How to Write Histogram to Text File?

Post by fmw42 »

convert tree.gif -format %c histogram:info:- >2 file.txt
stowball

Re: How to Write Histogram to Text File?

Post by stowball »

Thanks!

I had to remove the "2" though - was that a typo?

Code: Select all

convert tree.gif -format %c histogram:info:- > file.txt
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Write Histogram to Text File?

Post by fmw42 »

Not a typo. The >2 was needed on my Mac OSX (unix) environment and does not work without the 2. Are you on Window? or some other Linux?
stowball

Re: How to Write Histogram to Text File?

Post by stowball »

Hmm. I'm on Windows. Interesting.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Write Histogram to Text File?

Post by fmw42 »

actually I believe more properly on unix it should be

convert tree.gif -format %c histogram:info:- 2>&1 file.txt
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to Write Histogram to Text File?

Post by el_supremo »

I tried that on my WIn XP system and the output does get sent to standard output whereas on the Mac (and Linux?) it would appear that it gets sent to standard error.

Pete
stowball

Re: How to Write Histogram to Text File?

Post by stowball »

fmw42 wrote:actually I believe more properly on unix it should be

convert tree.gif -format %c histogram:info:- 2>&1 file.txt
Trying this on Windows gave me a 90000 line pixel enumeration file.

I think I'll stick with what I have for the time being.

Thanks guys.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to Write Histogram to Text File?

Post by anthony »

Or even better, write it directly to the file, rather than tto stdout/stderr (the meaning of ther '-')

Code: Select all

convert  tree.gif  -format %c histogram:info:file.txt
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply