View Full Version : Simple(!) cropping question
Floatingshed
12th May 2012, 11:50
I can't get my brain around this. If someone could kick-start me please...
I have some film footage that has a scratch about a quarter of the way into the image from the left (image is 720x576).
The DeScratch filter does a god job of removing it but also it removes sharp edges (door frames etc) from the rest of the image.
So I thought I'd process just the strip of picture where the scratch appears but cannot think how to!
I can crop out the affected area but how do I keep the cropped areas so I can then reassemble using StackHorizontal?
Drinking coffee isn't helping!
Thanks.
manolito
12th May 2012, 12:20
Try this:
//EDIT//
Script removed due to errors, use Gavino's script from this post instead:
http://forum.doom9.org/showthread.php?p=1574364#post1574364
Good luck
manolito
Floatingshed
12th May 2012, 12:41
This doesn't seem to allow me to use the full height of the video.
If I set y1=0 and y2=575 I get: Crop: Destination height is zero or less
If I box in the scratch I get: Heights don't match
Any ideas?
Thanks.
StainlessS
12th May 2012, 13:52
AVISource("D:\avs\avi\testvid.avi").ConvertToYV12() # For Descratch
# First define the coordinates of the scratched area
# X1 is left, X2 is right
x1=200
X2=300
# Make the values MOD4
X1 = X1 - (X1 % 4)
X2 = (X2+3)/4 * 4 # EDITED
Scratched = crop(X1,0,X2-X1,-0)
Left = crop(0,0,X1,-0)
Right = crop(X2,0,-0,-0)
DeScratch(Scratched)
stackhorizontal(Left,last,Right)
return last
Floatingshed
12th May 2012, 14:01
Perfect. Thanks.
Gavino
12th May 2012, 14:49
# Make the values MOD4
X1 = X1 - (X1 % 4)
X2 = X2 + (4 - (X2 % 4))
If X2 is already a multiple of 4, this will round up to the next such multiple (error inherited from manolito's script).
Should be:
X2 = (X2+3)/4 * 4
manolito
12th May 2012, 15:53
Thanks Gavino for the correction...:)
Cheers
manolito
StainlessS
12th May 2012, 17:16
Thankyou kind sir. Did not even look at that line. (EDIT: Fixed)
EDIT: @Manolito, you may want to fix the error in your post.
(PS, thought you were great in High Chaparral)
manolito
12th May 2012, 18:41
you may want to fix the error in your post.
Done...
(PS, thought you were great in High Chaparral)
Careful, you are revealing that you must be just as old as I am...
Cheers
manolito
StainlessS
12th May 2012, 19:10
I'm just glad you did not mention the Wizard of Oz (Them woz the daze).
Gavino
12th May 2012, 19:12
@Manolito, you may want to fix the error in your post.
While you're doing that, it's worth pointing out that the code only works if the cropped area is entirely inside the frame - it fails if it coincides with any of the borders, as Floatingshed discovered.
(PS, thought you were great in High Chaparral)
And there was me thinking you were the guy from Bonanza... :)
(Also showing my age :))
manolito
12th May 2012, 22:13
While you're doing that, it's worth pointing out that the code only works if the cropped area is entirely inside the frame - it fails if it coincides with any of the borders, as Floatingshed discovered.
Would these 2 added lines fix it in your opinion?
X2 > width() ? X2 = width() : NOP()
Y2 > height() ? Y2 = height() : NOP()
To me it looks like it should work if width() and height() already are MOD4 (which is true for standard DVD frame sizes).
Cheers
manolito
StainlessS
12th May 2012, 23:16
No, you would have to completely skip at least one (only 1, I think) StackXXXXXX op if desired area was flush against border.
EDIT: Counting as if all StackXXXXX ops were converted to two arguments.
EDIT: Answer relates to both your 1st post code for delogo, and FloatingShed's solution.
EDIT: No, if in corner (delogo) would need to skip 2 Stacks.
Gavino
12th May 2012, 23:37
Would these 2 added lines fix it in your opinion?
X2 > width() ? X2 = width() : NOP()
Y2 > height() ? Y2 = height() : NOP()
To me it looks like it should work if width() and height() already are MOD4 (which is true for standard DVD frame sizes).
The syntax of those lines is wrong - you can't put an assignment inside a conditional.
But the underlying problem is a deeper one. In your original script, any or all of the segments Above, Below, Left or Right could be empty if the cropped area is aligned to a border, so you need to check for those as special cases.
I really meant for you just to add a note clarifying the restrictions, but a completely general solution would be:
X1 = X1 - (X1 % 4)
Y1 = Y1 - (y1 % 4)
X2 = (X2 + 3) / 4 * 4
Y2 = (Y2 + 3) / 4 * 4
Scratched = crop(X1,Y1,X2-X1,Y2-Y1)
Above = Y1 > 0 ? crop(0,0,width(),Y1) : NOP
Below = Y2 < height() ? crop(0,Y2,width(),height()-Y2) : NOP
Left = X1 > 0 ? crop(0,Y1,X1,Y2-Y1) : NOP
Right = X2 < width() ? crop(X2,Y1,width()-X2,Y2-Y1) : NOP
DeScratch(Scratched)
IsClip(Left) ? StackHorizontal(Left, last) : NOP
IsClip(Right) ? StackHorizontal(last, Right) : NOP
IsClip(Above) ? StackVertical(Above, last) : NOP
IsClip(Below) ? StackVertical(last, Below) : NOP
return last
manolito
13th May 2012, 00:53
Thanks very much Gavino,
I still am quite a noob when it comes to AviSynth scripting...
Cheers
manolito
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.