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 > General > Newbies

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd December 2012, 15:55   #41  |  Link
zee944
Registered User
 
Join Date: Apr 2007
Posts: 240
Will try that, but meanwhile I have figured out an alternative way I'm rather excited about. Since I wanted a fool-proof method which can be used anywhere and anytime (sometimes I do adding/cropping in RGB32 space too), I thought that I could compare the luma and chroma edges after every "risky" operation, check the possible variations and choose the best match.

This is the raw idea. Using these customized functions for every operation worked alright so far (but I haven't tested fully yet):

Code:
function FixChroma(clip clp)
{
	clp
	GScriptClip("""
		LumaEdges=GreyScale().mt_edge("sobel", U=2, V=2)
		ChromaEdgesN6=MergeChroma(PointResize(width, height, 0,-6)).UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		ChromaEdgesN4=MergeChroma(PointResize(width, height, 0,-4)).UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		ChromaEdgesN2=MergeChroma(PointResize(width, height, 0,-2)).UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		ChromaEdges00=                                             UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		ChromaEdges02=MergeChroma(PointResize(width, height, 0, 2)).UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		ChromaEdges04=MergeChroma(PointResize(width, height, 0, 4)).UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		ChromaEdges06=MergeChroma(PointResize(width, height, 0, 6)).UToY.PointResize(width, height).mt_edge("sobel", U=2, V=2)
		subtitle("no shift")
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdges06, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, 6)).subtitle("shift +6") : last
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdges04, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, 4)).subtitle("shift +4") : last
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdges02, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, 2)).subtitle("shift +2") : last
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdges00, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, 0)).subtitle("no shift") : last
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdgesN2, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, -2)).subtitle("shift -2") : last
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdgesN4, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, -4)).subtitle("shift -4") : last
		AverageLuma(Overlay(LumaEdges, last.UToY.PointResize(last.width, last.height).mt_edge("sobel", U=2, V=2), mode="subtract")) 
\> AverageLuma(Overlay(LumaEdges, ChromaEdgesN6, mode="subtract")) ? clp.MergeChroma(clp.PointResize(width, height, 0, -6)).subtitle("shift -6") : last
	""",  args="clp", local=true)
} 

function smartConvertToRGB32(clip c) {
  c
  ConvertToYV24(chromaresample="point")
  MergeChroma(PointResize(width, height, 0, 1))
  ConvertToRGB32()
}

function smartConvertToYV12(clip c) {
  c
  ConvertToYV12(chromaresample="point")
}

function smartAddBorders(clip clp, int l, int t, int r, int b) {
  clp
  ss=2
  PointResize(width*ss, height*ss)
  AddBorders(l*ss,t*ss,r*ss,b*ss)
  PointResize(width/ss, height/ss)
  IsYUV ? last : clp.AddBorders(l, t, r, b)
}

function smartCrop(clip clp, int l, int t, int r, int b) {
  clp
  ss=2
  PointResize(width*ss, height*ss)
  Crop(l*ss,t*ss,-1*abs(r)*ss,-1*abs(b)*ss)
  PointResize(width/ss, height/ss)
  IsYUV ? last.FixChroma : clp.Crop(l, t,-1*abs(r),-1*abs(b))
}
Still need a few advices:

1. Is "UToY.PointResize()" and "VToY.PointResize()" (later) right? Will the chroma subtituting pixels be at their right place, and not shifted by one or half pixel in any direction?

2. Should I merge the edge mask of U and V (not just U)? Sometimes when the image has dull colors, none of them has enough edges to work with, though.

3. Would it be enough to check only +2 (or zero) shift all the time? Can the correction be different than +2 after numerous conversions and border operations?

4. I happened to notice that my source (DVD 720x480) has a chroma shift to begin with. "MergeChroma(PointResize(width, height, 0, 2))" is too much, "MergeChroma(PointResize(width, height, 0, 1))" would be ideal if there would be such thing as 1 pixel shift in YV12. Is replacing PointResize() with Lanczos4Resize() an accepted solution for that?

Last edited by zee944; 2nd December 2012 at 15:57.
zee944 is offline   Reply With Quote
Old 5th March 2015, 09:08   #42  |  Link
Kein
Registered User
 
Kein's Avatar
 
Join Date: Mar 2010
Posts: 79
Quote:
Originally Posted by natt View Post
yv12->yv24->yv12 can be lossless with pointresample of chroma, provided the algorithm is correct. avisynth's yv12->yv24 with chromaresample=point is rather incorrect.
Were there any changes on this field in avs' chromaresample since then?

Also, does anyone by any chance know what method Sony Vegas uses when converting imported media to RGB in its own editing space?

Quote:
Originally Posted by zee944 View Post
[...] leads to heavy chroma shift, very noticeably on the red parts.
I also have a bit similar problem with red shift, but of different origin, any idea how to combat it (crop by even values)? I've been told that upscaling by 1.25 factor causes this and there is no way to avoid it. Colorspace conversion does not happen (all being kept in YvV2).

Last edited by Kein; 5th March 2015 at 09:31.
Kein is offline   Reply With Quote
Old 5th March 2015, 14:58   #43  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
Quote:
Originally Posted by Kein View Post
Were there any changes on this field in avs' chromaresample since then?
Unfortunately Avisynth's PointResize semantics are plain wrong and will never be changed because it needs to keep backwards compatibility with all the scripts that utilise these wrong semantics (e.g. some old versions of Destripe).
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 6th March 2015, 12:45   #44  |  Link
Warperus
Registered User
 
Join Date: Apr 2010
Location: Sain-Petersburg, Russia
Posts: 139
Quote:
Originally Posted by Kein View Post
what method Sony Vegas uses when converting imported media to RGB in its own editing space?
It's a bit a of mess actually if you are asking about color transformation
http://www.glennchan.info/articles/v...s-9-levels.htm

Also add automatic deinterlace, pull down removal, external quicktime, vfw filters etc.

As for resize, it's bilinear or bicubic in pan/crop and track motion.
Warperus is offline   Reply With Quote
Reply

Tags
colorspace conversion, quality, rgb32, yv12

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 13:03.


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