how to sort the data histogram: descending?

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
Nezar
Posts: 14
Joined: 2010-05-19T00:03:19-07:00
Authentication code: 8675308

how to sort the data histogram: descending?

Post by Nezar »

Please, I'm sorry for my English - translated text translator

I need to sort the data histogram: descending
Ie from

Code: Select all

 15: (4, 4, 4.255) # 040404 rgba (4,4,4,1) 
         4: (7, 7, 7,255) # 070707 rgba (7,7,7,1) 
        20: (8, 8, 8.255) # 080808 grey3 
I need to get a txt file

Code: Select all

 20: (8, 8, 8.255) # 080808 grey3 
        15: (4, 4, 4.255) # 040404 rgba (4,4,4,1) 
         4: (7, 7, 7,255) # 070707 rgba (7,7,7,1) 
tried
convert tree.gif-format% c histogram: info: - | sort-r-k 1
fails
if you do so
convert tree.gif-format% c histogram: info: - | sort
some sort - but ascending

Please tell my how to solve the problem.

And another question
possible to derive a txt file only the maximum number of pixels of one color
for this example - 20
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to sort the data histogram: descending?

Post by fmw42 »

You have not been careful about spaces:

try


convert tree.gif -format "%c" histogram:info:- | sort -r -k 1

422: ( 0,255,255) #00FFFF cyan
381: ( 50,205, 50) #32CD32 LimeGreen
126: ( 46,139, 87) #2E8B57 SeaGreen
59: (160, 82, 45) #A0522D sienna
20: (255,255, 0) #FFFF00 yellow
16: ( 0,128, 0) #008000 green


This will send to a file:


convert tree.gif -format "%c" histogram:info:- | sort -r -k 1 > sort.txt

This will give the first line from the sort with the largest count:


convert tree.gif -format "%c" histogram:info:- | sort -r -k 1 | head -n 1

422: ( 0,255,255) #00FFFF cyan



This will get just the count (and remove the leading spaces):

convert tree.gif -format "%c" histogram:info:- | sort -r -k 1 | head -n 1 | cut -d: -f 1 | sed 's/ //g'

422
Nezar
Posts: 14
Joined: 2010-05-19T00:03:19-07:00
Authentication code: 8675308

Re: how to sort the data histogram: descending?

Post by Nezar »

convert tree.gif -format "%c" histogram:info:- | sort -r -k 1
does not work and gives an error - input file is determined by the double

convert tree.gif -format "%c" histogram:info:- | sort -r -k 1 | head -n 1
also an error -
"head" is not an internal or external
command, operable program or batch file.


at varying - Windous 7
and convert.exe - 6.6.2
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to sort the data histogram: descending?

Post by snibgo »

These are operating system questions, not questions about ImageMagick.

In Windows, "help sort" will show you how to reverse the output ("/R").
snibgo's IM pages: im.snibgo.com
Nezar
Posts: 14
Joined: 2010-05-19T00:03:19-07:00
Authentication code: 8675308

Re: how to sort the data histogram: descending?

Post by Nezar »

snibgo wrote:These are operating system questions, not questions about ImageMagick.

In Windows, "help sort" will show you how to reverse the output ("/R").
/R works! Thank you. I do not know what sort relates to the functions of Windows.
can recommend you the first line in it withdraw? )
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to sort the data histogram: descending?

Post by fmw42 »

My commands above are for unix. Windows users see http://www.imagemagick.org/Usage/windows/
Post Reply