swap colors/channels

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?".
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

swap colors/channels

Post by Tosyk »

hello, how can i swap, for example ALPHA channel and BLUE channel, or BLUE channel and GREEN channel?

can't find the solution, but it should be simle i'm sure! :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: swap colors/channels

Post by fmw42 »

see http://www.imagemagick.org/Usage/basics/#swap

convert image -separate -swap 0,1 -combine result

this will swap the red and green channels
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

ha, i know that, i just thought that i can use other technic than this
but i don't understand why all channel (rgb) became so dark after combining?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: swap colors/channels

Post by fmw42 »

What version of IM are you using?

After IM 6.7.8.2, separate (grayscale) channels are linear rather than non-linear. To keep them non-linear add -set colorspace RGB before -separate

try

convert image -set colorspace RGB -separate -swap 0,1 -combine result

or just convert back to sRGB after the combine

convert image -separate -swap 0,1 -combine -colorspace sRGB result


see
viewtopic.php?f=4&t=21269
Last edited by fmw42 on 2012-09-11T20:17:07-07:00, edited 1 time in total.
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

i'm useing latest 6.7.9-4 version
and now everything works brilliant, thank you very much!

will use this technic for all my needs :D
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: swap colors/channels

Post by fmw42 »

User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

oh, thank u, very usefull info
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

strange, i can't swap ALPHA channel with other RGB channel for some reason

strings: -separate +swap 0,2 -combine -colorspace sRGB

snd

-separate -swap 1,3 -combine -colorspace sRGB

please help me
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: swap colors/channels

Post by fmw42 »

add -channel rgba -alpha on before the -separate. not sure if -alpha on is needed, but it won't hurt

Note r=0, g=1, b=2 and a=3 in terms of channels in -swap
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

oh, thank you, i will try this :)
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

hm, strange, it actual copying but copied channel looks strange:

Image

i used this commands:
-channel rgba -alpha on -separate -swap 1,3 -combine -fill "#ffffff" -colorize 0,0,100 -alpha off -colorspace sRGB
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: swap colors/channels

Post by fmw42 »

Perhaps you should post a link to your original image and explain why you are doing that and why the result looks wrong.
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

fmw42 wrote:Perhaps you should post a link to your original image and explain why you are doing that and why the result looks wrong.
you right
here is original image
https://dl.dropbox.com/u/9919707/tempor ... 0807_4.dds

i'm trying to swap green and alpha channels, fill blue channel with blue and kill alpha channel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: swap colors/channels

Post by fmw42 »

try this, seems to work for me

# enable rgba, separate channels, swap g and alpha, delete new alpha, combine
# select channel b and make uniform white, reenable rgb channels
# convert to sRGB
convert Tex_0807_4.dds \
-channel rgba -separate +channel -swap 1,3 +delete -combine \
-channel B -evaluate set 100% +channel \
-colorspace sRGB Tex_0807_4_swap.png

Image
Last edited by fmw42 on 2012-09-22T10:34:51-07:00, edited 1 time in total.
User avatar
Tosyk
Posts: 25
Joined: 2012-09-11T18:55:12-07:00
Authentication code: 67789
Location: Armenia

Re: swap colors/channels

Post by Tosyk »

thank you, but i keep getting those artifacts :?
Post Reply