how we combine LAB or HSB channels from different pictures?

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
nitrofurano
Posts: 8
Joined: 2011-02-13T07:37:10-07:00
Authentication code: 8675308

how we combine LAB or HSB channels from different pictures?

Post by nitrofurano »

hi! i'm struggling on combining, for example, L channel from picture1 and AB from picture2, in a picture 3 - how can we do it?
the idea is copying the luminance from one picture, and the chrominance from other, both in the same pixel size

i tried this, but the result is really weird

Code: Select all

convert pic1.png -colorspace LAB -channel R -separate pic1_L.png
convert pic1.png -colorspace LAB -channel G -separate pic1_A.png
convert pic1.png -colorspace LAB -channel B -separate pic1_B.png
convert pic2.png -colorspace LAB -channel R -separate pic2_L.png
convert pic2.png -colorspace LAB -channel G -separate pic2_A.png
convert pic2.png -colorspace LAB -channel B -separate pic2_B.png #- it's weird that we need to use -channel "R", "G" and "B" instead of "L", "A" and "B"
convert pic1_L.png pic2_A.png pic2_B.png -set colorspace LAB -colorspace RGB -combine combined.png
#- convert pic1_L.png pic1_A.png pic1_B.png -set colorspace LAB -colorspace RGB -combine combined.png #- for checking if combined.png is exactly the same as pic1.png - the result is really weird
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how we combine LAB or HSB channels from different pictur

Post by snibgo »

This is wrong:

Code: Select all

convert pic1_L.png pic2_A.png pic2_B.png -set colorspace LAB -colorspace RGB -combine combined.png
It should be:

Code: Select all

convert pic1_L.png pic2_A.png pic2_B.png -combine -set colorspace LAB -colorspace sRGB combined.png
You need to combine before changing colorspace, and change it to sRGB not RGB.
snibgo's IM pages: im.snibgo.com
nitrofurano
Posts: 8
Joined: 2011-02-13T07:37:10-07:00
Authentication code: 8675308

Re: how we combine LAB or HSB channels from different pictur

Post by nitrofurano »

snibgo wrote:This is wrong:

Code: Select all

convert pic1_L.png pic2_A.png pic2_B.png -set colorspace LAB -colorspace RGB -combine combined.png
It should be:

Code: Select all

convert pic1_L.png pic2_A.png pic2_B.png -combine -set colorspace LAB -colorspace sRGB combined.png
You need to combine before changing colorspace, and change it to sRGB not RGB.
thanks, it makes sense!

but when i try (with pic1.png only):

Code: Select all

convert pic1_L.png pic1_A.png pic1_B.png -combine -set colorspace LAB -colorspace sRGB combined.png
the colours of combined.png are somehow different from pic1.png, it looks more saturated, dark and blueish... :S (i wished to have the most closest result as possible, of course counting with the lose of quality resulted from RGB-LAB-sRGB colourspace conversion, but not on the colour "calibration" this way, so notably different. :S )
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how we combine LAB or HSB channels from different pictur

Post by snibgo »

Testing my method on a single sample image, I get no visual difference.

What version of IM are you using, on what platform? I'm using v6.8.7-0 on Windows 7.
snibgo's IM pages: im.snibgo.com
nitrofurano
Posts: 8
Joined: 2011-02-13T07:37:10-07:00
Authentication code: 8675308

Re: how we combine LAB or HSB channels from different pictur

Post by nitrofurano »

snibgo wrote:Testing my method on a single sample image, I get no visual difference.

