snibgo's ImageMagick pages

Composite arithmetic

blah.

blah

blah.

Trials

All numbers are percentages of Quantum.

call %PICTBAT%compArith ca_list
dst; src Add Modulus
Add
Plus Subtract Modulus
Subtract
Minus Minus
Dst
Minus
Src
Difference Multiply Divide
Dst
Divide
Src
Lighten Darken
0% ;0% 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0% ;75% 75 75 75 75 75 75 75 0 75 0 100 0 75 0
65% ;0% 65 65 65 35 35 0 0 65 65 0 0 100 65 0
65% ;75% 40 40 100 9.999 9.999 9.999 9.999 0 9.999 48.75 100 86.67 75 65
75% ;0% 75 75 75 25 25 0 0 75 75 0 0 100 75 0
75% ;65% 40 40 100 90 90 0 0 9.999 9.999 48.75 86.67 100 75 65
100% ;0% 100 100 100 0 0 0 0 100 100 0 0 100 100 0
100% ;100% 100 100 100 0 0 0 0 0 0 100 100 100 100 100
100% ;90% 90 90 100 90 90 0 0 10 10 90 90 100 100 90
set caIM=%IMDEV%

call %PICTBAT%compArith ca_list2

set caIM=
dst; src Add Modulus
Add
Plus Subtract Modulus
Subtract
Minus Minus
Dst
Minus
Src
Difference Multiply Divide
Dst
Divide
Src
Lighten Darken
0% ;0% 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0% ;75% 75 75 75 75 75 75 75 0 75 0 100 0 75 0
65% ;0% 65 65 65 35 35 0 0 65 65 0 0 100 65 0
65% ;75% 40 40 100 9.999 9.999 9.999 9.999 0 9.999 48.75 100 86.67 75 65
75% ;0% 75 75 75 25 25 0 0 75 75 0 0 100 75 0
75% ;65% 40 40 100 90 90 0 0 9.999 9.999 48.75 86.67 100 75 65
100% ;0% 100 100 100 0 0 0 0 100 100 0 0 100 100 0
100% ;100% 100 100 100 0 0 0 0 0 0 100 100 100 100 100
100% ;90% 90 90 100 90 90 0 0 10 10 90 90 100 100 90

Blah

Operator Expression Output Comments
Add result = dst + src <= 100% if result > 100%, subtracts 100%.
Plus result = dst + src Any Proper arithmetic.
Minus result = src - dst Any Proper arithmetic.
MinusDst result = src - dst Any Proper arithmetic.
MinusSrc result = dst - src Any Proper arithmetic.
Difference result = abs(dst - src) >= 0 Proper arithmetic.
Multiply result = dst * src Any Proper arithmetic.
Lighten result = max (dst, src) Any Proper arithmetic.
Darken result = min (dst, src) Any Proper arithmetic.
%IM%convert ^
  xc:gray(75%%) ( +clone ) ( +clone ) ^
  -background Black ^
  -compose Add -layers Merge ^
  -precision 4 -format "%%[fx:r*100]" ^
  info:
25
%IMDEV%convert ^
  xc:gray(75%%) ( +clone ) ( +clone ) ^
  -background Black ^
  -compose Add -layers Merge ^
  -precision 4 -format "%%[fx:r*100]" ^
  info:
25

Add: if the inputs are in the range 0 to 100%, the output will also be in that range.

If the input may be outside the range 0 to 100%, no operation can result in modulus 100% (so a value of 120% becomes 20%, and -30% becomes 70%).

However, if an input is in the range 0 to 200%, ADDing it to black will make the output in the range 0 to 100%.

We can easily negate an image: subtract it from black.

We can easily find the absolute of an image: find the difference from black.

See IM forum, reported bug -compose Modulus.

Scripts

For convenience, .bat scripts are also available in a single zip file. See Zipped BAT files.

compArith.bat

set LIST=%1.csv

set OPERS=Add Modulus-Add Plus Subtract Modulus-Subtract Minus Minus-Dst Minus-Src Difference Multiply Divide-Dst Divide-Src Lighten Darken

set sOPERS=%OPERS:-=%

set OPERSCOM=%OPERS: =,%
set OPERSCOM=%OPERSCOM:-=^^^<br /^^^>%

echo sOPERS=%sOPERS%
echo OPERSCOM=%OPERSCOM%

echo dst; src,%OPERSCOM% >%LIST%

call :doOpers 75 65
call :doOpers 75 -65
call :doOpers -65  75
call :doOpers 65 -75
call :doOpers 65 75
call :doOpers -65 -75
call :doOpers 65 0
call :doOpers -65 0
call :doOpers 0 0
call :doOpers 100 0
call :doOpers 165 0
call :doOpers 165 100
call :doOpers 265 0
call :doOpers 265 100
call :doOpers 365 0
call :doOpers 365 90

cSort /i%LIST% /o%LIST% /h /k0,1 /u

type %1.csv

call csv2tab %1

exit /B 0

:doOpers

%IM%convert xc:gray(%1%%) -precision 4 -format "%%[fx:r*100]%%" info:>>%LIST%

%IM%convert xc:gray(%2%%) -precision 4 -format " ;%%[fx:r*100]%%" info:>>%LIST%

for %%P in (%sOPERS%) do call :doArith %1 %2 %%P

%IM%convert xc: -format "\n" info:>>%LIST%

exit /B 0

:doArith

%IM%convert ^
  xc:gray(%1%%) xc:gray(%2%%) ^
  -compose %3 -composite ^
  -precision 4 -format ",%%[fx:r*100]" ^
  info:>>%LIST%

All images on this page were created by the commands shown, using:

%IM%identify -version
Version: ImageMagick 6.9.2-5 Q16 x64 2015-10-31 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180031101
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

To improve internet download speeds, some images may have been automatically converted (by ImageMagick, of course) from PNG to JPG.

Source file for this web page is comparith.h1. To re-create this web page, run "procH1 comparith".


This page, including the images, is my copyright. Anyone is permitted to use or adapt any of the code, scripts or images for any purpose, including commercial use.

Anyone is permitted to re-publish this page, but only for non-commercial use.

Anyone is permitted to link to this page, including for commercial use.


Page version v1.0 23-March-2015.

Page created 05-Jun-2016 06:50:01.

Copyright © 2016 Alan Gibson.