duboism wrote:Anyway I followed you advice and I have now a working (linux) script
- Code: Select all
filename=`basename $1 .jpg`
# 1st conversion (RGB order)
convert $1 $filename.tmp.ras
# swap channels and write to pnm
convert \( $filename.tmp.ras -channel R -separate \) \
\( $filename.tmp.ras -channel G -separate \) \
\( $filename.tmp.ras -channel B -separate \) -channel BGR -combine $filename.tmp.pnm
# final step
pnmtorast -standard $filename.tmp.pnm > $filename.ras
rm $filename.tmp.ras $filename.tmp.pnm
That 'channel swap' convert does nothing BUT convert the ras to pnm. The -channel setting order has no bearing on the result of the combine at all. It is simply a unordered list of channel flags. That is
-channel BGR means exactly the same thing as
-channel RGBIf you really want to swap channels in that convert you must extract the channels in the order wanted, or swap (reverse) the order of the separate channels. Also you only need to read the image once!
- Code: Select all
# swap channels so RGB become BGR and write to pnm
convert $filename.tmp.ras -separate -reverse -combine $filename.tmp.pnm
See -reverse
http://www.imagemagick.org/Usage/basics/#reverseAn alternative is to use
-swap 0,2 to swap the red and blue channel images.
See the blue rose in the combine examples of IM Examples
http://www.imagemagick.org/Usage/color_basics/#combineThis also explains about the unordered nature of the -channel setting
If your script is working it will be because "pnmtorast" is doing the channel swap as part of its operations.