What version of IM are you using, on what platform? I'm using v6.8.7-0 on Windows 7.
Synaptic says 8:6.7.7.10-5ubuntu3 - it's on Lubuntu 13.10
(i also have Crunchbang-Jessie installed on another partition, i didn't tried there, but i imagine it will behave in the same way)


the test picture, pic1.png , i used was this: http://img34.imageshack.us/img34/5001/i8ld.png (a sea city from Jacque Fresco)
the result was http://img594.imageshack.us/img594/3460/57mw.png (you can see how different it become)


btw, i also tried this:

Code: Select all

#!/bin/bash
convert pic1.png -colorspace YUV -channel R -separate pic1_Y.png
convert pic1.png -colorspace YUV -channel G -separate pic1_U.png
convert pic1.png -colorspace YUV -channel B -separate pic1_V.png
convert pic2.png -colorspace YUV -channel R -separate pic2_Y.png
convert pic2.png -colorspace YUV -channel G -separate pic2_U.png
convert pic2.png -colorspace YUV -channel B -separate pic2_V.png
convert pic1_Y.png pic1_U.png pic1_V.png -combine -set colorspace YUV -colorspace sRGB combined_yuv.png
#convert pic1_Y.png pic2_U.png pic2_V.png -combine -set colorspace YUV -colorspace sRGB combined_yuv.png
and the result is as green as "incredible hulk"... :S - http://img801.imageshack.us/img801/5238/7k1p.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how we combine LAB or HSB channels from different pictur

Post by fmw42 »

convert pic1_L.png pic1_A.png pic1_B.png -combine -set colorspace LAB -colorspace sRGB combined.png
I believe this should be -set colorspace LAB before -combine and -colorspace sRGB after the -combine. See http://www.imagemagick.org/Usage/color_ ... bine_other

convert pic1_L.png pic1_A.png pic1_B.png -set colorspace LAB -combine -colorspace sRGB combined.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how we combine LAB or HSB channels from different pictur

Post by snibgo »

v6.7.7 is old. I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how we combine LAB or HSB channels from different pictur

Post by fmw42 »

snibgo wrote:v6.7.7 is old. I suggest you upgrade.

I am not sure LAB was clean in that old a version.

From the changelog:

2012-07-02 6.7.8-2 Cristy <quetzlzacatenango@image...>
Change LAB encoding to permit blurring, resize, etc. (signed A and B channel values now stored using a 50% bias)
Additional.. This removes a non-linear discontinuity from stored LAB space values. As a result you can now Blur, Compose, Resize and Distort in LAB colorspace, without problems that previously existed.


2012-06-09 6.7.7-8 Cristy <quetzlzacatenango@image...>
XYZ and Lab colorspace conversion tweaked (reference viewtopic.php?f=3&t=21161).


2010-05-17 6.6.2-0 Cristy <quetzlzacatenango@image...>
Make sure Lab => RGB => Lab survives the round trip.


2010-04-15 6.6.1-4 Cristy <quetzlzacatenango@image...>
Revert Lab-to-XYZ colorspace transform patch.


2009-08-06 6.5.4-10 Cristy <quetzlzacatenango@image...>
(ab) of Lab colorspace was not offset correctly.
nitrofurano
Posts: 8
Joined: 2011-02-13T07:37:10-07:00
Authentication code: 8675308

Re: how we combine LAB or HSB channels from different pictur

Post by nitrofurano »

fmw42 wrote:
convert pic1_L.png pic1_A.png pic1_B.png -combine -set colorspace LAB -colorspace sRGB combined.png
I believe this should be -set colorspace LAB before -combine and -colorspace sRGB after the -combine. See http://www.imagemagick.org/Usage/color_ ... bine_other

convert pic1_L.png pic1_A.png pic1_B.png -set colorspace LAB -combine -colorspace sRGB combined.png
the result is the same... :S
nitrofurano
Posts: 8
Joined: 2011-02-13T07:37:10-07:00
Authentication code: 8675308

Re: how we combine LAB or HSB channels from different pictur

Post by nitrofurano »

fmw42 wrote:
snibgo wrote:v6.7.7 is old. I suggest you upgrade.

I am not sure LAB was clean in that old a version.

From the changelog:

2012-07-02 6.7.8-2 Cristy <quetzlzacatenango@image...>
Change LAB encoding to permit blurring, resize, etc. (signed A and B channel values now stored using a 50% bias)
Additional.. This removes a non-linear discontinuity from stored LAB space values. As a result you can now Blur, Compose, Resize and Distort in LAB colorspace, without problems that previously existed.


2012-06-09 6.7.7-8 Cristy <quetzlzacatenango@image...>
XYZ and Lab colorspace conversion tweaked (reference viewtopic.php?f=3&t=21161).


2010-05-17 6.6.2-0 Cristy <quetzlzacatenango@image...>
Make sure Lab => RGB => Lab survives the round trip.


2010-04-15 6.6.1-4 Cristy <quetzlzacatenango@image...>
Revert Lab-to-XYZ colorspace transform patch.


2009-08-06 6.5.4-10 Cristy <quetzlzacatenango@image...>
(ab) of Lab colorspace was not offset correctly.
thanks!
btw, how can i install? 6.6.7 is the last one from the repository... (and the .rpm version available officially i don't know if i'm going to have problems with dependencies...) is there any ubuntu-ppa where from i can install, or some .deb, embedded .sh or tarball installer? or i really have to compile the sources?
Post Reply