Page 1 of 1
"-distort" and "-channel"
Posted: 2010-04-25T20:18:32-07:00
by snibgo
The "-distort" operator seems to ignore the "-channel" setting.
This would be useful, for example to correct chromatic abberation from some cameras where blue light falls further from the centre than other colours. This could be corrected with:
convert in.png -channel Blue -distort Barrel 0,0,0,1.001 out.png <-- This won't currently work
To prevent breaking scripts that rely on "-distort" ignoring "-channel", I suggest a new option is added, perhaps "-distort-regard-channel".
Re: "-distort" and "-channel"
Posted: 2010-04-26T10:12:14-07:00
by fmw42
Interesting suggestion. In the mean time you can use -separate
convert in.png -separate \( -clone 2 -distort Barrel 0,0,0,1.001 \) -swap 1,2 -delete 2 -combine out.png
Re: "-distort" and "-channel"
Posted: 2010-04-26T11:28:40-07:00
by snibgo
Thanks, Fred. Your "-swap 1,2" swaps the green and blue channels, which isn't a great idea, but the general technique is fine. The working equivalent to my non-working example is:
convert in.png -separate \( -clone 2 -distort Barrel 0,0,0,1.001 \) -delete 2 -combine out.png
Re: "-distort" and "-channel"
Posted: 2010-04-26T12:14:42-07:00
by fmw42
your method is better. my method is overkill and erroneous as you point out. but my method would work if I used -swap 2,3 -delete 3 as I was trying to swap the modified blue with the original blue and then deleted the original blue which now is the last image.
Re: "-distort" and "-channel"
Posted: 2010-04-26T18:42:35-07:00
by anthony
snibgo wrote:The "-distort" operator seems to ignore the "-channel" setting.
-channel is only used for operators that deal with images as greyscale. That is each channel is handled separateally from each other. Blur (Convolution), Morphology, Level, Normalize, FX, Evaluate, Function, etc all handle images as a greyscale array of values, and so the channel setting is applied.
However operators that only deal with pixels, as a whole, do not use -channel. Distort, Resize, Scale, Rotate, and the Duff-Porter Alpha Composition Methods, are all examples of this. None of these use the 'channel' setting.
Now if you had requested that Mathematical Composition Operators (multiply, add, plus, etc...) to understand 'channel' setting, then YES that is a BUG. It is also something that I will need to go in a fix soon too, as Morphology is requiring the use of Mathematical Composition with channel sensitivity. That internal API has it available, just not used at this point.
Re: "-distort" and "-channel"
Posted: 2010-04-26T18:48:51-07:00
by anthony
fmw42 wrote:your method is better. my method is overkill and erroneous as you point out. but my method would work if I used -swap 2,3 -delete 3 as I was trying to swap the modified blue with the original blue and then deleted the original blue which now is the last image.
The normal technique for modifying a image in a sequence, (or in this case a channel) is...
Code: Select all
.... \( -clone N .... \) -swap N +delete ...
Where 'N' is the image number (starting at zero) to modify
Or for OLDER versions of IM (before v6.4) before a 'single argument' form of swap was added...
Code: Select all
.... \( -clone N .... \) -swap -1,N +delete ...
The -1 means the 'last' image whcih is the one you just cloned and modified. The alturnative (and the original method
before -swap was created) requires 'N' to be given three times...
Code: Select all
.... \( -clone N .... \) -delete N -insert N ...
For more detail see
Combining and Debugging Complex Image Operations
http://www.imagemagick.org/Usage/basics/#seq_combine
Re: "-distort" and "-channel"
Posted: 2010-04-26T19:26:00-07:00
by fmw42
Anthony,
Out of curiosity, what is not acceptable or less acceptable about just deleting an intermediate image rather than the last one in the sequence as per the way user snibgo suggested.
Re: "-distort" and "-channel"
Posted: 2010-04-26T19:48:31-07:00
by anthony
fmw42 wrote:Anthony,
Out of curiosity, what is not acceptable or less acceptable about just deleting an intermediate image rather than the last one in the sequence as per the way user snibgo suggested.
For that specific case YES that is acceptable. but for the general case (image is in middle rather than at the end)
then the -swap should be used.
Re: "-distort" and "-channel"
Posted: 2010-04-26T20:11:00-07:00
by fmw42
Anthony wrote:but for the general case (image is in middle rather than at the end)
then the -swap should be used.
Why? Can you give an example where it is bad to delete from the middle?
Re: "-distort" and "-channel"
Posted: 2010-05-05T21:50:18-07:00
by anthony
anthony wrote:Now if you had requested that Mathematical Composition Operators (multiply, add, plus, etc...) to understand 'channel' setting, then YES that is a BUG. It is also something that I will need to go in a fix soon too, as Morphology is requiring the use of Mathematical Composition with channel sensitivity. That internal API has it available, just not used at this point.
This has been submitted (IM v6.6.1-6) and documentation updated. Channel handling for Mathematical Compose operations is enabled when you use
-channel without setting a
'Sync' flag. The
'Sync' flag is enabled by default when users have not specified a channel setting or rest it using
+channel (default channel setting is
'RGBK,Sync').
The flag means 'syncronize' cross-channel handling within operations. For some operations it means applying the same operation to all color channels together (-auto-level and -auto-gamma) for others (like compose maths methods) it means making the appropriate changes with regard to the alpha channel (typically color weighting by the alpha value). Many operators are properly test this flag.