combining commands

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
publikus
Posts: 5
Joined: 2015-10-15T05:59:21-07:00
Authentication code: 1151

combining commands

Post by publikus »

Hi
How can I combine these two imagemagick command into one. I want to compare two images by columns. I thing I'am wasting too much time to write results to a disk.

set /a "width = 1600"
set /a "height = 1200"
set /a "column = 5"
set /a "x = 0"

:while1
if %x% < %width% (
set /a "x = x + %column%"
convert sample.mpc -crop %column%x%height%+%x%+0 sample/cropped%x%.mpc
convert test.mpc -crop %column%x%height%+%x%+0 test/cropped%x%.mpc
compare -metric AE -fuzz 2%% sample/cropped%x%.mpc test/cropped%x%.mpc null 2>>differences.txt
goto :while1
)

Thank you so much for your help!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: combining commands

Post by snibgo »

You can combine these three ...

Code: Select all

convert sample.mpc -crop %column%x%height%+%x%+0 sample/cropped%x%.mpc

convert test.mpc -crop %column%x%height%+%x%+0 test/cropped%x%.mpc

compare -metric AE -fuzz 2%% sample/cropped%x%.mpc test/cropped%x%.mpc null 2>>differences.txt
... into one convert. (Windows BAT syntax, untested.)

Code: Select all

convert ^
  ( sample.mpc -crop %column%x%height%+%x%+0 ) ^
  ( test.mpc -crop %column%x%height%+%x%+0 ) ^
  -metric AE ^
  -compare ^
  -format %%[distortion] ^
  info: >>differences.txt
(Untested.)

A "for" loop is probably quicker than "goto".

The loop could create a script file that builds just one convert command that reads sample.mpc and test.mpc just once, then does multiple crops (on clones) and comparisons. That would be massively quicker.
snibgo's IM pages: im.snibgo.com
publikus
Posts: 5
Joined: 2015-10-15T05:59:21-07:00
Authentication code: 1151

Re: combining commands

Post by publikus »

Thank you very much!
I'am going to try it out.
publikus
Posts: 5
Joined: 2015-10-15T05:59:21-07:00
Authentication code: 1151

Re: combining commands

Post by publikus »

not working... :(
publikus
Posts: 5
Joined: 2015-10-15T05:59:21-07:00
Authentication code: 1151

Re: combining commands

Post by publikus »

I cant do this without writing converted images to disk.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: combining commands

Post by snibgo »

Do you get any error messages? What is "not working"? What version IM are you on? If it is old, "convert" may not have the "-compare" operator. In that case, as you care only about how many pixels are different, you can "-compose Difference -composite" and change non-black into white and find the mean. This gives the proportion of pixels that are different. Multiply by W*H to get the number that have changed.
snibgo's IM pages: im.snibgo.com
publikus
Posts: 5
Joined: 2015-10-15T05:59:21-07:00
Authentication code: 1151

Re: combining commands

Post by publikus »

It's OK! You syntax is working.
I did make a mistake :)
Thank you one more time!
Post Reply