Compare result text file size is huge

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
philhung
Posts: 6
Joined: 2018-07-15T23:12:11-07:00
Authentication code: 1152

Compare result text file size is huge

Post by philhung »

Hi all,

I am new to ImageMagicK

I use the below command to compare 2 pdf files and generate the difference to the text file.

Code: Select all

convert c:\QG1.pdf null: c:\QG2.pdf -compose Difference -layers composite c:\diff.txt
but the output text file size is very large, sometimes over 200m bytes.
I look into the text file, the text file not only contain the differences, but the pixels with no difference.
I think this is the reason why the output file size is so large...

is it possible that the output text file with difference only, or any other smart way using ImageMagicK to compare 2 pdf to text file??

thanks a lot in advance!!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare result text file size is huge

Post by snibgo »

Writing to "txt:" output always gives all of the pixels. In your case, the black pixels are the same in both inputs, so you can process the output in an external filter (such a grep, or Windows findstr) to remove those pixels.

Another option is to make black pixels transparent ("-transparent black"), then to output to "sparse-color:" which doesn't output transparent pixels.
snibgo's IM pages: im.snibgo.com
philhung
Posts: 6
Joined: 2018-07-15T23:12:11-07:00
Authentication code: 1152

Re: Compare result text file size is huge

Post by philhung »

thanks for your help.

I tried to output the difference to image file

Code: Select all

convert c:\QG1.pdf null: c:\QG2.pdf -compose Difference -layers composite c:\diff.png
and then convert that image file to txt file with ("-transparent black") and ("sparse-color:")

Code: Select all

convert c:\diff.png -transparent white sparse-color c:\diff.txt
the below are some lines of the output files

Code: Select all

406,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
407,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
408,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
409,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
410,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
411,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
412,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
413,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
414,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
415,0: (65535,65535,65535,0)  #FFFFFFFFFFFF0000  srgba(255,255,255,0)
I think I make something wrong when using ("sparse-color:")...
thanks again for your help in advance, thanks!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compare result text file size is huge

Post by fmw42 »

You are confusing -sparse-color with sparse-color:

See http://www.imagemagick.org/Usage/files/#sparse-color

Try:

Code: Select all

convert c:\diff.png -transparent white sparse-color: > c:\diff.txt
But that will give one long string.

In unix, you can pipe to tr to change the space to a new line, for example:

Code: Select all

convert logo: -transparent white sparse-color: | tr " " "\n" > diff.txt
I do not know if Windows has an equivalent.
philhung
Posts: 6
Joined: 2018-07-15T23:12:11-07:00
Authentication code: 1152

Re: Compare result text file size is huge

Post by philhung »

many thanks for support, it works perfectly, thanks again
PhillpZeng
Posts: 4
Joined: 2018-07-20T02:16:20-07:00
Authentication code: 1152

Re: Compare result text file size is huge

Post by PhillpZeng »

convert c:\diff.png -transparent white sparse-color: > c:\diff.txt
this command did not work to my PNG files, I just get an empty txt file.
is there anything else should I pay attentions?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare result text file size is huge

Post by snibgo »

If the input c:\diff.png is entirely white then the output should be empty.

Do you get any error message?

For more help, please provide a link to the input, and tell us what version of IM you are using, on what platform.
snibgo's IM pages: im.snibgo.com
PhillpZeng
Posts: 4
Joined: 2018-07-20T02:16:20-07:00
Authentication code: 1152

Re: Compare result text file size is huge

Post by PhillpZeng »

it is not entirely white, just an extra word in png.

the command as this:

Code: Select all

Compare -compose src A.pdf B.pdf AB.png

Code: Select all

convert AB.png -transparent white sparse-color: > AB.txt
is there any problem?

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

Re: Compare result text file size is huge

Post by fmw42 »

How can we comment about your command without having your two input images to see what is going on.

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
Post Reply