Getting different results when using -channel to contrast-stretch

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
aytac0x
Posts: 2
Joined: 2015-06-09T06:55:24-07:00
Authentication code: 6789

Getting different results when using -channel to contrast-stretch

Post by aytac0x »

I am getting different result when I apply -contrast-strect 0 on a single channel by using -channel operator and when I use -contrast-strecth after I separate the channels. Any hints why this is the case?

I tried this with LAB LCHab and HSL using latest imagemagick on arch linux.
original image: https://dl.dropboxusercontent.com/u/22023572/a3.png

Using -channel

Code: Select all

convert img.png -colorspace LAB -channel L -contrast-stretch 0 -colorspace sRGB img_lab_only_L_auto.png
result: https://dl.dropboxusercontent.com/u/220 ... uto_a3.png

Doing it "by hand"

Code: Select all

convert img.png -colorspace LAB -separate img_lab_channel_%d.png
convert img_lab_channel_0.png -contrast-stretch 0 img_lab_channel_0_stretched.png
convert img_lab_channel_0_stretched.png img_lab_channel_1.png img_lab_channel_2.png -set colorspace LAB -combine -colorspace sRGB img_lab_only_L.png
result: https://dl.dropboxusercontent.com/u/220 ... y_L_a3.png

Any ideas?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting different results when using -channel to contrast-stretch

Post by snibgo »

Annoyingly, "-channel L" is a synonym for "-channel B", ie the third channel, not the first channel. Use "-channel R" instead.

EDIT: I said "-channel G" but meant "-channel B".
snibgo's IM pages: im.snibgo.com
aytac0x
Posts: 2
Joined: 2015-06-09T06:55:24-07:00
Authentication code: 6789

Re: Getting different results when using -channel to contrast-stretch

Post by aytac0x »

Hmm so L is the L in HSL. At first I thought the problem was about the Sync flag for -channel.

When I looked at the output of

Code: Select all

convert -list channel
i can see A and B as well. That was misleading, So A is for Alpha and B is for Black?

edit: B must be for Blue, I am overthinking... :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting different results when using -channel to contrast-stretch

Post by snibgo »

A is for Alpha
B is for Blue (the third channel, whatever colour model)

I only ever use R, G, B and A. If I did CMYK work, I would also use those.
snibgo's IM pages: im.snibgo.com
Post Reply