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. |
28th April 2015, 08:30 | #1 | Link | |
Registered User
Join Date: Mar 2014
Posts: 308
|
Gamma corrected resizing
Quote:
The long answer is that if you decide to work out the equations, it's probably (!) possible to get a decent first-order approximation (for small Cb and Cr values) that runs faster than a roundtrip YCbCr→RGB→linear RGB→RGB→YCbCr conversion. Or you could stick with the zeroth-order approximation of just applying the inverse gamma to luma, resizing, then applying gamma again, which actually works moderately well because no one cares about chroma.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource! |
|
28th April 2015, 16:05 | #2 | Link | |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
http://www.imagemagick.org/Usage/resize/#resize_lab |
|
29th April 2015, 04:52 | #3 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
@feisty2 I don't think CIE Lab is so different from YUV maybe a bit bigger, also imho resizing on RGB will be better, isn't recommended to use a very sharp resizer on those color-opponent colorspaces (coz haloing and ringing will be bad on colorplanes).
so imho easier YCbCr→RGB→Linear RGB→YCbCr→Resize as colours wrote, no one cares about chroma, and converting to RGB needs a croma upsample pass and a matrix too.
__________________
powered by Google Translator |
29th April 2015, 06:12 | #4 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
that's chilling
well, chroma does matter even if you don't wanna care about it, cuz Y in most YUV colorspaces ain't exactly like L in Lab, most YUV images are converted from some gamma compressed RGB colorspace, unlike Lab, derived from XYZ which is linear, some luminance gets kicked into UV planes due to this, that's why filtering under RGB and YUV are so different sometimes, you have to think about chroma unless you are using a 2020cl matrix, which is linear, just like Lab |
29th April 2015, 18:28 | #5 | Link | |
Registered User
Join Date: Oct 2011
Posts: 204
|
Quote:
Just saying, you know, for the record... |
|
29th April 2015, 18:50 | #6 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
I was saying "XYZ is linear"....
The linear stuff ain't about lab and yuv, it's about their source color spaces (xyz and rgb) The point is, the source color space gotta be linear so the luminance separated from it would be pure, like lab or ycbcr with 2020cl matrix |
29th April 2015, 19:20 | #7 | Link | |
Moderator
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
|
Quote:
A dvd/blu-ray is encoded in non-linear Y'Cb'Cr'. So you convert to R'G'B', convert that to linear RGB (= undo gamma) and convert back to linear Yc'Cbc'Crc' [except it's Rec601/709 instead of Rec2020, but that's not the point]. Then you can apply the smoothing and resizing, etc ... ?? I'm a bit puzzled by the derivation of Cbc'Crc' though. I expected it would be something like: Cbc' = (B-Yc')/(1-Kb), but it's not. @StainlessS, where do you see tau mentioned in the docs? I thought i removed that. Will look at your other issue later. Last edited by Wilbert; 29th April 2015 at 19:25. |
|
29th April 2015, 19:36 | #8 | Link | |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
|
|
30th April 2015, 06:31 | #9 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
source
regular Code:
dither_convert_rgb_to_yuv (matrix="709",lsb=true,output="yv24",tv_range=False) dither_resize16 (600,300) dither_convert_yuv_to_rgb (matrix="709",lsb_in=true,output="rgb24",mode=6,tv_range=False) new method Code:
r=showred ("y8").convert8to16 (false).Dither_y_gamma_to_linear (tv_range_in=False, tv_range_out=False, curve="srgb") g=showgreen ("y8").convert8to16 (false).Dither_y_gamma_to_linear (tv_range_in=False, tv_range_out=False, curve="srgb") b=showblue ("y8").convert8to16 (false).Dither_y_gamma_to_linear (tv_range_in=False, tv_range_out=False, curve="srgb") dither_convert_rgb_to_yuv (r,g,b,matrix="709",lsb=true,output="yv24",tv_range=False) dither_resize16 (600,300) dither_convert_yuv_to_rgb (matrix="709",lsb_in=true,output="rgb48y",tv_range=False) Dither_y_linear_to_gamma (tv_range_in=False, tv_range_out=False, curve="srgb") round8 (false) mergergb (selectevery (3,0),selectevery (3,1),selectevery (3,2)) Function Convert8To16 (clip input, bool "tv_range") { tv_range = Default (tv_range, True) iCceil = (255-128) / (255.5-128) * (65535.5-32768) + 32768 Yexpr = "0-0 ; 255-65535 ;65535-65535 " Cexpr = "0-0.5;0.5-0.5;128-32768;255-"+String(iCceil)+";65535-"+String(iCceil) fullrange = StackVertical (input.Dither_gen_null_lsb (), input). \ SmoothCurve16 (Ycurve=Yexpr, Ucurve=Cexpr, Vcurve=Cexpr, mode=0, interp=0, HQ=True, \ dither=-1, limiter=False, TVrange=0) output = tv_range ? input.Dither_convert_8_to_16 () \ : fullrange return output } Function Round8 (clip input, bool "tv_range") { tv_range = Default (tv_range, True) iCceil = (255-128) / (255.5-128) * (65535.5-32768) + 32768 Yexpr = "0-0; 65535-255" Cexpr = "0-0.5;0.5-0.5;32768-128;"+String(iCceil)+"-255;65535-255" fullrange = input.SmoothCurve16 (Ycurve=Yexpr, Ucurve=Cexpr, Vcurve=Cexpr, mode=0, interp=0, HQ=True, \ dither=-1, limiter=False, TVrange=0) output = tv_range ? input.ditherpost (mode=-1, y=3, u=3, v=3) \ : fullrange.Dither_get_lsb () return output } guess it works |
30th April 2015, 12:48 | #10 | Link | |
Registered User
Join Date: Mar 2014
Posts: 308
|
Quote:
Anyway, the only correct way of doing gamma-aware resizing is in a linear-light colourspace (like linear-light RGB). What feisty2 posted works, but it has an unnecessary roundtrip conversion to linear-light YCbCr.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource! |
|
30th April 2015, 13:05 | #11 | Link | |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
edit: just did a test on that rose image, and ycbcr fails... turns out Lab can't be simply replaced by ycbcr and Lab resize is almost identical to gamma ignorant resize so... gotta choose between gamma aware and dark halos... Last edited by feisty2; 30th April 2015 at 13:46. |
|
30th April 2015, 14:40 | #12 | Link | |
Registered User
Join Date: Mar 2014
Posts: 308
|
Quote:
Code:
jpegsource("O:\earthlights_big.jpg") dither_convert_yuv_to_rgb(tv_range=false,cplace="MPEG1",matrix="601",output="rgb48y") dither_lut16("x 255 / 219 * 4096 +") dither_y_gamma_to_linear() dither_resize16(600,300) dither_y_linear_to_gamma() dither_lut16("x 4096 - 219 / 255 *") ditherpost(mode=-1) mergergb(selectevery(3,0),selectevery(3,1),selectevery(3,2))
__________________
Say no to AviSynth 2.5.8 and DirectShowSource! |
|
30th April 2015, 23:05 | #13 | Link | |
Registered User
Join Date: Oct 2011
Posts: 204
|
Quote:
The first line of my quotes was ambivalent, but the second one seemed to point me to you saying "Lab is linear", which was obviously a misunderstanding. I'm curious, though: Is a perceptual colorspace actually more suited to resizing than a linear one? And, as long as the colorspace is linear (or perceptual), why should it matter whether the luminance is extracted into a separate channel or mixed into the other channels? Linear (or perceptual) weighting should just take care of that, shouldn't it? In any case, the bottom line is: I misunderstood, and I'm sorry |
|
1st May 2015, 07:14 | #15 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
anyways, I made a new sort of gamma aware resizer tryna overcome dark ringings caused by linear light resizing
so, "rose image" source gamma ignorant resizing Code:
r=showred ("y8") g=showgreen ("y8") b=showblue ("y8") gamma=interleave (r,g,b).convert8to16 (false) gamma.dither_resize16 (210,138) round8 (false) mergergb (selectevery (3,0),selectevery (3,1),selectevery (3,2)) gamma aware resizing Code:
r=showred ("y8") g=showgreen ("y8") b=showblue ("y8") gamma=interleave (r,g,b).convert8to16 (false) linear=gamma.Dither_y_gamma_to_linear (tv_range_in=False, tv_range_out=False, curve="srgb") linear.dither_resize16 (210,138) Dither_y_linear_to_gamma (tv_range_in=False, tv_range_out=False, curve="srgb") round8 (false) mergergb (selectevery (3,0),selectevery (3,1),selectevery (3,2)) new fake gamma aware resizing Code:
r=showred ("y8") g=showgreen ("y8") b=showblue ("y8") gamma=interleave (r,g,b).convert8to16 (false) linear=gamma.Dither_y_gamma_to_linear (tv_range_in=False, tv_range_out=False, curve="srgb") gresize=gamma.dither_resize16nr (210,138).Dither_y_gamma_to_linear (tv_range_in=False, tv_range_out=False, curve="srgb") #resizing under gamma compressed space gets highlight areas into trouble, highlight ringings and lack of brightness, pick dither_resize16NR to get rid of highlight ringings lresize=linear.dither_resize16 (210,138) #real gamma aware resizing, works better on highlight areas, less highlight ringings and better brightness, but makes dark halos brightdif=dither_sub16 (lresize,gresize,dif=true).dither_lut16 ("x 32768 < 32768 x ?") #find the differences between pixels, keep brighter difs and discard darker difs (halos) gresize.dither_add16 (brightdif,dif=true) Dither_y_linear_to_gamma (tv_range_in=False, tv_range_out=False, curve="srgb") round8 (false) mergergb (selectevery (3,0),selectevery (3,1),selectevery (3,2)) edit: typo in the code Last edited by feisty2; 1st May 2015 at 07:48. |
1st May 2015, 11:38 | #17 | Link | ||
Registered User
Join Date: Nov 2005
Location: Russia
Posts: 62
|
I think this resizing discussion should form a new discussion thread, cause it is not only "AviSynth 2.6.0 RC3 [Apr 15th, 2015]" development question.
By the way, are you aware of decade old discussion at avsforum concerning resize? Quote from it: Quote:
Quote:
__________________
Avisynth syntax highlighting for AkelPad |
||
1st May 2015, 11:58 | #18 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
yeah, but as you can see, how u gonna slay those dark halos caused by pure linear light resizing (see #27, "rose image")
Code:
I think this resizing discussion should form a new discussion thread edit: result of new fake gamma aware resizing Last edited by feisty2; 1st May 2015 at 12:19. |
Thread Tools | Search this Thread |
Display Modes | |
|
|