PDA

View Full Version : Creating a Contrast Mask


Backwoods
7th March 2006, 10:11
http://www.gimpguru.org/Tutorials/ContrastMask/

I tried recreating the guide in the link above to AVISynth but I am not having much success.

AVISource("hi.avi")
Spline36Resize(640,360)
a=last

b=a.Greyscale().Invert().Blur(1).Blur(1).Blur(1)

Layer(b,a)

The resulting footage is the same, nothing is changed from the original source. I have tried Overlay and all the options but again, nothing. There is a Gaussian Blur script out there that I have tried also but instead of digging it up, I just tossed Blur x3 in there.

It's obvious the problem is with the layering but I am not sure what other options to use. Any suggestions are appreciated.

Kika
7th March 2006, 10:31
Try:

Overlay(a,b,opacity=.5)

or:
Layer(a,b,level=128)

Didée
7th March 2006, 10:50
@ Backwoods

You didn't forget about this thread (http://forum.doom9.org/showthread.php?p=631400#post631400), no? :)

Didée
7th March 2006, 14:40
By the way, after re-reading that GIMP guide, it gets clear that it is not fully clear what "Overlay" in GIMP actually is doing: The shown method preserves full gamut, which is not possible to achieve when re-building the process with Avisynth's Overlay() or Layer() commands directly.

I know how to do it with YV12Lutxy, but it would be interesting to see what GIMP's Overlay is really doing. So, could someone who has GIMP running (I don't have) please do the following: create one horizontal & one vertical 0-255 gradient, combine both with GIMP's overlay, and post the result?

Backwoods
7th March 2006, 20:37
@ Backwoods

You didn't forget about this thread (http://forum.doom9.org/showthread.php?p=631400#post631400), no? :)

Of course I did!

I know how to do it with YV12Lutxy, but it would be interesting to see what GIMP's Overlay is really doing. So, could someone who has GIMP running (I don't have) please do the following: create one horizontal & one vertical 0-255 gradient, combine both with GIMP's overlay, and post the result?

http://img61.imageshack.us/img61/3190/full5jn.jpg

Like that?

Didée
8th March 2006, 13:00
Like that, yes. Thanks. From that picture, one can also see that this operation can not be done with the currently available modes of Avisynth's Overlay, because the wanted result is an asymetric multiplication. Overlay("multiply") is symmetric, and "softlight" or "hardlight" are different operations (that overflow, btw.).

For Photoshop, we get the corresponding transformation from here (http://www.pegtop.net/delphi/articles/blendmodes/overlay.htm). That works, but isn't too elegant, because of
Disadvantage:
There is a separate formula for bright and for dark base colors, so there is a discontinuance for a = ½ (diagram 1 can be sparated into two parts).
But we don't need to do it in the way which the Photoshop Morons had chosen. :)

Basic operation, without any discontinuity:

http://img150.imageshack.us/img150/926/gimpoverlaybasic9ne.th.png (http://img150.imageshack.us/my.php?image=gimpoverlaybasic9ne.png)

Top-left & -right: the two gradients
left-top: multiplication
left-bottom: inverse multiplication
preview: gradiented combination of [multiplication] and .

So far, it's [i]almost the same, but not fully. With some additional twisting of the values during the operation, it'll be very close - close enough, in any case.

Plus, most probably, some knobs to tweak the strenght-of-effect, speed of transitions, etc ...
... best thing is, all of it will fit in one single YV12Lutxy() operation. :)

Backwoods
11th March 2006, 20:13
When I use YV12Lutxy(a,b) in a plain-jane fashion just to see how it looks, all I get is green. Now if I remember correctly, that green is from now having YV12 footage...but it is. Oh Masktools and your complexity (more like my misunderstanding).

foxyshadis
11th March 2006, 20:42
Everyone makes that mistake. ;) By default it totally ignores chroma, you can add chroma="process" or "copy". The docs have more info on that.

Backwoods
13th March 2006, 08:46
That would be with mt_masktools, correct? Using 1.5.8 of Masktools gives me an error saying invalid with chroma="process".

I tried mt_lutxy(a,b,chroma="process") and it worked but there was no change.

foxyshadis
13th March 2006, 08:58
In 1.x it's u= and v=1,2,3,4; ignore, copy, process, and copy second. Sorry! The default (no expr, yexpr, etc) should be to simply hand you back the first argument, though, odd. The docs might have more info on it.

Didée
13th March 2006, 14:41
I tried mt_lutxy(a,b,chroma="process") and it worked but there was no change.
Did you write it just like that, without any string for "yexpr"? :)

BTW, with a=source and b=source.invert.blur, the luts are ...

Photoshop and GIMP (discontinual):
edit: forgot normalization [/255], corrected.
OVERLAY = "y 128 < x y 2 * * 255 / 255 2 255 y - 255 x - * * 255 / - ?"


Gradiented as shown above (continual):

- for 0-255 range:
MUL = "x y * 255 /"
INVMUL = "255 255 x - 255 y - * 255 / -"
OVERLAY = "y "+MUL+" * 255 y - "+INVMUL+" * + 255 /"

- for 16-235 range:
MUL = "x 16 - y 16 - * 235 16 - / 16 +"
INVMUL = "235 16 - 235 16 - x 16 - - 235 16 - y 16 - - * 235 16 - / - 16 +"
OVERLAY = "y 16 - "+MUL+" * 235 16 - y 16 - - "+INVMUL+" * + 235 16 - / 8 +"

In the given case, bothe methods (dis/continual) work almost identical, because of the close relation between "a" and "b".

Backwoods
14th March 2006, 03:09
@Didée
your post
____

my head

So obviously a value for "yexpr" will give me the results I am looking (hoping) for. As per that value I am lost.

@foxyshadis
Yes that worked, thank you.

Didée
14th March 2006, 10:06
With the (corrected) LUT expressions given above, it's just
source = whatever
contrastmask = source .invert() .SomeGaussianBlur()

result = YV12Lutxy( source, contrastmask, yexpr = OVERLAY, U=2,V=2 )

And if you try it that way, you'll find that it doesn't work satisfactury.
It could be the way that GIMP is doing the greyscale conversion (there are different possibilities to do that). But mostly I suspect the method just does not fit too well for the typical Luma-only processing of YUV sources, where only the Y channel is altered, and the UV channels stay the same, where they should be adapted, too. Working in RGB, the Overlay operation is performed simultaneously on all three channels, thereby working on brightness & chrominance at the same time.


Gave it a quick try last week, and got the following ...

Reference pictures from the guide, before - after:

http://img74.imageshack.us/img74/4677/gimpbefore5ss.jpg http://img81.imageshack.us/img81/5733/gimpafter1vt.jpg

Applying the processing as shown in the guide, BUT in YV12, I got:

http://img84.imageshack.us/img84/3658/gimpmethodyv121ib.jpg

Not too impressing. The according contrast adjustments have happened, but the coloring is not good. Alltogether, it seems just "wrong", somehow.

Then, I've not the right mood to puzzle much more in that direction ... and tell you why:
Do you to remember the "YLevels" function I had one posted? With a minor modification (blend over 0-128 instead of 0-255), plus alittle chroma pushing based on the amount-of-change achieved on the Y channel, I got

http://img79.imageshack.us/img79/7852/ylevelsg1501284yo.jpg

Enough to call it a day.

Backwoods
14th March 2006, 22:10
Ok now http://forum.doom9.org/showthread.php?s=&threadid=79898 needs a full reading and a full day or two of testing.

What would I do without you? (Probably actually goto the tailor today for my pants.)

travolter
31st December 2011, 11:38
With the (corrected) LUT expressions given above, it's just
source = whatever
contrastmask = source .invert() .SomeGaussianBlur()

result = YV12Lutxy( source, contrastmask, yexpr = OVERLAY, U=2,V=2 )

And if you try it that way, you'll find that it doesn't work satisfactury.
It could be the way that GIMP is doing the greyscale conversion (there are different possibilities to do that). But mostly I suspect the method just does not fit too well for the typical Luma-only processing of YUV sources, where only the Y channel is altered, and the UV channels stay the same, where they should be adapted, too. Working in RGB, the Overlay operation is performed simultaneously on all three channels, thereby working on brightness & chrominance at the same time.


Gave it a quick try last week, and got the following ...

Reference pictures from the guide, before - after:

http://img74.imageshack.us/img74/4677/gimpbefore5ss.jpg http://img81.imageshack.us/img81/5733/gimpafter1vt.jpg

Applying the processing as shown in the guide, BUT in YV12, I got:

http://img84.imageshack.us/img84/3658/gimpmethodyv121ib.jpg

Not too impressing. The according contrast adjustments have happened, but the coloring is not good. Alltogether, it seems just "wrong", somehow.

Then, I've not the right mood to puzzle much more in that direction ... and tell you why:
Do you to remember the "YLevels" function I had one posted? With a minor modification (blend over 0-128 instead of 0-255), plus alittle chroma pushing based on the amount-of-change achieved on the Y channel, I got

http://img79.imageshack.us/img79/7852/ylevelsg1501284yo.jpg

Enough to call it a day.

Its an old thread but Im very intersted in contrastmask.

questions:
1) in the script posted by didée what values I need to use for OVERLAY?

result = YV12Lutxy( source, contrastmask, yexpr = OVERLAY, U=2,V=2 )

2) What values I need to use with ylevels to get similar results as a contrast mask? I need to use ylevelsc/s/or g?

(plz paste example of code use).. didée´s explanation is hard to translate for a newbie like me ;)

With a minor modification (blend over 0-128 instead of 0-255), plus alittle chroma pushing based on the amount-of-change achieved on the Y channel

This line is really hard to translate for me.. and I think that ylevels way to contrast mask is more useful than the contrastmask method using invert.gaussianblur to save CPu in realtime