Page 1 of 1
Feathered mask
Posted: 2016-10-07T08:04:56-07:00
by mikmach
I've refined command from my previous post to form:
Code: Select all
convert file.tif -channel H -fx "hue < 0.917 && hue > 0.083 && saturation > 0.10 ? r * 0.97 : r" +channel file-fx.tif
But I have two problems:
1. -fx takes terribly long time to work, on big files it really adds up
2. It creates sharp border. 0.97 translates to ca. 7-8 levels on 8 bit images (BTW - how IM rounds up levels in this case - any way to know it?)
Solution to second problem could be creation of mask, feather it a bit, lower reds in underlaying layer and at last apply mask. But: Is it possible to create mask without -fx in this case? If -fx is still necessary it will only increase length of processing.
My version of IM:
Code: Select all
Version: ImageMagick 6.9.3-5 Q8 x64 2016-02-20 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib
Re: Feathered mask
Posted: 2016-10-07T09:20:57-07:00
by snibgo
mikmach wrote:But: Is it possible to create mask without -fx in this case?
Yes. I don't use FX except on very small images. One trick is to create a mask, white where you want the full effect (100%), black where you don't want it at all (0%), or shades of gray. If you make a mask that is only black and white, you can blur it to transition the effect.
Then:
Code: Select all
convert ^
input.png ^
( -clone 0 {the_effect} ) ^
( -clone 0 {a_mask} ) ^
-compose Over -composite ^
output.png
Re: Feathered mask
Posted: 2016-10-08T00:57:42-07:00
by mikmach
Well, it's kinda obvious (although thanks for syntax). The real question was: how to create mask for pixels fullfilling condition:
Code: Select all
hue > 0.917 && hue < 0.083 && saturation < 0.10
without FX?
Re: Feathered mask
Posted: 2016-10-08T06:57:26-07:00
by snibgo
You've reversed the hue range, so that condition will never be true. I'll use the condition you gave in the OP.
Create a mask that is white where 8.3% < hue < 91.7% AND saturation > 10%, and black otherwise.
We will make a mask from saturation, and another from hue, then multiply them together.
The saturation condition is simply a "-threshold". The hue condition can be implemented in a number of ways. I will use "-opaque". Note that:
(8.3+91.7)/2 = 50
91.7 - 50 = 41.7
Windows BAT script:
Code: Select all
%IM%convert ^
rose: ^
-colorspace HSL ^
-separate ^
-delete 2 ^
( -clone 0 -fuzz 41.7%% -opaque gray(50%%) ) ^
( -clone 1 -threshold 10%% ) ^
-delete 0-1 ^
-compose Multiply -composite ^
mask.png
Putting it together in a single convert, with "-blur" for feathering:
Code: Select all
%IM%convert ^
rose: ^
-colorspace HSL ^
( -clone 0 ^
-channel R -evaluate Multiply 0.97 +channel ^
) ^
( -clone 0 ^
-separate ^
-delete 2 ^
( -clone 0 -fuzz 41.7%% -opaque gray(50%%) ) ^
( -clone 1 -threshold 10%% ) ^
-delete 0-1 ^
-compose Multiply -composite ^
-blur 0x2 ^
) ^
-compose Over -composite ^
r2.png
Re: Feathered mask
Posted: 2016-10-09T13:22:16-07:00
by mikmach
Thank you very much. But I have problem - mask is working great but red manipulation is broken. Links to 3 images:
Source image:
https://drive.google.com/open?id=0B6_Yh ... 3BwQlA4V1k
FX method (upped parameter to r * 0.5 to get easily visible results):
https://drive.google.com/open?id=0B6_Yh ... Hg4Z2hqbGc
Mask method (as above Multiply 0.5):
https://drive.google.com/open?id=0B6_Yh ... FZoUnNWbUU
If you open FX image and compare it with source image you will see that Green and Blue channels remain untouched, only Red is affected.
Mask part works great but reduction of Red not. In fact looks like it adds it!
Thanks for help.
Re: Feathered mask
Posted: 2016-10-09T13:36:08-07:00
by snibgo
Sorry, I misunderstood what you wanted. Try this:
Code: Select all
%IM%convert ^
obecny.jpg ^
( -clone 0 ^
-channel R -evaluate Multiply 0.5 +channel ^
) ^
( -clone 0 ^
-colorspace HSL ^
-separate ^
-delete 2 ^
( -clone 0 -fuzz 41.7%% -opaque gray(50%%) ) ^
( -clone 1 -threshold 10%% ) ^
-delete 0-1 ^
-compose Multiply -composite ^
-blur 0x2 ^
-set colorspace sRGB ^
) ^
-compose Over -composite ^
r3.png
Re: Feathered mask
Posted: 2016-10-09T13:53:27-07:00
by mikmach
That's it! Thank you very much.
I thought this is something with -colorspace but put it in all the wrong places (outside of ()s ).