View Full Version : Mask with MergeChroma
DoctorM
8th July 2013, 22:53
Hope this makes sense... (seriously, I have no idea what I'm talking about below.)
I have two clips that are nearly identical. The first clip has objects not found in the second. The second has a cleaner more accurate chroma.
I want to merge the chroma from the second into the first. That leaves the unique objects in clip 1 with the wrong color.
Is it possible to create a mask of the difference between the two clips, and then use mergechroma for only what isn't in the mask?
Something like:
avisource("clip1.avi")
clip1=last.tweak(sat=0)
clip2=avisource("clip2.avi")
clip3=tweak(clip2, sat=0)
Similarities=mask(subtract(clip3,clip1))
mergechroma(Similarities,clip2) #Something magic happens
I know this won't work, but the problem is I don't understand masks or the syntax involved. (Reading the guides doesn't give me a clue.)
Didée
9th July 2013, 11:55
Define "nearly identical". It's a long way from "fairly similar to a man's naked eye" up to "pixel identical to a dumb compare filter".
If the clips are indeed pixel identical, I'd use masktools, like e.g.
clip1 = this
clip2 = that
diff = mt_lut(clip1,clip2,"x y - abs 255 *") # luma difference (very strict)
clip1.mt_merge(clip2,diff,luma=true,Y=2,U=3,V=3) # merge chroma planes by using the luma mask
The diff-masking is very strict, it will catch on every +/- 1 difference.
If there are some slight luma variations in the sources, (BUT all objects are at exactly the same spatial position), the mask could be made less aggressive.
However if there are any spatial differences between the clips, you won't have much fun.
DoctorM
9th July 2013, 20:05
Wow, I understand none of the context in that script, but I'll give it a go. You are correct though, the sources are close to the point that subtract() will make the new objects hot, but you can still see the ghost of the rest of the frame.
How much less aggressive can it be made and what part would I need to play around with to get there?
Edit 2: (If you read the first edit, ignore it.) I guess I need to have a tweakable threshold so I can experimentally find where the cut off is for the objects.
DoctorM
10th July 2013, 23:31
Read a little of mask tools to understand what you're doing. Should 'mt_lut' be 'mt_lutxy'?
Edit:
Cludging around I found something that works the way I need it to. The thing is, I'm sure adjusting some of the values in the expression SHOULD do the same thing. I just don't know what:
diff= mt_lutxy(clip1,clip2,"x y - abs") # luma difference
tweakdiff=tweak(diff, cont=128).Levels(0, 1, 255, 255, 0) #Increase the threshold between copied and un-copied luma and then invert black/white
clip1.mt_merge(clip2,diff,luma=true,Y=2,U=3,V=3)
Can you make a suggestion on improving my nonsense?
Edit: Final script for now:
difftemp=mt_lutxy(last,clip2,"x y - abs 2 *") #Holy cow, I haven't seen reverse Polish notation since the 80's.
diff=tweak(difftemp,cont=16).Levels(0, 1, 255, 255, 0) #adjust mask contrast and invert black/white
mt_merge(clip2,diff,luma=true,Y=2,U=3,V=3)
Didée
11th July 2013, 13:30
to understand what you're doing. Should 'mt_lut' be 'mt_lutxy'?
Oops, silly me. Fingers were faster than brain. Or maybe vice versa. Of course that has to be mt_lutxy! :)
If in your case it is sufficient to play with just the intensity of the mask, it could be done directly in the LUT. No need to pull Tweak and Levels.
Like, e.g.:
diff = mt_lutxy(clip1,clip2,"x y - abs 2 - 255 12 / *")
This would make the difference ignore differences up to +/-2, and scale the remaining difference-mask in 12 steps from black to white.
DoctorM
11th July 2013, 20:25
I have little understanding of the math going on there (RPE just confuses me). I CAN tell you that it doesn't invert the mask. That and it's a bit looser in picking what chroma to keep than what I was shooting for.
Didée
11th July 2013, 20:49
Inverting the mask, or swapping the clips. A triviality, either way.
Could you post a sample of a typical situation, please? Im not going to waste time poking in the blue.
DoctorM
12th July 2013, 00:41
Not sure what you mean about inverting the mask or swapping the clips. With ABS swapping the clips produces identical results.
Anyway, I thank you for your help. I'd have liked to have been accurate, but my script still did what I needed. It isn't long enough to be worth more time fiddling.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.