View Full Version : Bug or feature: differences between crop before resize and crop in resize function
Viperzahn
17th March 2005, 18:18
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.
IanB
20th March 2005, 07:26
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
Viperzahn
20th March 2005, 18:13
Ok, thank you for the information :)
$in0bi
1st March 2012, 02:23
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
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)
???
IanB
1st March 2012, 05:51
Accuracy is the wrong concept. Both methods are accurate, they just have very different edge behaviour. You must choose the edge behaviour you want.
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.
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.
$in0bi
1st March 2012, 09:02
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?
IanB
1st March 2012, 09:34
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.
$in0bi
1st March 2012, 12:20
Ok, thanks. Resize cropping crops centred on the real image edge and Crop makes it hard without black noise but less precisely, right?
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?
Brother John
2nd March 2012, 03:31
To illustrate the difference, try this script:
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:
http://i40.tinypic.com/3502z4x.png
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.
$in0bi
2nd March 2012, 04:03
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.
J_Darnley
2nd March 2012, 11:16
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.
Asmodian
2nd March 2012, 11:40
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.
$in0bi
2nd March 2012, 15:39
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?
Brother John
2nd March 2012, 16:00
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.
IanB
3rd March 2012, 01:05
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/c9/b22326c4b70d836b5c4b94a7eb2d6fc9.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 :-... # 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.
Asmodian
3rd March 2012, 06:25
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.
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.
$in0bi
3rd March 2012, 13:57
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?
LaTo
3rd March 2012, 14:49
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.
Brother John
3rd March 2012, 14:53
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.
$in0bi
3rd March 2012, 16:51
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?
Gavino
3rd March 2012, 17:20
It's not a question of 'educating' Crop.
As others have tried to explain, chroma is subsampled in YV12.
This means that in a 720x576 clip, there are only 360x288 chroma pixels.
You cannot crop at odd numbers, as there is no chroma pixel at those points.
$in0bi
3rd March 2012, 18:39
So how and why Resize can do it or you want to say that Resizecrop can't do it? If the second I showed the example in my previous post.
Didée
3rd March 2012, 19:17
Crop simply does a hard cut-off. (And therefore is limited by subsampled chroma pixel structure.)
No kind of interpolation is happening here.
Resize-crop does interpolation, taking the "outer" pixels into consideration.
The operations are very well laid out in what they are doing. If any sort of "education" is needed, then it's not for the filters, but for the user. :)
Gavino
3rd March 2012, 19:18
Resize can do it because it does resampling (http://avisynth.org/mediawiki/Resampling) - that's what resizers do.
Crop simply removes some of the existing pixels and leaves the remainder untouched.
gyth
3rd March 2012, 23:11
You can crop by odd amounts in yv24, which is available in avisynth 2.6a3 (http://sourceforge.net/projects/avisynth2/files/AviSynth_Alpha_Releases/)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.