Compare 2 images, and export the difference to txt 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
philhung
Posts: 6
Joined: 2018-07-15T23:12:11-07:00
Authentication code: 1152

Compare 2 images, and export the difference to txt file

Post by philhung »

Hi All,

I use the command to find the difference between the below 2 images

https://photos.app.goo.gl/HzrdYycdhgbBacZ19
https://photos.app.goo.gl/9ckbkprJwezqDCJM7

Code: Select all

Compare -compose src c:\black1.png c:\black2.png c:\black_diff.png
the below is the output image
https://photos.app.goo.gl/UwNqWWgN3cXWQNjL7

and I want to convert that output image with difference only to be txt file for data processing by the below 2 commands.

output file size very large...

Code: Select all

convert c:\black_diff.png -transparent "#CCCCCC" sparse-color: c:\a.txt
output file contains nothing...

Code: Select all

convert c:\black_diff.png -transparent "#CCCCCC" sparse-color: > c:\b.txt
thanks for your help in advance!!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare 2 images, and export the difference to txt file

Post by snibgo »

black_diff.png already has transparency, and the search for opaque pixels #CCCCCC finds none. You can "-alpha off" to remove any transparency.
snibgo's IM pages: im.snibgo.com
philhung
Posts: 6
Joined: 2018-07-15T23:12:11-07:00
Authentication code: 1152

Re: Compare 2 images, and export the difference to txt file

Post by philhung »

Many thanks for your reply.
I still have few questions

1. how we know that black_dif.png with transparency?? is it I use Compare to find the difference??
2. I tried the below command with -alpha off, just want to make sure my understanding is correct

Code: Select all

convert c:\black_diff.png -transparent "#CCCCCC" -alpha off sparse-color: > c:\b.txt
thanks!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare 2 images, and export the difference to txt file

Post by snibgo »

You should turn alpha off before the search:

Code: Select all

convert c:\black_diff.png -alpha off -transparent "#CCCCCC" sparse-color: > c:\b.txt
snibgo's IM pages: im.snibgo.com
philhung
Posts: 6
Joined: 2018-07-15T23:12:11-07:00
Authentication code: 1152

Re: Compare 2 images, and export the difference to txt file

Post by philhung »

many thanks for your support!!!
Post Reply