[FFmpeg-user] fftfilt

Michael Koch astroelectronic at t-online.de
Thu Oct 14 17:13:48 EEST 2021


Am 14.10.2021 um 13:29 schrieb Michael Koch:
> Am 14.10.2021 um 13:23 schrieb Paul B Mahol:
>> On Thu, Oct 14, 2021 at 1:18 PM Michael Koch 
>> <astroelectronic at t-online.de>
>> wrote:
>>
>>> Am 14.10.2021 um 13:11 schrieb Paul B Mahol:
>>>> On Thu, Oct 14, 2021 at 1:08 PM Michael Koch <
>>> astroelectronic at t-online.de>
>>>> wrote:
>>>>
>>>>> Am 14.10.2021 um 13:01 schrieb Paul B Mahol:
>>>>>> On Thu, Oct 14, 2021 at 12:59 PM Michael Koch <
>>>>> astroelectronic at t-online.de>
>>>>>> wrote:
>>>>>>
>>>>>>> Am 14.10.2021 um 12:53 schrieb Paul B Mahol:
>>>>>>>> On Thu, Oct 14, 2021 at 12:29 PM Michael Koch <
>>>>>>> astroelectronic at t-online.de>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Am 14.10.2021 um 12:07 schrieb Paul B Mahol:
>>>>>>>>>> Sorry but I'm not on windows, so I can not use your script.
>>>>>>>>> Then try the below (slightly improved) version. It would 
>>>>>>>>> become much
>>>>>>>>> simpler with variables:
>>>>>>>>> ARRAY_H = pow(2,ceil(log(ceil(W*10/9))/log(2)))
>>>>>>>>> ARRAY_V = pow(2,ceil(log(ceil(H*10/9))/log(2)))
>>>>>>>>>
>>>>>>>>> The test image contains wavelengths from 4 to 8 (in the 
>>>>>>>>> center) to
>>> 16
>>>>>>>>> pixels per linepair.
>>>>>>>>> The filter wavelength is independant of input size. You can 
>>>>>>>>> change
>>> the
>>>>>>>>> size in the first command (but it must be 1:1 aspect ratio,
>>> otherwise
>>>>>>>>> hstack would fail)
>>>>>>>>>
>>>>>>>> Since when hstack fails because of different aspect ratio?
>>>>>>> Because I first make the left half of the test image, then 
>>>>>>> transpose
>>> it
>>>>>>> and then hstack them together
>>>>>>>
>>>>>>> The fftfilt examples do of course work with any aspect ratio.
>>>>>>>
>>>>>> I think you do not understand what aspect ratio really means.
>>>>> width / height
>>>>>
>>>> Doesn't all this introduces aliasing if not using power of 2 width and
>>>> height square dimensions?
>>> I'm not sure if I understand what you mean. Do you see a significant
>>> difference if you make the input size 250x250 or 256x256?
>>>
>>
>> it did for first test.png  you sent
>


This is the command line for the lowpass filter, where the filter 
freqency isn't a function of input size. The constant "8" is the filter 
wavelength in pixels per linepair.

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=0:dc_U=0:dc_V=0:weight_Y='lte(hypot(X/pow(2,ceil(log(ceil(W*10/9))/log(2))),Y/pow(2,ceil(log(ceil(H*10/9))/log(2)))),1.0/8)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y lowpass.png

With two new variables for the FFT array size

ARRAY_H = pow(2,ceil(log(ceil(W*10/9))/log(2)))
ARRAY_V = pow(2,ceil(log(ceil(H*10/9))/log(2)))

the command line could be simplified to:

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=0:dc_U=0:dc_V=0:weight_Y='lte(hypot(X/ARRAY_H,Y/ARRAY_V),1.0/8)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y lowpass.png

It's possble to simplify even more by defining
X_REL = X / ARRAY_H
Y_REL = Y / ARRAY_V

Then the command line is

ffmpeg -i test.png -vf 
scale=2*iw:2*ih,fftfilt=dc_Y=0:dc_U=0:dc_V=0:weight_Y='lte(hypot(X_REL,Y_REL),1.0/8)':weight_U=1:weight_V=1,scale=iw/2:ih/2 
-y lowpass.png

By the way, fftfilt also has another problem. If the image contains the 
highest possible frequency (pixels are black, white, black, white and so 
on), this can't be filtered out with a lowpass filter. I think that's 
because of the YUV subsampling. As a workaround I did scale the image up 
before filtering and scale down after filtering.

Michael



More information about the ffmpeg-user mailing list