Log in

View Full Version : How to detect continuous areas


MysteryX
24th May 2017, 17:50
I have a mask like this of stripe patterns in a frame. The stronger areas are the patterns of past frame, and the weaker areas are the patterns of next frame (when doing frame interpolation).

https://s13.postimg.org/7va7usms3/Stripes.png (https://postimg.org/image/7va7usms3/)

Now, I would like to detect large continuous areas and produce a mask from it. What I have so far is this.


EMstp = EMstp.BicubicResize(Round(C.Width/BlkSize/4.0)*2, Round(C.Height/BlkSizeV/4.0)*2)
\ .mt_expand(mode= mt_circle(zero=true, radius=1))
\ .mt_binarize(min(SkipTrh*2, 255))
\ .Blur(.3)
\ .BicubicResize(C.Width, C.Height)


I'm not totally satisfied by it although it generally gives an acceptable result.
https://s13.postimg.org/ohrs3vfpv/Mask.png (https://postimg.org/image/ohrs3vfpv/)

This selects or rejects large blocks based on the position of stripes within the blocks, so a large area half in a block and half in the next will be discarded, and a narrow but long stripe will also be discarded, while smaller areas matching a block will pass.

I might as well ask for advice here. What better technique can you come up with? Ideally, we could detect horizontal patches and vertical patches as well, not just large square patches.

If necessary, it's possible to write a new filter from scratch for the right algorithm, but ideally we'd do it with standard functions.

In this sample I want to include the whole barrier at the top and discard the bottom part, ideally.

raffriff42
24th May 2017, 18:30
mt_hysteresis maybe.
https://forum.doom9.org/showthread.php?t=128458
https://forum.doom9.org/showthread.php?p=1780589#post1780589
mt_hysteresis will keep each solid areas of the second mask depending if there is at least one pixel of the first mask in these areas. It's like a fill function trying to color the second mask from each pixel set in the first mask.

MysteryX
24th May 2017, 20:29
It might give ideas but I don't see how it can apply here.

johnmeyer
24th May 2017, 20:39
I don't have a direct answer, but you might want to skim the source for the old Despot (https://avisynth.org.ru/despot/despot.html)function. That function was designed to detect a spot, and then determine how to expand to adjacent pixels that "belong" to that same spot, even if the "spot" was oblong, or some random shape or size.

MysteryX
24th May 2017, 23:53
I tried something along those lines, but it ends up giving worse results than the first. Too many areas end up being included.

EMstp = EMstp.GaussianBlur2(16).mt_binarize(70).mt_expand().GaussianBlur2(8)


The mask gives this
https://s2.postimg.org/tcqtkj4n9/Mask_Blur.png (https://postimg.org/image/tcqtkj4n9/)

MysteryX
25th May 2017, 00:16
OK I think I nailed it :)

EMstp = EMstp.BicubicResize(Round(C.Width/BlkSize)*4, Round(C.Height/BlkSizeV)*4)
\ .FRC_GaussianBlur2(6)
\ .mt_binarize(80)
\ .mt_expand(mode= mt_circle(zero=true, radius=3))
\ .FRC_GaussianBlur2(1.4)
\ .BicubicResize(C.Width, C.Height)

https://s23.postimg.org/f4ygmyzfb/Mask_Nail.png (https://postimg.org/image/f4ygmyzfb/)

With the parade clip, it's covering the flags -- which is technically correct since that's what it's designed for. I'm not getting much other false positives.

MysteryX
27th May 2017, 15:44
Now I'm looking at this.

https://s12.postimg.org/3wpqg0xu1/91patterns.png (https://postimg.org/image/3wpqg0xu1/) https://s12.postimg.org/n9c18jy2x/91blur.png (https://postimg.org/image/n9c18jy2x/) https://s12.postimg.org/wfubvu3bd/91binarize.png (https://postimg.org/image/wfubvu3bd/)

Could I get more of the continuous areas by playing with unidirectional blur? (what's the syntax for unidirectional blur anyway)

If I apply blur to the right, one excluded area is going to become slightly whiter and can be added to the mask. Then I'd have to repeat that for the 3 other directions. Would require 4 more blends, 4 more binarize and 4 more overlays, but I think it would give a better result.

Or skip the first blend; only do 4 blurs separately and merge the results. I should get more of the original shapes as the borders of continuous areas won't get eroded by the unidirectional blend.