pinterf / masktools

MaskTools v2 fork
Other
48 stars 11 forks source link

[Feature request] mt_hysteresis2 #23

Closed Purfview closed 2 years ago

Purfview commented 3 years ago

Would it be possible to make hysteresis2 func which would ignore the corner connections?

For example a mask with a single square wouldn't grow into the both squares:

alt text

pinterf commented 3 years ago

Need more info, because I'm quite unfamiliar - never used - with hysteresis. For example I didn't know that it has anything with corner connections. So because I'm dummy, and do not understand the request, other examples needed for me:

Purfview commented 3 years ago

This example should answer your questions:

mask1: alt text

mask2: alt text

maskH (result of hysteresis / mask1 grows into -> mask2 / result not good for me): alt text

Expected result if the corner connections are ignored: alt text

Script:

mask1=ImageReader(file="D:\mask1.png", pixel_type="Y8")
mask2=ImageReader(file="D:\mask2.png", pixel_type="Y8")
maskH=mask1.mt_hysteresis(mask2)

Stackvertical(mask1, mask2.AddBorders(0,2,0,0,$FFFFFF), maskH.AddBorders(0,2,0,0,$FFFFFF))
Purfview commented 3 years ago

Forgot one scenario:

mask2: alt text

In expected result that bottom square would disappear.

Blankmedia1 commented 3 years ago

That's a good idea.

pinterf commented 3 years ago

Request registered, I busy with other projects at the moment, pls. ping me if no progress is made in a month, thanks :)

Purfview commented 2 years ago

Request registered, I busy with other projects at the moment, pls. ping me if no progress is made in a month, thanks :)

Ping, ping... :)

pinterf commented 2 years ago

Yikes! It's time to remember :)

pinterf commented 2 years ago

Good news, I'm seeing the expected output in my tests. An additional parameter needed, perhaps 'corners'=true (default) and false for the new working mode? Or a better name?

Purfview commented 2 years ago

Nice, no difference for me.

pinterf commented 2 years ago

Pls. check v30, if it is O.K. for you as well, then I release it. https://drive.google.com/uc?export=download&id=1VjitVTdJNRw1mYFSJ5Ch3U30PGy3EZhX

Purfview commented 2 years ago

It works as expected, just that corners=false is default in v30, should be other way around.

pinterf commented 2 years ago

Thanks, next try pls https://drive.google.com/uc?export=download&id=1xAUPCatE4G8MkEaKMSrSP79XR5_sXOL2

Purfview commented 2 years ago

Now default is correct. I did some benchmarks, v30.test2 is faster than v30.test1, but it's ~10% slower than v29:

v29 ("corners=true") 4560

v30.test1 corners=false 4084 v30.test1 corners=true 3980

v30.test2 corners=false 4333 v30.test2 corners=true 4070

pinterf commented 2 years ago

Nothing has been changed in between. Since v29 Visual Studio 2019 got some months older. Since test1 there has been zero changes. Are you testing with the same type of dlls? (xp/nonxp/clang?) version? EDIT: Anyway, I've rearranged some lines, and the new build regained speed of v29 for corners=true case. I'm gonna upload a new set of dlls (build process of all versions takes ~25-30 minutes on my i7)

Purfview commented 2 years ago

Strange, I ran dozens of times, results fluctuated around ~0.5%.

AVSMeter 3.0.7.0 (x86) AviSynth+ 3.7.1 (r3556, master, i386) dlls from "x86" folder CPU supports AVX (no AVX2)

mask1: alt text

mask2: alt text

mask1=ImageReader(file="D:\mask1.png", pixel_type="Y8").loop(100)
mask2=ImageReader(file="D:\mask2.png", pixel_type="Y8").loop(100)
maskH=mask1.mt_hysteresis(mask2, corners=true)
maskH
pinterf commented 2 years ago

New v30 build https://drive.google.com/uc?export=download&id=1-qYyGEqJci2RmDl5MLymkLZv07-dZuJE EDIT: there is no SIMD acceleration inside. I was testing x64

Purfview commented 2 years ago

Nice rearrangement, now it's even faster than v29:

v29 ("corners=true") 4560

v30.test1 corners=false 4084 v30.test1 corners=true 3980

v30.test2 corners=false 4333 v30.test2 corners=true 4070

v30.test3 corners=false 4854 v30.test3 corners=true 4680

Purfview commented 2 years ago

Thank you. Now I need to remember where and when I needed it and test it in the real world. :)