Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source of the YIQ transform matrix #481

Closed
kimikage opened this issue Jun 2, 2021 · 1 comment
Closed

Source of the YIQ transform matrix #481

kimikage opened this issue Jun 2, 2021 · 1 comment

Comments

@kimikage
Copy link
Collaborator

kimikage commented Jun 2, 2021

In relation to the issue #453, I have considered whether gamma correction should be considered in the conversion between RGB and YIQ, and my policy is to not apply gamma correction for now. (cf. JuliaGraphics/ColorTypes.jl#250 (comment))

Apart from the gamma correction, there is also a discussion about the coefficients of the transformation matrix.
I am going to change the implementation of matrix-based transform regarding #477 (Edit: see also PR #482 ). For the discussion on numerical error, I am looking for a reliable source of the coefficients.

The current coefficients are as follows:

function cnvt(::Type{CV}, c::YIQ) where CV<:AbstractRGB
cc = correct_gamut(c)
CV(clamp01(cc.y+0.9563*cc.i+0.6210*cc.q),
clamp01(cc.y-0.2721*cc.i-0.6474*cc.q),
clamp01(cc.y-1.1070*cc.i+1.7046*cc.q))
end

function cnvt(::Type{YIQ{T}}, c::AbstractRGB) where T
rgb = correct_gamut(c)
YIQ{T}(0.299*red(rgb)+0.587*green(rgb)+0.114*blue(rgb),
0.595716*red(rgb)-0.274453*green(rgb)-0.321263*blue(rgb),
0.211456*red(rgb)-0.522591*green(rgb)+0.311135*blue(rgb))
end

I know that these values are often used, but I could not find the origin of the values. In fact, hose values are different from the SMPTE 170M-2004 specification.

These kinds of coefficients are often the subject of editing wars in Wikipedia and they are not very helpful. (It's not as bad as the case of sRGB, though.:cold_sweat:)

Also, the number of significant digits and the rounding direction in clamping are a bit weird.

correct_gamut(c::YIQ{T}) where {T} = YIQ{T}(clamp(c.y, zero(T), one(T)),
clamp(c.i, convert(T,-0.5957), convert(T,0.5957)),
clamp(c.q, convert(T,-0.5226), convert(T,0.5226)))

@Myndex
Copy link

Myndex commented Feb 5, 2023

You would normally go from a gamma-encoded RʹGʹBʹ to YʹIQ and leave the gamma in place.

Use the 601 coefficients for standard definition (720x576 and lower), and 709 for high definition.

@kimikage kimikage closed this as completed Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants