Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 1st January 2021, 00:37   #1  |  Link
PRAGMA
Registered User
 
PRAGMA's Avatar
 
Join Date: Jul 2019
Posts: 42
YUV to RGB via numpy?

Is there a lossless way to convert YUV to RGB (with support for both sub-sampled YUV and not).

I'm trying to add YUV support to VSGAN, with no success. The main issue I'm having is that with sub-sampled YUV, (e.g. 4:2:0).

The Y channel is obviously full resolution, however U and V channels arent. This causes np.dstack to freak out about it, and I haven't been able to find a way to losslessly convert from sub-sampled 4:2:0 to 4:4:4 in a no-interpolation way.

Any advice would be great, as I'd love to be able to use VSGAN on YUV input's (which would be the majority of data I would be sending through VapourSynth, e.g. DVD's, Blu-ray's).
PRAGMA is offline   Reply With Quote
Old 1st January 2021, 01:04   #2  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,509
Quote:
Is there a lossless way to convert YUV to RGB (with support for both sub-sampled YUV and not).
a lossless conversion is possible only if the chroma has a top-left placement. in such case you simply interpolate the chroma with a resampling filter that preserves the original pixel at the top-left corner of each 2x2 grid, and interpolates the other 3 spots, you can do that with something like nnedi3(dh=True) or eedi3(dh=True).
but seriously, it makes absolutely no sense to request a lossless conversion since you will be performing some lossy resampling (SRGAN) afterwards anyways. the composite function SRGAN(YUVtoRGB(x)) is no longer lossless even if YUVtoRGB(x) is lossless
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Old 1st January 2021, 01:33   #3  |  Link
PRAGMA
Registered User
 
PRAGMA's Avatar
 
Join Date: Jul 2019
Posts: 42
Quote:
Originally Posted by feisty2 View Post
a lossless conversion is possible only if the chroma has a top-left placement. in such case you simply interpolate the chroma with a resampling filter that preserves the original pixel at the top-left corner of each 2x2 grid, and interpolates the other 3 spots, you can do that with something like nnedi3(dh=True) or eedi3(dh=True).
but seriously, it makes absolutely no sense to request a lossless conversion since you will be performing some lossy resampling (SRGAN) afterwards anyways. the composite function SRGAN(YUVtoRGB(x)) is no longer lossless even if YUVtoRGB(x) is lossless
That's totally correct assumption, however my point is to try and provide the most untouched data to the SRGAN, otherwise it may interpolate differently.
PRAGMA is offline   Reply With Quote
Old 1st January 2021, 01:43   #4  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,509
It makes no difference, SRGAN is unaware of the untouched data and has no specialization for data that went thru a lossless YUVtoRGB conversion
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Old 1st January 2021, 04:32   #5  |  Link
Soulvomit
Registered User
 
Join Date: May 2012
Posts: 28
Not sure how proper this is but you can map and resize each component separately in RGB (UtoY8; VtoY8) then put them back together in YV24 (YtoUV).

Last edited by Soulvomit; 1st January 2021 at 04:34.
Soulvomit is offline   Reply With Quote
Old 1st March 2021, 20:42   #6  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 180
I come back to this, because I thought you asked about something else. You want just simple YUV to RGB to fill RGB planes?
https://forum.videohelp.com/threads/...e2#post2575815
rgb was obtained manually to show it is the same as using vapoursynth Point resize function (rgb2). Is it a problem for SRGAN to extrapolate from values obtained like that (YUV420V to RGB)?
So simple:
Code:
rgb = core.resize.Point(YUV420clip, format = vs.RGB24, matrix_in_s = '709')
would not work?

Last edited by _Al_; 1st March 2021 at 20:46.
_Al_ is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:37.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.