Scaling just one channel

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
b3and1p
Posts: 25
Joined: 2010-12-07T17:25:08-07:00
Authentication code: 8675308

Scaling just one channel

Post by b3and1p »

Hi everyone. I want to create a chromatic aberration effect in IM. I want to scale the blue channel and the green channel from the center at different amounts, how would I go about doing this? For instance lets say I want to scale the blue channel 2% and the green channel 1% while leaving the red channel untouched. Can this be done in one command? Thanks guys!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scaling just one channel

Post by fmw42 »

See clones and parenthesis process at http://www.imagemagick.org/Usage/basics/#parenthesis

convert image -channel rgb -separate \
\( -clone 1 -distort SRT "1.01 0" \) \
\( -clone 2 -distort SRT "1.02 0" \) \
-delete 1-2 -combine result

This shows little change, but if you exaggerate the scaling to say 1.1 and 1.2, then you can see the changes very well.

So, the above seems to work OK; whereas using -resize in place of -distort SRT gives an error about the images that are to be combined are not the same size.
b3and1p
Posts: 25
Joined: 2010-12-07T17:25:08-07:00
Authentication code: 8675308

Re: Scaling just one channel

Post by b3and1p »

Do you have to put the first "\" characters in there for it to work? Or is that just so you can have a new line?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Scaling just one channel

Post by GreenKoopa »

( and ) have to be escaped to \( and \) on Linux, % must be escaped to %% in Windows batch files. Line continuation is \ on Linux, ^ on Windows.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Scaling just one channel

Post by anthony »

see Using IM on Windows, DOS scripts...
http://www.imagemagick.org/Usage/windows/#scripts
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
b3and1p
Posts: 25
Joined: 2010-12-07T17:25:08-07:00
Authentication code: 8675308

Re: Scaling just one channel

Post by b3and1p »

I got this error in my log. Do I have the wrong version of IM installed? Did I format something incorrectly?

[2010-12-10T16:29:34+00:00] Executing '/usr/local/bin/convert imageA.jpg -channel rgb -separate \( -clone 1 -distort SRT 1.01 0 \) \( -clone 2 -distort SRT 1.02 0 \) -delete 1-2 -combine result -quality 100 "/home/test/public_html/ImageB.jpg"'
[2010-12-10T16:30:12+00:00] Return error. Output:
[2010-12-10T16:30:12+00:00]
Errors:
convert: unable to open image `0': @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `0' @ error/constitute.c/ReadImage/532.
convert: unable to open image `0': @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `0' @ error/constitute.c/ReadImage/532.
convert: unable to open image `result': @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `result' @ error/constitute.c/ReadImage/532.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Scaling just one channel

Post by Bonzo »

Try putting the distort options within " " e.g. -distort SRT "1.01 0"
b3and1p
Posts: 25
Joined: 2010-12-07T17:25:08-07:00
Authentication code: 8675308

Re: Scaling just one channel

Post by b3and1p »

Hmm, still not working.

[2010-12-11T16:06:04+00:00] Executing '/usr/local/bin/convert imageA.jpg -channel rgb -separate \( -clone 1 -distort SRT "1.01 0" \) \( -clone 2 -distort SRT "1.02 0" \) -delete 1-2 -combine result -quality 100 "/home/test/public_html/imageB.jpg"'
[2010-12-11T16:06:07+00:00] Return error. Output:
[2010-12-11T16:06:07+00:00]
Errors:
convert: unable to open image `result': @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `result' @ error/constitute.c/ReadImage/532.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scaling just one channel

Post by fmw42 »

What IM version and platform are you using? Is it old? Are directories set up for the write permission?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Scaling just one channel

Post by GreenKoopa »

b3and1p wrote:Hmm, still not working.

[2010-12-11T16:06:04+00:00] Executing '/usr/local/bin/convert imageA.jpg -channel rgb -separate \( -clone 1 -distort SRT "1.01 0" \) \( -clone 2 -distort SRT "1.02 0" \) -delete 1-2 -combine result -quality 100 "/home/test/public_html/imageB.jpg"'
What does result do? It reads like an input file, but this doesn't look like your intent.
/usr/local/bin/convert imageA.jpg -channel rgb -separate \( -clone 1 -distort SRT "1.01 0" \) \( -clone 2 -distort SRT "1.02 0" \) -delete 1-2 -combine result -quality 100 "/home/test/public_html/imageB.jpg"
b3and1p
Posts: 25
Joined: 2010-12-07T17:25:08-07:00
Authentication code: 8675308

Re: Scaling just one channel

Post by b3and1p »

Yea I am dumb! I didn't realise "result" was the output because I didn't see a .png. Sorry, stupid mistake on my part.

And this works! I wanted a subtle effect. here is what it looks like:
http://placesnapdev02.s3.amazonaws.com/ ... 2de1_o.jpg

here it is without that effect:
http://placesnapdev02.s3.amazonaws.com/ ... 4748_o.jpg

You can really see it towards the edges of the picture. Thanks guys! I ended up using 1.005 and 1.01. I wanted it to be really subtle like a real chromatic aberration.
Post Reply