Page 1 of 1

Clip values of a channel if out of the defined range

Posted: 2015-06-05T00:16:03-07:00
by TiborB
Hi,

I want to convert the image to LAB (this in fact is not important) and set minimum and maximum of AB values the way that values inside the range are not changed and values out of range are set to the range borders..

I am bit familiar with gimp, but it doesnt have this functionality it seems, so I dont know how to name it or what to search for. "Levels" are something different.

Would you help?

Thank

EDIT: I mean each channel is to be treated separately, of course.

Re: Clip values of a channel if out of the defined range

Posted: 2015-06-05T00:43:52-07:00
by snibgo
I'm not sure exactly what you are asking, but the following might help.

The "-channels X" setting makes following operations operate only on the named channels. For X we use R, G or B even if the channel represents L*, a* or b*.

"-evaluate Max N%" will set the value to the maximum of N% or whatever the value currently is. Similarly, "-evaluate Min N%" will set the value to the minimum of N% or whatever the value currently is. (But apparently these meaning will soon be swapped. See viewtopic.php?f=4&t=27769 )

So, to clip the a* channel at 10% and 85%:

Code: Select all

-channel G
-evaluate Max 10%
-evaluate Min 85%
+channel

Re: Clip values of a channel if out of the defined range

Posted: 2015-06-05T01:32:23-07:00
by TiborB
Yes, this look like exactly what I need. I made some experiments because it still doesnt work as I hoped. The simpliest operation is like this:

Code: Select all

convert input.jpg -colorspace HSL -channel G -evaluate Min 10%   -colorspace RGB output.jpg
This seems to work, it limits the saturation. Though that "S" seems to be not visually proportional.

But when I try the similar operation in LAB, it gives strange colors. I tried two commands:

Code: Select all

convert input.jpg -colorspace LAB -channel G -evaluate Min 75% -evaluate Max 25%   -channel B -evaluate Min 75% -evaluate Max 25%  -colorspace RGB output.jpg
convert input.jpg -colorspace LAB -channel G -evaluate Min 25% -evaluate Max -25%   -channel B -evaluate Min 25% -evaluate Max -25%  -colorspace RGB output.jpg
I am not sure if AB channels go from 0%-100" or from -100%-100% and I also presume that "middle" is 50% or 0% alternatively

Could you advice please some circular colorspace like HSV where "S" is more visually proportional? Maybe LAB is not the best idea after all.

Re: Clip values of a channel if out of the defined range

Posted: 2015-06-05T02:16:52-07:00
by snibgo
When you want future operations to affect all channels, you need "+channel".

If you are using integer IM, all values will be within 0 to 100%. The mid-value of the a* and b* channels is 50%.

You might prefer one of the other H* colorspaces, eg HCL, HCLp, HSI, HSL or HSB.

Re: Clip values of a channel if out of the defined range

Posted: 2015-06-05T02:59:03-07:00
by TiborB
snigbo

thanks for all answers, I am still toying with it, the results are not as I expected but at least it is fun :)

Regards