Opened 11 years ago

Last modified 6 days ago

#3643 open enhancement

XYZ to RGB color space

Reported by: TTeam Owned by:
Priority: normal Component: swscale
Version: git-master Keywords: xyz
Cc: Elon Musk Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: XYZ to RGB colorspace conversion use only sRGB matrix and sometimes the conversion is deffected in red channel and the picture is dark.

Hi all!

Is it possible to add more color space matrix (in option) to XYZ to RGB conversion? Because the FFMPEG use only one matrix (sRGB) but lots of available, and best if the user can choose one.
Because the problem is: sometimes the conversion is deffected the red is much more and the picture is dark.

If possible please add some from this list. The default is the sRGB but optional the others.

XYZ to RGB matrices:
http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

Thanks

Change History (6)

in reply to:  description comment:1 by Carl Eugen Hoyos, 11 years ago

Component: undeterminedswscale
Keywords: xyz added; more XYZ to RGB matrix removed
Version: unspecifiedgit-master

Replying to tteam:

sometimes the conversion is deffected in red channel and the picture is dark.

Please provide an example to make this a valid ticket:
Upload a sample input file and post your command line (the one that makes the picture dark) together with the complete, uncut console output.

comment:2 by TTeam, 11 years ago

ffmpeg version N-62259-gb176320 Copyright (c) 2000-2014 the FFmpeg developers

built on Apr 7 2014 22:08:51 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av

isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-zlib

libavutil 52. 74.100 / 52. 74.100
libavcodec 55. 58.102 / 55. 58.102
libavformat 55. 36.102 / 55. 36.102
libavdevice 55. 11.100 / 55. 11.100
libavfilter 4. 3.100 / 4. 3.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100

command:

ffmpeg -i trailer.mxf -vcodec prores -profile:v 3 trailer.mov

ffmpeg -i j2c000047.j2c rgb_out.tif

here is the sample download link: http://we.tl/eiE5MkoGeY

Now I attach the original XYZ picture the imagemagik converted what output result is OK and the FFMPEG result.

When I see this problem is generated by the matrix and/or linearization.

here is the UTAH university test:

http://www.cs.utah.edu/~halzahaw/CS7650/Project2/project2_index.html

They opinion with the Bruce Lindbloom matrix:

"The images seemed to have more of a red hue which I'm not able to explain. Also it was interesting that the bottom-right most square which is supposed to be the black square actually appears to be dark grey. I tried different values of gamma but it always turns out grey or if it does seem black then all the other colored squares are affected in turn."

For good output result Utah use a generic XYZ to RGB matrix with gamma: 0.4.
here is:

r = 2.5623 * x + (-1.1661) * y + (-0.3962) * z
g = (-1.0215) * x + 1.9778 * y + 0.0437 * z
b = 0.0752 * x + (-0.2562) * y + 1.1810 * z

this matrix is really close to COLORMATCH RGB matrix ;)

and here is a other matrix (XML part from easydcp) and this result is ok too this output is same like imagemagik.

  • <transformation name="X'Y'Z' -> Linear RGB" comment="comment line"> <source color_space="X'Y'Z'" primaries="XYZ" white_point="" gamma="0.3846154" white_projector_luminance="48.0" normalizing_constant="52.37" normalizing_bitrate="12" /> <destination color_space="Linear RGB" primaries="RGB" white_point="" gamma="2.2" />
  • <matrix> <row>3.24096989631653;-1.5373831987381;-0.498610764741898</row> <row>-0.96924364566803;1.87596750259399;0.0415550582110882</row> <row>0.0556300804018974;-0.203976958990097;1.05697154998779</row>

So if its possible please add to the XYZ to RGB conversion more matrix and input - output gamma adjust options.

Thanks :)

comment:3 by Elon Musk, 9 years ago

The XYZ sample is gone.

comment:4 by Carl Eugen Hoyos, 9 years ago

Cc: Elon Musk added

One XYZ sample is attached to ticket #4827.

I just uploaded the original zip to http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket3643/

Last edited 9 years ago by Carl Eugen Hoyos (previous) (diff)

in reply to:  4 comment:5 by Balling, 4 years ago

Status: newopen

Replying to cehoyos:

One XYZ sample is attached to ticket #4827.

I just uploaded the original zip to http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket3643/

That XYZ sample is frm_000127.j2c from that zip archive from samples.ffmpeg.org. BTW, where is original trailer.mxf?

comment:6 by Balling, 6 days ago

Related https://patchwork.ffmpeg.org/project/ffmpeg/patch/20241216112118.424999-8-ffmpeg@haasn.xyz/

I do not understand this patch at all, Haasn. It is correct to tag it as SMPTE primaries, those are fake primaries (centre white), they are not used as XYZ HAS NO primaries.

XYZ to RGB colorspace conversion use only sRGB matrix

It is correct for typical HD video, that has BT.709 primaries, you must use BT.709 primaries XYZ matrix as specified in Nvidia docs or here: https://en.wikipedia.org/wiki/SRGB#Correspondence_to_CIE_XYZ_stimulus (The 2003 amended version of the sRGB standard points out that higher accuracy is needed when the samples are encoded with more than 8 bits. It provides the matrix), the primaries in BT.2020 will have to be converted to BT.709 or different XYZ matrix will have to be used.

If I do not understand something please tell me so (what does it mean in your patch "possibly simply by using a more fitting
RGB intermediate like SMPTE428"), also see page 7 of https://5253154.fs1.hubspotusercontent-na1.net/hubfs/5253154/st2067-40-2021.pdf

Also this is how you get YCbCr two cofficients from primaries, as such: https://imgur.com/a/i6742tj

Note: See TracTickets for help on using tickets.