This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Mask levels modificator
#1
Lightbulb 
Hello.

I tried to modify the mask using levels and gamma and it seemed to me that in certain cases this method is more accurate and adjustable than binarize:
 
clipMask = havsfunc.SmoothLevels(input=clipMask, input_low=0, input_high=300, output_low=0, output_high=1020, gamma=1.0, Ecurve=0)

If you find this useful, it would be great to have it in the interface.
Reply
#2
Out of curiosity:
Got an example where stretching the luma of a mask makes sense? (seems like your brightening everything up my a factor of 3.4= 1020/300)
(I guess there might be some case, I just can't think of one.)

Side note: using expr might be faster than using Levels or SmoothLevels.
factor = 3.4
clipMask = core.std.Expr(clipMask, expr=f"x {factor} *")

Or did I misunderstand what you are doing?
I don't see how that is an alternative to binarize (which drops everything under a threshold).
I thought about adding a generic 'Expr' field to be applied to masks, but that seemed like it wouldn't really be used by anyone. Smile


Cu Selur

Ps: What you do is basically stacking masks to create new masks. I thought about it, but I haven't come up with a generic way to add stacked masking, in a way which is still usable in a gui. At the end the only generic way would be to basically write something like Custom script/filter additions? but for masks. (which would be tons of work that basically nobody would use)
----
Dev versions are in the 'experimental'-folder of my GoogleDrive, which is linked on the download page.
Reply
#3
It seems to me that with the help of levels and gamma, you can not only cut off the effect as binarization does, but redistribute the effect.
For example, we have a line that fades out smoothly, if you use binarization, then the filter effect will simply be cut off in the middle of the line.
When using levels and gamma, you could set the necessary restrictions, but make them more planar.

Examples:

Normal Sobel Mask
[Image: _3b6133523bccd260e6911d4b11a4e3a1.jpeg]

clipMask = havsfunc.SmoothLevels(input=clipMask, input_low=0, input_high=300, output_low=0, output_high=1020, gamma=1.0, Ecurve=0)
[Image: _76ced3c55b05057b4bc6ba0efdd74ab4.jpeg]

clipMask = havsfunc.SmoothLevels(input=clipMask, input_low=0, input_high=300, output_low=0, output_high=1020, gamma=0.3, Ecurve=0)

[Image: _329954ff3ce86e8d44142cacdaa55137.jpeg]

clipMask = havsfunc.SmoothLevels(input=clipMask, input_low=0, input_high=300, output_low=0, output_high=1020, gamma=1.5, Ecurve=0)
[Image: _8e13ebecdb1be9624a1c56006d590406.jpeg]

clipMask = havsfunc.SmoothLevels(input=clipMask, input_low=0, input_high=1020, output_low=0, output_high=1020, gamma=2.0, Ecurve=0)
[Image: _a1fabf61e59f24824fcaf10c70cac25e.jpeg]
Reply
#4
Okay, so why not normal Levels?
----
Dev versions are in the 'experimental'-folder of my GoogleDrive, which is linked on the download page.
Reply
#5
Both normal levels and normal gamma will do, I just took it as an example, but when I took simple levels, the mask turned green for some reason Smile
Reply
#6
You applied Levels on all planes, not just Y.
----
Dev versions are in the 'experimental'-folder of my GoogleDrive, which is linked on the download page.
Reply
#7
I uploaded a new 'scale'-option to the masking, which scales the pixel values by a factor.
Also, please use another image hoster in the future, since my firewall and MalwareBytes go crazy whenever I click on one of the linked images. Smile

Since gamma changes, do the following: they apply x^1/γ, where x is the input pixel value and γ is the gamma value. I'm not sold on the need for an additional gamma adjustment.
(Applying gamma and a scaling factor would be "x^1/γ * scale" or (x*scale)^1/γ) depending on the order those are combined.)
Maybe I'll add an option for users to apply a custom 'expr'-expression to masks, if need be, but since I personally don't really like using reverse polish notation, that is unlikely atm.

Cu Selur
----
Dev versions are in the 'experimental'-folder of my GoogleDrive, which is linked on the download page.
Reply
#8
It seems to me that it would be more correct to place the new option before the mask inversion


[Image: 2025-02-07-01-41-13.png]
Normal Mask:
 [Image: 2025-02-07-01-48-46.png]

Weakening the mask after inversion weakened the overall selection, not the lines.
 [Image: 2025-02-07-01-49-10.png]
 
Strengthening the lines reduced the amount of detail highlighted by the mask, rather than enhancing it.
[Image: 2025-02-07-01-49-26.png]

As you can see I don't have the "Show" option pressed, but I can see the mask.
I couldn't turn off the mask display, so for now I'm back to the previous Hybrid Dev version.
Reply
#9
Uploaded a new dev, which hopefully fixes the problems.
Going to dev now, but if there are still problems, I'll look at them tomorrow after work.

Cu Selur
----
Dev versions are in the 'experimental'-folder of my GoogleDrive, which is linked on the download page.
Reply
#10
Everything seems to be working correctly now.

By the way, is it possible to disable the million errors when loading or saving old vapoursynth presets?
They occur when updating Hybrid and you have to write the preset completely from scratch. 

[Image: 2025-02-07-04-05-20.png]
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)