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 > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th March 2005, 18:18   #1  |  Link
Viperzahn
Registered User
 
Join Date: Sep 2004
Posts: 9
Bug or feature: differences between crop before resize and crop in resize function

Code:
A=BlankClip(width=720,height=8,pixel_type="RGB24",color=$000000)
B=BlankClip(width=720,height=560,pixel_type="RGB24",color=$CACACA)
C=BlankClip(width=720,height=8,pixel_type="RGB24",color=$000000)
SOURCE=StackVertical(A,B,C)
#
#
V1=SOURCE
     \.SeparateFields()
     \.Crop(16,4,688,280)
     \.BicubicResize(576,160,0.0,0.5)
     \.Weave()
#
V2=SOURCE
     \.SeparateFields()
     \.BicubicResize(576,160,0.0,0.5,16,4,688,280)
     \.Weave()
Can someone explain me the differences between V1 and V2 on the top and bottom border? I test also with BilinearResize() + LanczosResize() and I use AviSynth 2.55 build: Sep 1 2004.

Last edited by Viperzahn; 17th March 2005 at 18:21.
Viperzahn is offline   Reply With Quote
Old 20th March 2005, 07:26   #2  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Viperzahn,

The cropping parameters of the resizer engine are floating point numbers. This allows the resizers to do subpixel shifting of the resultant image. As a consequence of this design the cropping is not a hard crop at the boundary but more an edge limit to the resampler centre point (there is seperate hard limiting at the picture edge).

So your V1 clip has a hard boundary 4 pixels in from the edge of the original image, thus there are no Black pixels in the available sampled image area. At the edge the resampler hits a hard boundary and doesn't sample beyond it.

For your V2 clip the centre point of the sampler is constrained to be 4 pixels away from the edge of the picture but wing samples are allowed to span beyond this limit right up to the edge of the image. Thus some of the black pixels are sampled in the wings.

For cropping off hard artifacts like VHS head noise or leterbox borders always use Crop.

For extracting a portion of an image and to maintain accurate edge resampling use the resize cropping parameters.

IanB
IanB is offline   Reply With Quote
Old 20th March 2005, 18:13   #3  |  Link
Viperzahn
Registered User
 
Join Date: Sep 2004
Posts: 9
Ok, thank you for the information
Viperzahn is offline   Reply With Quote
Old 1st March 2012, 02:23   #4  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
Quote:
Originally Posted by IanB View Post
For your V2 clip the centre point of the sampler is constrained to be 4 pixels away from the edge of the picture but wing samples are allowed to span beyond this limit right up to the edge of the image. Thus some of the black pixels are sampled in the wings.
So this method is not accurate for cropping letterboxes of the 2.35 widescreen film? The noise from the noised pixels come to clean pixels and image would be with black borders, which it didn't contain before, right? I'm talking about the scrypt like this for example LanczosResize(720, 304, 0, 132, -0, -132).
And the second question:
http://avisynth.org/mediawiki/Spline36Resize
Quote:
the Resizer filter lobes can extend into the cropped region but not beyond the physical edge of the image.
Does it mean that this type of the resize gives the maximum portion of the image in compare of the Crop, like this scrypt for example
Crop(0, 132, -0, -132)
LanczosResize(720, 304)
???

Last edited by $in0bi; 1st March 2012 at 03:33.
$in0bi is offline   Reply With Quote
Old 1st March 2012, 05:51   #5  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Accuracy is the wrong concept. Both methods are accurate, they just have very different edge behaviour. You must choose the edge behaviour you want.
Quote:
Originally Posted by IanB View Post
For cropping off hard artefacts like VHS head noise or letterbox borders always use Crop.
The crop command defines a hard edge of the image. Former pixels beyond that edge no longer exist.
Quote:
For extracting a portion of an image and to maintain accurate edge resampling use the resize cropping parameters.
The resizer cropping defines the centre point of the edge. Pixels to the left and right of that centre point will be used to calculate the new output pixel. Only if the hard edge of the input image is encountered will sampling be constrained.
IanB is offline   Reply With Quote
Old 1st March 2012, 09:02   #6  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
Quote:
Originally Posted by IanB View Post
Pixels to the left and right of that centre point will be used to calculate the new output pixel.
So the image would not be clean, it would contain some black noise, which film picture image doesn't have, right?
$in0bi is offline   Reply With Quote
Old 1st March 2012, 09:34   #7  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
If you want to hard chop the image edge use a Crop().

If you want the image edge interpolation centred on image edge use the Resize croping.
IanB is offline   Reply With Quote
Old 1st March 2012, 12:20   #8  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
Ok, thanks. Resize cropping crops centred on the real image edge and Crop makes it hard without black noise but less precisely, right?
Quote:
Originally Posted by IanB View Post
Only if the hard edge of the input image is encountered will sampling be constrained.
My Input image is a Blu-Ray with the AR 2.35:1 of the film The Departed (2006) Martin Scorcese - you know where you can see it. I see there legible edge, not like some VHS, so is it a hard edge of the input image?

