#9947 closed defect (fixed)
Misbehaving Curves Filter
Reported by: | kesh | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avfilter |
Version: | git-master | Keywords: | curves |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description (last modified by )
Summary of the bug:
The curves filter appears to produce a spline, which is far from that of the GIMP's curves' tool.
A failing case:
To illustrate, I have a 2-point curve in GIMP: [(7,152),(65,234)]
These points normalize to [(0.027450980392156862, 0.596078431372549), (0.2549019607843137, 0.9176470588235294)]
Accordingly, I run the following FFmpeg command on a single-row input image of increasing pixel values to get the curve (so I can plot it easily in Python, rather than getting gnuplot setup)
ffmpeg -report -nostdin -hide_banner -pix_fmt gray -i input.png \ -vf "curves=m='0.0/0.0 0.027450980392156862/0.596078431372549 0.2549019607843137/0.9176470588235294 1.0/1.0'" \ -f rawvideo -frames:v 1 -pix_fmt gray
Then plotting the input vs output pixel values gave me this curve:
Descriptions of the other attachments:
- input.png: Input single-row image
- ffmpeg.log: FFmpeg log file generated by
-report
This command was tested on ffmpeg version 5.1-essentials_build-www.gyan.dev
Attachments (10)
Change History (18)
by , 2 years ago
Attachment: | ffmpeg.log added |
---|
by , 2 years ago
by , 2 years ago
Attachment: | gimp_curves.png added |
---|
by , 2 years ago
Attachment: | ffmpeg_curves.png added |
---|
comment:1 by , 2 years ago
Description: | modified (diff) |
---|
comment:2 by , 2 years ago
Description: | modified (diff) |
---|
by , 2 years ago
Attachment: | pchip_ffmpeg_curves.png added |
---|
comment:3 by , 2 years ago
IMHO, it appears that PCHIP 1-D monotonic cubic interpolation produces a curve much like GIMP. Here is the PCHIP curve of the presented case over the FFmpeg curve:
Based on what I've seen online, this interpolation algorithm may very well be what Photoshop uses.
comment:4 by , 2 years ago
Component: | undetermined → avfilter |
---|---|
Version: | unspecified → git-master |
The issue is also reproducible with a FFmpeg-made input file:
ffmpeg -f lavfi -i color=black:s=32x8,format=rgb24 -lavfi geq=r='X+32*Y':g='X+32*Y':b='X+32*Y',format=rgb24,datascope=s=960x288:mode=color2:format=dec,scale='2*iw':'2*ih' -frames 1 -y test_gray.png
ffmpeg -i test_gray.png -vf "curves=m='0.0/0.0 0.027450980392156862/0.596078431372549 0.2549019607843137/0.9176470588235294 1.0/1.0'" out.png
by , 2 years ago
Attachment: | test_gray.png added |
---|
by , 2 years ago
Attachment: | out_natural.png added |
---|
by , 2 years ago
Attachment: | out_pchip.png added |
---|
by , 2 years ago
Attachment: | 0001-avfilter-vf_curves-add-PCHIP-interpolator-and-interp.patch added |
---|
comment:5 by , 2 years ago
I submitted a patch last night to ffmpeg-devel list to add PCHIP interpolation to the curves filter option. Here are the input and output images of Michael Koch's test commands.
Input
Output (original natural cubic interpolation)
Output (patched PCHIP interpolation)
command:
ffmpeg -i test_gray.png \ -vf curves=m='0.0/0.0 0.027450980392156862/0.596078431372549 0.2549019607843137/0.9176470588235294 1.0/1.0':interp=pchip \ -loglevel debug out_pchip.png
comment:6 by , 2 years ago
Are you sure that you uploaded the correct output image? It seems to be the same as the input image.
by , 2 years ago
Attachment: | out_pchip_correct_one.png added |
---|
comment:7 by , 2 years ago
Oops, you're right. I must've renamed the test files incorrectly. I've fixed the image to the correct one above.
comment:8 by , 2 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Changed links to attached files (if works