Selur's Little Message Board
Mask levels modificator - Printable Version

+- Selur's Little Message Board (https://forum.selur.net)
+-- Forum: Hybrid - Support (https://forum.selur.net/forum-1.html)
+--- Forum: Problems & Questions (https://forum.selur.net/forum-3.html)
+--- Thread: Mask levels modificator (/thread-4001.html)

Pages: 1 2


Mask levels modificator - dsiomnainc - 05.02.2025

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.


RE: Mask levels modificator - Selur - 05.02.2025

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)


RE: Mask levels modificator - dsiomnainc - 05.02.2025

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]


RE: Mask levels modificator - Selur - 05.02.2025

Okay, so why not normal Levels?


RE: Mask levels modificator - dsiomnainc - 05.02.2025

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


RE: Mask levels modificator - Selur - 06.02.2025

You applied Levels on all planes, not just Y.


RE: Mask levels modificator - Selur - 06.02.2025

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


RE: Mask levels modificator - dsiomnainc - 06.02.2025

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.


RE: Mask levels modificator - Selur - 06.02.2025

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


RE: Mask levels modificator - dsiomnainc - 06.02.2025

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]