Last edited by $in0bi; 1st March 2012 at 16:43.
$in0bi is offline   Reply With Quote
Old 2nd March 2012, 03:31   #9  |  Link
Brother John
(schein)heilig
 
Brother John's Avatar
 
Join Date: Jun 2003
Location: Germany
Posts: 512
To illustrate the difference, try this script:
Code:
src = BlankClip(width=320, height=240, color=$ff0000).KillAudio().AddBorders(20,20,20,20)
a = src.LanczosResize(240, 180, 20, 20, 320, 240)
      \.Levels(0, 0.0001, 255, 0, 255).Subtitle("resizecrop", align=5)
b = src.Crop(20, 20, -20, -20).LanczosResize(240, 180)
      \.Levels(0, 0.0001, 255, 0, 255).Subtitle("crop then resize", align=5)

StackHorizontal(a.AddBorders(0, 0, 20, 0, color=$ffffff), b)
StackVertical(src.Subtitle("source image", align=5).AddBorders(0, 0, 140, 20, color=$ffffff), last)
AddBorders(20,20,20,20,$ffffff)
It produces this image:

You can see how with resizecrop information from outside the cropped area is used by the resizer. Look at the dark border around the “resizecrop” rectangle. That is from the black border in the source bleeding into the cropped image. That cannot happen with “crop then resize” because first you cut, then you scale. And information that is not there anymore cannot be used by the resizer. Hence no bleeding.

If you want that bleeding effect or not depends, as explained in postings above.

P.S.: The effect is greatly exaggerated by Levels(). Otherwise it would be too subtle to notice with the naked eye.
__________________
Brother John

When lost in BeSweet's options, have a look at the Commandline Reference.
DVD nach MPEG-4 klappt nicht? Verzweifelt? Auf zum Encodingwissen!
Brother John is offline   Reply With Quote
Old 2nd March 2012, 04:03   #10  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
Brother John, you added borders by yourself and IanB wrote that the resizer cropping defines the centre point of the edge. It's something other I think.

Last edited by $in0bi; 2nd March 2012 at 05:11.
$in0bi is offline   Reply With Quote
Old 2nd March 2012, 11:16   #11  |  Link
J_Darnley
Registered User
 
J_Darnley's Avatar
 
Join Date: May 2006
Posts: 957
What? His image shows the effect this thread has been discussing. The only borders he adds are the black ones to the "source" clip and then the white ones everywhere else so he can make one image.
__________________
x264 log explained || x264 deblocking how-to
preset -> tune -> user set options -> fast first pass -> profile -> level
Doom10 - Of course it's better, it's one more.
J_Darnley is offline   Reply With Quote
Old 2nd March 2012, 11:40   #12  |  Link
Asmodian
Registered User
 
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,403
Quote:
Originally Posted by $in0bi View Post
Resize cropping crops centred on the real image edge and Crop makes it hard without black noise but less precisely, right?
It is not a matter of more or less precise. It is a matter of what you want. If you are cropping non-video information, like the black boarders in the example, you want to use crop. If cropping video information, such as to change aspect ratio while resizing, resize cropping keeps more information. You don't want to keep this information unless it is real video information and it only affects the outermost few pixels.
Asmodian is offline   Reply With Quote
Old 2nd March 2012, 15:39   #13  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
Quote:
Originally Posted by Asmodian View Post
If cropping video information, such as to change aspect ratio while resizing, resize cropping keeps more information.
Does it keep more video information or keeps like Brother John and J_Darnley think video with black borders noise, which the original image doesn't contain?
$in0bi is offline   Reply With Quote
Old 2nd March 2012, 16:00   #14  |  Link
Brother John
(schein)heilig
 
Brother John's Avatar
 
Join Date: Jun 2003
Location: Germany
Posts: 512
But the original image does contain the black bars, look at the example! The difference is this: Resizecrop can use information from outside the crop area in the interpolation process of edge pixels. That leads to the bleeding effect. It always happens, not only with black bars. Crop+Resize can not use information from outside the crop area in the interpolation process.

Forget about more or less information in the output image. That’s not the point. The important difference is that edge pixels contain different information.
__________________
Brother John

When lost in BeSweet's options, have a look at the Commandline Reference.
DVD nach MPEG-4 klappt nicht? Verzweifelt? Auf zum Encodingwissen!
Brother John is offline   Reply With Quote
Old 3rd March 2012, 01:05   #15  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Quote:
Originally Posted by $in0bi PM
I want only to know are these borders at the top and down be part of real image or just a noise which had got by the wrong algorithm of the crop (resize)?
http://i32.fastpic.ru/big/2012/0226/...a7eb2d6fc9.png
Ther resize-crop was LanczosResize(720, 304, 0, 132, -0, -132)

