Log in

View Full Version : How to "divide" color?


Brejlounek
1st May 2010, 14:00
Hi everyone. I have one small problem with avisynth.

I have video a. And I want to do this operation using Overlay:

b=255/a

With corrected /0, of course. So for example if color a would be (16, 130, 0), color b would be (16, 2, 0).

Could you please help me figure it out? I am experimenting with invert and mode="multiply", but I have no good results. :(

EDIT: Whole operation is in fact b=b+b*(255/a) so much more precise one would be b=b*(255+a)/a, but it is unusable, because 255+something is 255 everytime :|

Didée
1st May 2010, 14:56
I don't fully understand your formulas, though it might only be the notation. When

b = 255 /a

means "modified pixel = 255 / (original pixel)", then it's more convenient to write

a' = 255 / a

So far things are easy. But I can't make head or tail about the formula in the 2nd half of your post. If

a = [original pixel] , and b = [modified pixel], then both

b=b+b*(255/a) --and-- b=b*(255+a)/a

don't make much sense. Meaningful equations would need to be solved for 'b', i.e. you need

b = F(a).

When you throw a formula like

b = F(a,b)

then the system doesn't have a unike solution.

You need to clarify the exact transformation you want to achieve.

***

For the easy case of "b = 255 / a", you can simply use mt_lut from MaskTools:

new = original.mt_lut("x 1 < 0 255 x / ?", Y=2,U=3,V=3)

In this way, you can do any arbitrary transformation that is based on one variable (mt_lut), based on two variables (mt_lutxy), or based on three variables (mt_lutxyz). All you need is a kosher formula. ;)

Gavino
1st May 2010, 15:48
But I can't make head or tail about the formula in the 2nd half of your post. If

a = [original pixel] , and b = [modified pixel], then both

b=b+b*(255/a) --and-- b=b*(255+a)/a

don't make much sense.
I think he means b' = b + b*(255/a), in which case what's needed is:
newb = mt_lutxy(a, b, "x 1 < y y 1 255 x / + * ?", Y=3,U=4,V=4)
mt_lut("x 1 < 0 255 x / ?", Y=2,U=3,V=3)
Shouldn't that be Y=3,U=2,V=2 - process luma and copy chroma, not vice versa?

Didée
1st May 2010, 16:23
I think he means b' = b + b*(255/a),
Quite possible. It's hard to tell for sure when mathematic nomenclature is used too loosely. Math is a pretty strict topic, in which the word "maybe" should not appear at all. ;)

Shouldn't that be Y=3,U=2,V=2 - process luma and copy chroma, not vice versa?
In the same spirit, it's not sure. I tried to do mindreading, going by the given example:
With corrected /0, of course. So for example if color a would be (16, 130, 0), color b would be (16, 2, 0).
To me the given triples look like YUV values, and if so, the example shows Y channel copied, and U/V channels processed.

It's all guesswork. Waiting for clarification what the deal is supposed to be.

jmac698
3rd May 2010, 04:28
That is the formula for removing a blended logo. You'd best try one of the delogo filters instead.
Try nologo from logotools. You need the logo against a blackframe usually to determine it's blending.
The same formula may apply to blended video; there's filters for that as well. srestore is a pretty powerful one. There's also simpler older ones which directly do your formula, maybe unblend.
The filter hotspot may apply the same formula as well, although it's made for a different kind of deblending.