Filter the output file when converting to text

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?".
Locked
etrader
Posts: 21
Joined: 2012-09-29T06:53:04-07:00
Authentication code: 67789

Filter the output file when converting to text

Post by etrader »

I convert greyscale images to txt files to analyse their bitmap coordinates. Since there is a line for each pixel, the files are huge, and obviously, I prefer to reduce the files by omitting unnecessary data. Albeit, I can remove unnecessary data by post-processing, but it is reasonable to avoid writing unnecessary data in the first place.

1. Is it possible to limit the output to grey/black pixels by avoiding white pixels?

2. The output has the colours in three formats:

218,75: (0,0,0) #000000 black
219,75: (65535,65535,65535) #FFFFFF white

Can I omit the colours in the output or limit them to one format only?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Filter the output file when converting to text

Post by snibgo »

What version of IM, on what platform?
etrader wrote:The output has the colours in three formats:
But you show only two.

You could make white transparent, then write to "sparse-color:".
snibgo's IM pages: im.snibgo.com

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

Re: Filter the output file when converting to text

Post by fmw42 »

On Unix-like platforms, you can use grep to filter:

Code: Select all

convert -size 10x10 gradient: txt: | grep -v "srgb"
0,0: (65535,65535,65535) #FFFFFFFFFFFF white
1,0: (65535,65535,65535) #FFFFFFFFFFFF white
2,0: (65535,65535,65535) #FFFFFFFFFFFF white
3,0: (65535,65535,65535) #FFFFFFFFFFFF white
4,0: (65535,65535,65535) #FFFFFFFFFFFF white
5,0: (65535,65535,65535) #FFFFFFFFFFFF white
6,0: (65535,65535,65535) #FFFFFFFFFFFF white
7,0: (65535,65535,65535) #FFFFFFFFFFFF white
8,0: (65535,65535,65535) #FFFFFFFFFFFF white
9,0: (65535,65535,65535) #FFFFFFFFFFFF white
0,9: (0,0,0) #000000000000 black
1,9: (0,0,0) #000000000000 black
2,9: (0,0,0) #000000000000 black
3,9: (0,0,0) #000000000000 black
4,9: (0,0,0) #000000000000 black
5,9: (0,0,0) #000000000000 black
6,9: (0,0,0) #000000000000 black
7,9: (0,0,0) #000000000000 black
8,9: (0,0,0) #000000000000 black
9,9: (0,0,0) #000000000000 black

etrader
Posts: 21
Joined: 2012-09-29T06:53:04-07:00
Authentication code: 67789

Re: Filter the output file when converting to text

Post by etrader »

snibgo wrote:
2020-02-21T01:15:44-07:00
What version of IM, on what platform?
etrader wrote:The output has the colours in three formats:
But you show only two.

You could make white transparent, then write to "sparse-color:".
Aren't they three? RGB in the parenthesis, RGB hex, and the colour name. :D

ImageMagick 7.0.8-34 on Ubuntu.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Filter the output file when converting to text

Post by snibgo »

Sorry, my mistake, I read "three formats" as "three colours".
snibgo's IM pages: im.snibgo.com

Locked