Opened 19 months ago

Closed 18 months ago

Last modified 18 months 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 19 months ago.
input.png (346 bytes ) - added by kesh 19 months ago.
gimp_curves.png (21.9 KB ) - added by kesh 19 months ago.
ffmpeg_curves.png (23.7 KB ) - added by kesh 19 months ago.
pchip_ffmpeg_curves.png (29.6 KB ) - added by kesh 19 months ago.
test_gray.png (603.1 KB ) - added by kesh 19 months ago.
out_natural.png (489.6 KB ) - added by kesh 19 months ago.
out_pchip.png (603.1 KB ) - added by kesh 19 months ago.
0001-avfilter-vf_curves-add-PCHIP-interpolator-and-interp.patch (14.8 KB ) - added by kesh 19 months ago.
out_pchip_correct_one.png (286.6 KB ) - added by kesh 19 months ago.

Change History (18)

by kesh, 19 months ago

Attachment: ffmpeg.log added

by kesh, 19 months ago

Attachment: input.png added

by kesh, 19 months ago

Attachment: gimp_curves.png added

by kesh, 19 months ago

Attachment: ffmpeg_curves.png added

comment:1 by kesh, 19 months ago

Description: modified (diff)

Changed links to attached files (if works

comment:2 by kesh, 19 months ago

Description: modified (diff)

by kesh, 19 months ago

Attachment: pchip_ffmpeg_curves.png added

comment:3 by kesh, 19 months 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, 19 months 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, 19 months ago

Attachment: test_gray.png added

by kesh, 19 months ago

Attachment: out_natural.png added

by kesh, 19 months ago

Attachment: out_pchip.png added

comment:5 by kesh, 19 months 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=interp=pchip:m='0.0/0.0 0.027450980392156862/0.596078431372549 0.2549019607843137/0.9176470588235294 1.0/1.0' \
  out_pchip.png


Last edited 19 months ago by kesh (previous) (diff)

comment:6 by Michael Koch, 19 months ago

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

by kesh, 19 months ago

Attachment: out_pchip_correct_one.png added

comment:7 by kesh, 19 months 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, 18 months ago

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