Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#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 kesh)

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)

ffmpeg.log (35.9 KB ) - added by kesh 2 years ago.
input.png (346 bytes ) - added by kesh 2 years ago.
gimp_curves.png (21.9 KB ) - added by kesh 2 years ago.
ffmpeg_curves.png (23.7 KB ) - added by kesh 2 years ago.
pchip_ffmpeg_curves.png (29.6 KB ) - added by kesh 2 years ago.
test_gray.png (603.1 KB ) - added by kesh 2 years ago.
out_natural.png (489.6 KB ) - added by kesh 2 years ago.
out_pchip.png (603.1 KB ) - added by kesh 2 years ago.
0001-avfilter-vf_curves-add-PCHIP-interpolator-and-interp.patch (14.8 KB ) - added by kesh 2 years ago.
out_pchip_correct_one.png (286.6 KB ) - added by kesh 2 years ago.

Change History (18)

by kesh, 2 years ago

Attachment: ffmpeg.log added

by kesh, 2 years ago

Attachment: input.png added

by kesh, 2 years ago

Attachment: gimp_curves.png added

by kesh, 2 years ago

Attachment: ffmpeg_curves.png added

comment:1 by kesh, 2 years ago

Description: modified (diff)

Changed links to attached files (if works

comment:2 by kesh, 2 years ago

Description: modified (diff)

by kesh, 2 years ago

Attachment: pchip_ffmpeg_curves.png added

comment:3 by kesh, 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 Michael Koch, 2 years ago

Component: undeterminedavfilter
Version: unspecifiedgit-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 kesh, 2 years ago

Attachment: test_gray.png added

by kesh, 2 years ago

Attachment: out_natural.png added

by kesh, 2 years ago

Attachment: out_pchip.png added

comment:5 by kesh, 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


Version 6, edited 2 years ago by kesh (previous) (next) (diff)

comment:6 by Michael Koch, 2 years ago

Are you sure that you uploaded the correct output image? It seems to be the same as the input image.

by kesh, 2 years ago

Attachment: out_pchip_correct_one.png added

comment:7 by kesh, 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 Michael Koch, 2 years ago

Resolution: fixed
Status: newclosed
Last edited 2 years ago by Carl Eugen Hoyos (previous) (diff)
Note: See TracTickets for help on using tickets.