How to combine these commands into one?

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
MILLIONER
Posts: 3
Joined: 2012-01-05T04:53:00-07:00
Authentication code: 8675308

How to combine these commands into one?

Post by MILLIONER »

Hi all! :)

How to combine these commands into one?

Code: Select all

1) convert photo1.jpg -convolve "-1,0,1,-1,0,1,-1,0,1" -fx "abs(u)" edge1.jpg
2) convert photo1.jpg -convolve "1,1,1,0,0,0,-1,-1,-1" -fx "abs(u)" edge2.jpg
3) convert edge1.jpg edge2.jpg -compose plus -composite edge3.jpg
Trying to merge, but the results very different

Code: Select all

convert photo1.jpg \( -clone 0 -convolve "-1,0,1,-1,0,1,-1,0,1" -fx "abs(u)" \) \( -clone 0 -convolve "1,1,1,0,0,0,-1,-1,-1" -fx "abs(v)" -compose plus -composite edge3.jpg
Thank you! :)
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to combine these commands into one?

Post by el_supremo »

You are missing \) just before -compose.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
MILLIONER
Posts: 3
Joined: 2012-01-05T04:53:00-07:00
Authentication code: 8675308

Re: How to combine these commands into one?

Post by MILLIONER »

el_supremo wrote:You are missing \) just before -compose.

Pete
written:

Code: Select all

convert photo1.jpg \( -clone 0 -convolve "-1,0,1,-1,0,1,-1,0,1" -fx "abs(u)" \) \( -clone 0 -convolve "1,1,1,0,0,0,-1,-1,-1" -fx "abs(v)" \) -compose plus -composite edge3.jpg
There are no results. : (
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to combine these commands into one?

Post by fmw42 »

convert photo1.jpg \( -clone 0 -convolve "-1,0,1,-1,0,1,-1,0,1" -fx "abs(u)" \) \( -clone 0 -convolve "1,1,1,0,0,0,-1,-1,-1" -fx "abs(v)" \) -compose plus -composite edge3.jpg

First you only have one image for each convolve, so abs(v) should be abs(u). Second, it appears that you are trying to generate an approximation to a gradient edge operator. However, unless you are in HDRI mode, -fx "abs(u)" will do nothing, since non-HDRI compiles will not allow negative values. Generally one will use -bias 50% before doing this and then compensate later. see viewtopic.php?f=1&t=16158&hilit=sobel and the links within it.

See http://www.imagemagick.org/Usage/convolve/#edgedet as IM has some built in edge detectors.

You can try my script, gradient, at the link below. It has both one-sided and two sided gradients for non-HDRI mode. The one-sided gradient should work as a two sided gradient if you are in HDRI mode, but I have not tested that. You can look at the bottom of my script for the code I used in both cases.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to combine these commands into one?

Post by anthony »

MILLIONER wrote:Hi all! :)

How to combine these commands into one?

Code: Select all

1) convert photo1.jpg -convolve "-1,0,1,-1,0,1,-1,0,1" -fx "abs(u)" edge1.jpg
2) convert photo1.jpg -convolve "1,1,1,0,0,0,-1,-1,-1" -fx "abs(u)" edge2.jpg
3) convert edge1.jpg edge2.jpg -compose plus -composite edge3.jpg
Trying to merge, but the results very different

Code: Select all

convert photo1.jpg \( -clone 0 -convolve "-1,0,1,-1,0,1,-1,0,1" -fx "abs(u)" \) \( -clone 0 -convolve "1,1,1,0,0,0,-1,-1,-1" -fx "abs(v)" -compose plus -composite edge3.jpg
Thank you! :)
The -fx 'abs(u)' will have NO effect unless you are using HDRI version of ImageMagick as image data values are already absolute values! The FX abs function is generally used for modifying the results of other calculations.

Basically as each image processing operation saves the values back into the image data store, whcih is generally Q16 (compile time quality). As these are 16 bit unsigned integers anything outside the range 0 to 65535 will be clipped/burned. No negatives get saved by default.

If you wish to use convolve and preserve or make use of negative results, you will need to either set the appropriate bias and scaling factors. That is not easy with the old -convolve operation, but much more controllable using the newer -morphology Convolve operator.

See IM Examples, Convolve.
http://www.imagemagick.org/Usage/convolve/
which looks at all these problems and more.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply