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. |
|
|
Thread Tools | Search this Thread | Display Modes |
23rd April 2012, 16:43 | #21 | Link | |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
Quote:
I tested a bunch of combinations and different sources, and Gavino's suggestion seems the best overall in terms of least deterioration, blurring or aliasing for round tripping it (note there are situations when you may want "blocky" color edges e.g. some types of VFX work , and other times when you want smoother, chroma edges) Last edited by poisondeathray; 23rd April 2012 at 16:53. |
|
9th May 2012, 11:31 | #24 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Code:
ConvertToYV24(interlaced=true, chromaresample="point") MergeChroma(PointResize(width, height, 0, 2)) ConvertToRGB32() ... # filtering in RGB32 ConvertToYV12(interlaced=true, chromaresample="point") |
|
16th May 2012, 17:54 | #26 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Which case(s) are you talking about? Certainly, conversion from RGB to YV24 (like any RGB-YUV conversion) is subject to rounding errors within 8-bit accuracy. |
|
26th November 2012, 21:32 | #30 | Link |
Registered User
Join Date: Apr 2007
Posts: 240
|
I've a problem related to this. I've learned from this topic how to do YV12<-->RGB32 conversion without chroma shift, but in-between I have to do some cropping as well. When I use even numbers to crop, everything is fine:
Code:
ConvertToYV24(chromaresample="point") MergeChroma(PointResize(width, height, 0, 1)) ConvertToRGB32() Crop(10,104,-10,-100) # ...filtering, etc... ConvertToYV12(chromaresample="point") # ...further filtering, etc... AddBorders(10,104,10,100) Code:
ConvertToYV24(chromaresample="point") MergeChroma(PointResize(width, height, 0, 1)) ConvertToRGB32() Crop(10,105,-10,-99) # ...filtering, etc... ConvertToYV12(chromaresample="point") # ...further filtering, etc... ss=2 PointResize(width*ss, height*ss) AddBorders(10*ss, 105*ss, 10*ss, 99*ss) PointResize(width/ss, height/ss) |
26th November 2012, 22:55 | #31 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
PointResize is also known as Nearest Neighbour.
There is no interpolation it chooses the value of the closest geographical pixel. For YV12, if pixel 1 is red and pixel 3 is green, what colour will pixel 2 be? Let's assume Green, now crop off 1 pixel, pixel 2 becomes pixel 1, 4 becomes 3, etc. Oops we just shifted the chroma .... |
27th November 2012, 05:37 | #33 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
It is the ConvertToYV12(chromaresample="point") that is the issue. Cropping by one half a color sample and using point resize is supposed to shift chroma, as IanB explained, no way around it.
This seems to not shift chroma and looks better with my test than the simple ConvertToYV12(chromaresample="lanczos"): Code:
PointResize(last.width*2,last.height*2) ConvertToYV12(chromaresample="point") LanczosResize(last.width/2,last.height/2) Better to crop in multiples of 2. I used this test script though ffdshow (YV12->NV12) and MadVR (0.85.1, nearest neighbor): Code:
imagesource("red.png", pixel_type = "RGB32") PointResize(30,30) ConvertToYV12(chromaresample="point") addborders(2,2,2,2) ConvertToYV24(chromaresample="point") MergeChroma(PointResize(width, height, 0, 1)) ConvertToRGB32() Crop(0,1,0,-1) PointResize(last.width*2,last.height*2) ConvertToYV12(chromaresample="point") LanczosResize(last.width/2,last.height/2) Last edited by Asmodian; 27th November 2012 at 07:59. |
27th November 2012, 19:32 | #34 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
The purpose of the supersampling is to end up adding borders with an odd number of pixels (here 105 and 99, matching the earlier Crop). This works for the luma, thus restoring the uncropped luma pixels to their original positions. However (and this is probably what you meant), it adds 53 chroma pixels to the top and 49 to the bottom, so chroma is shifted down by 1 luma pixel (2*53 - 105). In addition, the earlier odd-numbered Crop has introduced a shift of its own, amounting to 1 luma pixel, so the final result has a shift of 2 luma pixels. However, as this is an even number (and we have a YV12 clip), it can be easily corrected by adding a final MergeChroma(PointResize(width, height, 0, 2)) Thus the following sequence is completely lossless (except of course for the pixels cropped off). Code:
ConvertToYV24(chromaresample="point") MergeChroma(PointResize(width, height, 0, 1)) #ConvertToRGB32() removed to make completely lossless Crop(10,105,10,-99) ConvertToYV12(chromaresample="point") ss=2 PointResize(width*ss, height*ss) AddBorders(10*ss, 105*ss, 10*ss, 99*ss) PointResize(width/ss, height/ss) MergeChroma(PointResize(width, height, 0, 2)) |
|
27th November 2012, 21:20 | #35 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,407
|
I thought it had to move the chroma without interpolation.
Oh, I see. You moved the chroma back after making the video mod2 again! Seems so obvious now. Thanks. edit: it is somewhat embarrassing how well I feel I understand YV12, point resize, etc. and how bad I am at seeing the (in retrospect, at least) obvious consequences. You are also right, I was only thinking about the chroma when looking at supersampled addboarders (but I didn't think I was). Last edited by Asmodian; 27th November 2012 at 21:31. |
27th November 2012, 22:12 | #36 | Link |
Registered User
Join Date: Apr 2007
Posts: 240
|
Nice, this works, thanks Gavino.
However, it's quite frustrating that I have to remember how I cropped the image earlier (by even or by odd values), then figure out if even or odd borders I want to add now and act accordingly. Can the colorspace conversions and cropping/adding borders be separated with a well-thought out function? I mean, to do a color conversion anytime, adding/cropping anytime by any values without taking into account what and how happened before, yet keep the chroma intact all the time? |
27th November 2012, 23:38 | #37 | Link | ||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
I had to sit down with pencil and paper and trace out where the individual chroma pixels went at each stage of the process, getting quite confused until I was finally sure I had worked it out correctly. Quote:
|
||
28th November 2012, 14:59 | #38 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
It would certainly be simpler just to restrict your crops to even numbers. |
|
28th November 2012, 17:40 | #39 | Link |
Registered User
Join Date: Apr 2007
Posts: 240
|
For anyone else, no - it's pretty poor material noone else would care about. As for me, if there would be no general solution I would still crop by 105 and use your chroma-merging trick somehow. Your posts have helped me tremendously in the past, and I'm sure I'll ask for help in the future, so don't spend time with this one, at least not yet. The by-pass (the chroma-merging trick) has already been covered, I'll try to use that.
Last edited by zee944; 28th November 2012 at 17:59. |
30th November 2012, 11:46 | #40 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
@zee944: Strange how the mind works - while thinking about something else, a relatively simple solution to your problem occurred to me...
You can use these customised wrapper functions for Crop and AddBorders which together produce the right results for both even and odd crop values. Code:
function MyCrop(clip c, int left, int top, int right, int bottom) { topc = top%2 == 0 ? top : top+1 bottomc = (bottom > 0 || top%2 == 0) ? bottom : bottom+1 c.Crop(left, top, right, bottom) top%2 !=0 ? MergeChroma(c.Crop(left, topc, right, bottomc)) : last } function MyAddBorders(clip c, int left, int top, int right, int bottom) { ss = top %2 == 0 ? 1 : 2 c PointResize(width*ss, height*ss) AddBorders(left*ss, top*ss, right*ss, bottom*ss) PointResize(width/ss, height/ss) } Code:
ConvertToYV24(chromaresample="point") MergeChroma(PointResize(width, height, 0, 1)) MyCrop(10,105,-10,-99) # must do in YV24, so BEFORE RGB conversion ConvertToRGB32() # ...filtering, etc... ConvertToYV12(chromaresample="point") # ...further filtering, etc... MyAddBorders(10, 105, 10, 99) It works by ensuring that the chroma is always cropped with an even value, even if the luma is cropped with an odd value. |
Tags |
colorspace conversion, quality, rgb32, yv12 |
Thread Tools | Search this Thread |
Display Modes | |
|
|