PS. Sorry for my English, it's not my native language.
Yes the top and bottom lines of that image are very subtly effected by the black area cropped from the input image. If you do not want that effect then you should crop off the black area before you resize it.

Have a really good hard close look at Brother John's excellent image comparison of the 2 cases. Copy his script and vary it to see how various changes effect the result.

If you were cropping a 4:3 section from the centre of the original and did not want the black borders to influence the top and bottom but did want the image side pixels to influence the left and right side you would do something like this :-
Code:
... # 1920x1080 source,  2.35:1 letterboxed
Crop(0, 132, 0, -132) # Crop off black borders
LanczosResize(640, 480, 413.33, 0, -413.33, 0) # Select 4:3 centre window

The forums are the right place for support questions, PM's are for in private exchanges of confidential information, i.e. password, email addresses, phone numbers, etc.

Also understand many members only read the forum every other day or so, some maybe only weekly, it is grossly impatient to expect answers within a few minutes of your posting. Prompting to read your posts via a PM should be reserved for at least 3 or 4 days of idleness.
IanB is offline   Reply With Quote
Old 3rd March 2012, 06:25   #16  |  Link
Asmodian
Registered User
 
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,403
I am sorry if my answer was confusing.

If cropping black boarders do not use resize cropping.

The exact same math is used to do the resize either way. The difference is weather the uncropped or cropped image is used when doing the resize.

Quote:
Originally Posted by Asmodian View Post
If cropping video information, such as to change aspect ratio while resizing, resize cropping keeps more information. You don't want to keep this information unless it is real video information and it only affects the outermost few pixels.

Last edited by Asmodian; 3rd March 2012 at 06:33.
Asmodian is offline   Reply With Quote
Old 3rd March 2012, 13:57   #17  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
IanB, so why don't you extend possibilities of the Crop? By using Crop I can chop only for two pixels, for example, Crop(0, 2, 0, -0), Crop(0, 4, 0, -0) and etc. Some images like some films need only one pixel to cut, for example, Crop(0, 1, 0, -0) and if I'll cut two pixels I'll cut the the image of the film picture. By the way Resize-crop can crop for 1 pixel.

PS. Does anybody concordant with me that it would be very useful innovation?

Last edited by $in0bi; 3rd March 2012 at 14:08.
$in0bi is offline   Reply With Quote
Old 3rd March 2012, 14:49   #18  |  Link
LaTo
LaTo INV.
 
LaTo's Avatar
 
Join Date: Jun 2007
Location: France
Posts: 701
Quote:
Originally Posted by $in0bi View Post
IanB, so why don't you extend possibilities of the Crop? By using Crop I can chop only for two pixels, for example, Crop(0, 2, 0, -0), Crop(0, 4, 0, -0) and etc. Some images like some films need only one pixel to cut, for example, Crop(0, 1, 0, -0) and if I'll cut two pixels I'll cut the the image of the film picture. By the way Resize-crop can crop for 1 pixel.

PS. Does anybody concordant with me that it would be very useful innovation?
It's an YV12 limitation, chroma is subsampled.
LaTo is offline   Reply With Quote
Old 3rd March 2012, 14:53   #19  |  Link
Brother John
(schein)heilig
 
Brother John's Avatar
 
Join Date: Jun 2003
Location: Germany
Posts: 512
Crop “step size” depends on the colour space you use. Most likely that is YV12, because that’s what almost every video uses. YV12 needs even crop values (“mod2”) because of the way it stores colour. To an extent you can work around that restriction with resizecrop. But the final width and height must be mod2, so Crop(0, 1, 0, -0) isn’t possible.

RGB doesn’t have such restrictions. But virtually every common delivery format (all the MPEGs, VC-1, VP8 …) relies on YV12. That means even when you use RGB in AviSynth you’ll probably have to convert to YV12 for the video encoder anyway.
__________________
Brother John

When lost in BeSweet's options, have a look at the Commandline Reference.
DVD nach MPEG-4 klappt nicht? Verzweifelt? Auf zum Encodingwissen!
Brother John is offline   Reply With Quote
Old 3rd March 2012, 16:51   #20  |  Link
$in0bi
Registered User
 
Join Date: Oct 2011
Posts: 11
I easy can do with Resizecrop something like this
LanczosResize(720, 304, 1, 131, -1, -131) #not mod2
So may be exist some way to educate Crop make the same in the next version of the avisynth?

Last edited by $in0bi; 3rd March 2012 at 18:07.
$in0bi 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 04:46.


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