Problem with colorhold filter

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with colorhold filter

Michael Koch
Hi,

I just found out that the colorhold filter doesn't behave as described.
In the documentation is written:
similarity
Similarity percentage with the above color. 0.01 matches only the exact
key color, while 1.0 matches everything.

But when I use similarity=1.0, it matches a wide range of colors, but
not everything. Can be reproduced as follows:

ffmpeg -f lavfi -i color=black:s=1280x256 -vf
geq=r='clip(512-X,0,255)+clip(X-1024,0,255)':g='lt(X,512)*clip(X,0,255)+gte(X,512)*clip(1024-X,0,255)':b='lt(X,1024)*clip(X-512,0,255)+gte(X,1024)*clip(1536-X,0,255)',oscilloscope=tw=1:s=1
-frames 1 -y spectrum.png

ffmpeg -i spectrum.png -filter_complex
colorhold=color=00FF00:similarity=1.0:blend=0 -y out.png

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

John Riselvato
This is a known bug. You'll just have to use it multiple times before you
get it to actually remove all the colors.
http://johnriselvato.com/ffmpeg-how-to-remove-all-colors-except-one-from-a-video/

On Sat, May 16, 2020 at 3:41 AM Michael Koch <[hidden email]>
wrote:

> Hi,
>
> I just found out that the colorhold filter doesn't behave as described.
> In the documentation is written:
> similarity
> Similarity percentage with the above color. 0.01 matches only the exact
> key color, while 1.0 matches everything.
>
> But when I use similarity=1.0, it matches a wide range of colors, but
> not everything. Can be reproduced as follows:
>
> ffmpeg -f lavfi -i color=black:s=1280x256 -vf
> geq=r='clip(512-X,0,255)+clip(X-1024,0,255)':g='lt(X,512)*clip(X,0,255)+gte(X,512)*clip(1024-X,0,255)':b='lt(X,1024)*clip(X-512,0,255)+gte(X,1024)*clip(1536-X,0,255)',oscilloscope=tw=1:s=1
>
> -frames 1 -y spectrum.png
>
> ffmpeg -i spectrum.png -filter_complex
> colorhold=color=00FF00:similarity=1.0:blend=0 -y out.png
>
> Michael
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

Carl Eugen Hoyos-2
Am Sa., 16. Mai 2020 um 17:52 Uhr schrieb John Riselvato
<[hidden email]>:
>
> This is a known bug.

Would you mind defining "known"?

Please find out what top-posting means and avoid it here.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

John Riselvato
On Sat, May 16, 2020 at 12:03 PM Carl Eugen Hoyos <[hidden email]>
wrote:

> Am Sa., 16. Mai 2020 um 17:52 Uhr schrieb John Riselvato
> <[hidden email]>:
> >
> > This is a known bug.
>
> Would you mind defining "known"?
>
> Please find out what top-posting means and avoid it here.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".


As in it's not the first time someone pointed out the issue? The command
doesn't work properly.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

Carl Eugen Hoyos-2
Am Sa., 16. Mai 2020 um 18:11 Uhr schrieb John Riselvato
<[hidden email]>:

>
> On Sat, May 16, 2020 at 12:03 PM Carl Eugen Hoyos <[hidden email]>
> wrote:
>
> > Am Sa., 16. Mai 2020 um 17:52 Uhr schrieb John Riselvato
> > <[hidden email]>:
> > >
> > > This is a known bug.
> >
> > Would you mind defining "known"?

> As in it's not the first time someone pointed out the issue?
> The command doesn't work properly.

Yes, Michael has explained this and shown a sample command.

My question was intended to show a certain "dissonance" between
claiming the issue is "known" and linking to your own blog (instead
of the trac ticket you should have opened or - even better - the fix
to either the code or the documentation).

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

kumowoon1025
In reply to this post by Michael Koch
Hi,

I think this might have been a typo? in vf_colorkey.c:48 the "diff" isn't normalized to 0 - 1, but to 0 - 3.
double diff = sqrt((dr * dr + dg * dg + db * db) / (255.0 * 255.0));

changing it to
double diff = sqrt((dr * dr + dg * dg + db * db) / (3 * 255.0 * 255.0));
seems to fix it for me.

Regards,
Ted Park

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

Carl Eugen Hoyos-2
Am Sa., 16. Mai 2020 um 22:02 Uhr schrieb Edward Park <[hidden email]>:

> I think this might have been a typo? in vf_colorkey.c:48 the "diff"
> isn't normalized to 0 - 1, but to 0 - 3.
> double diff = sqrt((dr * dr + dg * dg + db * db) / (255.0 * 255.0));
>
> changing it to
> double diff = sqrt((dr * dr + dg * dg + db * db) / (3 * 255.0 * 255.0));
> seems to fix it for me.

Paul sent such a patch two hours ago.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem with colorhold filter

Michael Koch
Am 16.05.2020 um 22:44 schrieb Carl Eugen Hoyos:

> Am Sa., 16. Mai 2020 um 22:02 Uhr schrieb Edward Park <[hidden email]>:
>
>> I think this might have been a typo? in vf_colorkey.c:48 the "diff"
>> isn't normalized to 0 - 1, but to 0 - 3.
>> double diff = sqrt((dr * dr + dg * dg + db * db) / (255.0 * 255.0));
>>
>> changing it to
>> double diff = sqrt((dr * dr + dg * dg + db * db) / (3 * 255.0 * 255.0));
>> seems to fix it for me.
> Paul sent such a patch two hours ago.

Tested and working fine now. Please note that if you have old scripts
with colorhold filter, the "similarity" value must now be divided by
sqrt(3) to get the same result as before.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".