Log in

View Full Version : Resize then sub-pixel shift without resampling twice?


Katie Boundary
6th March 2020, 11:18
One of the coolest thing about AVIsynth's built-in resizers is that they can perform both a resize and a sub-pixel crop with a single rescale. HOWEVER, the way they're set up assumes that the user wishes to crop first and then resize. If I wanted to resize first and then crop by a fractional number of pixels, I'd have to rescale twice like this:

mpeg2source("101.d2v")
bilinearresize(720,405)
spline144resize(720,304,0,50.5,720,304)

Are there any tricks or filters I can use to do this with only a single rescale? Assume that all numbers must be exact, and that God will kill a kitten if I use 59.85 (or any other number) as an approximation of 59.85185185185...

FranceBB
6th March 2020, 11:43
God will kill a kitten if I use 59.85 (or any other number) as an approximation of 59.85185185185...

Engineer: Ok... Sounds good to me.

https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQxYQFFUl4TcNOKdnPrA-jIFlNek-B0TM_h8gZJBZXh7Ud33wg0

Mathematician:

as an approximation

as an approximation

an approximation

https://i.imgur.com/loEJ5qI.jpg




Jokes aside, I don't generally use the built-in crop function but when I do, I always crop first and then resize as I think it's easier for me to do the calculations and check it, so I don't know.

wonkey_monkey
6th March 2020, 11:48
There's no such thing as "cropping by a fractional number of pixels." Just combine the scale and shift into one call and then crop:


spline16resize(720, 405, 0, 0.5, 720, last.height)
crop(0,50,0,-51)


Just shift by the fractional amount required to get the right alignment and then do the rest of the shift in the crop.

(I'm curious to know what colourspace mpeg2source is returning here that allows you to resize to an odd height. Could it be that you've left out some information? Surely not...)

PS Since I'm presumably still on ignore for daring to answer previous questions informatively and succinctly, I think it'd be fun if everyone else replied to say how great my answer is.

StainlessS
6th March 2020, 13:44
Great answer Wonkey :goodpost:

Katie Boundary
7th March 2020, 05:56
I don't generally use the built-in crop function but when I do, I always crop first and then resize

https://i.imgur.com/CprXEnG.jpg

There's no such thing as "cropping by a fractional number of pixels."

Yes there is. I do it every time I use a non-integer value for the src_left, src_top, src_width, or src_height parameters in the resize filters.

(I'm curious to know what colourspace mpeg2source is returning here that allows you to resize to an odd height. Could it be that you've left out some information? Surely not...)

I omitted converttorgb() because it wasn't relevant to the problem being discussed.

I'm presumably still on ignore for daring to answer previous questions informatively and succinctly

Actually it's for saying insane and incorrect things like "There's no such thing as cropping by a fractional number of pixels"

wonkey_monkey
7th March 2020, 13:13
Yes there is. I do it every time I use a non-integer value for the src_left, src_top, src_width, or src_height parameters in the resize filters.

That might be what you call it, but that's not what it is. You insist on making up your own language for things then acting indignant when no-one else plays along.

I omitted converttorgb() because it wasn't relevant to the problem being discussed.

When are you going to learn? Everything is relevant. If you leave stuff out, for no good reason, it just needlessly confuses things because it's clear that you've left stuff out. You do this all the time and it's part of the reason you never get the answers you want.

Actually it's for saying insane and incorrect things like "There's no such thing as cropping by a fractional number of pixels"

I believe what you meant to say was "Thank you".

And stop spamming the forum with your stupid memes. This isn't Facebook.

manolito
7th March 2020, 13:41
The AviSynth docs and IanB call it "Sub Pixel Shifter"...

Note the source cropping parameters are all floats. This allows any resizer to be used as a sub pixel shifter
https://forum.doom9.org/showthread.php?p=938102#post938102

It's just semantics. I think that you could also call it "Crop by a fractional number of pixels".

Katie Boundary
17th March 2020, 11:24
So, does anyone know of a way?

huhn
17th March 2020, 12:56
cropping by a fraction is "resizing".
because you can't technically crop by a fraction it's an illusion done by resizing.

wonkey_monkey
17th March 2020, 13:40
So, does anyone know of a way?

I literally gave you the code to do it and an explanation of how it works.

MeteorRain
18th March 2020, 03:16
The result of an operation must consists of full pixels. You can't resize to integers and then crop to floats. Your can't have a result of 719.5px width for example.

And as others have mentioned, you can't crop subpixels for real. "Cropping" inside resizer changes the source-target pixel mapping, not actually removing pixels or subpixels.

Katie Boundary
20th March 2020, 06:27
cropping by a fraction is "resizing".
because you can't technically crop by a fraction it's an illusion done by resizing.

You technically can, but it involves using a resampling filter, which is more commonly used for, but not the same thing as, resizing.

The result of an operation must consists of full pixels. You can't resize to integers and then crop to floats. Your can't have a result of 719.5px width for example.

Doesn't matter because (a) I'm asking how to do this as a single operation, not as two, and (b) I'm not asking how to get a fractional width as a result.

And as others have mentioned, you can't crop subpixels for real. "Cropping" inside resizer changes the source-target pixel mapping, not actually removing pixels or subpixels.

"It's not a half-dozen, mom! It's six!"

:rolleyes:

wonkey_monkey
20th March 2020, 09:33
Doesn't matter because (a) I'm asking how to do this as a single operation

I've already given you the simplest solution (subject to your restrictions, which are nonsensical) with a single resample, but thanks to your bad attitude it seems like you're going to miss out. Shame.

I recommend that no-one else wastes their time on this thread because the question has been answered.

Stereodude
20th March 2020, 16:01
I recommend that no-one else wastes their time on this thread because the question has been answered.
I'm still baffled that anyone replies to any of these threads trying to help. The same thing plays out every time. Haven't you all learned not to feed the ingrate yet?

wonkey_monkey
20th March 2020, 17:42
I live in hope that one day she might learn to say "thank you."

Besides, there's always the possibility that someone else might be looking for the same answer.

huhn
21st March 2020, 03:03
You technically can, but it involves using a resampling filter, which is more commonly used for, but not the same thing as, resizing.

in the video world resizing and resampling are the "same" thing these terms are used as everyone see fits.

feel free to go on a crusade to rename every case of resizing in the video world where it is actually rescaling/resampling and "correct" it.

Katie Boundary
22nd March 2020, 21:20
I recommend that no-one else wastes their time on this thread because the question has been answered.

Wrong.

I'm still baffled that anyone replies to any of these threads trying to help. The same thing plays out every time.

What baffles me is that there are so many illiterate morons who feel the need to dump off-topic shit in my threads and then complain about the amount of shit in them. People like YOU are the reason why this plays out every time. Post constructively or STFU.

wonkey_monkey
23rd March 2020, 00:32
Wrong.

Well, why don't you try telling me what's wrong with my answer instead of just ignoring it completely? Then maybe, just maybe, you will get an answer that satisfies you.

Do you really not realise how excruciatingly difficult you make it for people to help you?

Stereodude
23rd March 2020, 01:42
What baffles me is that there are so many illiterate morons who feel the need to dump off-topic shit in my threads and then complain about the amount of shit in them. People like YOU are the reason why this plays out every time. Post constructively or STFU.
ROFL...

Tell us how you really feel Katie. Let it all out. We're here for you!

johnmeyer
23rd March 2020, 03:43
Given what is happening in this world at the moment, most of us are worried about our friends, neighbors, and our community, but this one is still self-centered and spouting attitude.

So much for "a crisis brings out the best in everyone."

Or, maybe this IS her best ...

Katie Boundary
25th March 2020, 00:09
Tell us how you really feel Katie. Let it all out. We're here for you!

Given what is happening in this world at the moment, most of us are worried about our friends, neighbors, and our community, but this one is still self-centered and spouting attitude.

So much for "a crisis brings out the best in everyone."

Or, maybe this IS her best ...

This thread is about rescaling and cropping. If you don't have anything to say about rescaling or cropping, then STFU and GTFO.

Groucho2004
25th March 2020, 01:09
So much for "a crisis brings out the best in everyone."Exactly. (https://www.youtube.com/watch?v=HM5eO84Q9-A)

Stereodude
25th March 2020, 01:40
This thread is about rescaling and cropping. If you don't have anything to say about rescaling or cropping, then STFU and GTFO.
But maybe I don't want to. Maybe we have a forum pool going on when you're going to snap and there's no rule against trying to influence the outcome... :devil:

Crop and rescale that.

ajp_anton
25th March 2020, 04:04
Since the "cropping" values in a resizer are applied on the source, one can't give you a full answer without knowing what the source dimensions are.

The source for your spline144resize is 720x405 pixels, so the "0, 50.5, 720, 304" values work on that. But they will be different when the source is 720x480 or 720x576 or whatever the resolution of your 101.d2v is.


Thinking aloud here...
Assuming your source is 480px tall, you need to scale your 50.5 by a factor 480/405 which is 59.851... Which you already posted, so it seems you already know the answer? Just scale your 50.5 and the 304 "crops" by a factor 480/405. Would that work? Though you can't combine bilinear and spline144, you will have to choose which one to use.

Katie Boundary
25th March 2020, 04:42
Since the "cropping" values in a resizer are applied on the source, one can't give you a full answer without knowing what the source dimensions are.

The particular case that prompted this question was originally 720x480, but a method that works should work regardless of the exact resolution of the source.

Assuming your source is 480px tall, you need to scale your 50.5 by a factor 480/405 which is 59.851... Which you already posted, so it seems you already know the answer? Just scale your 50.5 and the 304 "crops" by a factor 480/405.

I also mentioned that God would kill a kitten if I used approximations.

StainlessS
25th March 2020, 08:46
should work regardless of the exact resolution of the source.
Dont be daft, given output size and fractional cropping, you have to have input size to calc input fractional cropping.

wonkey_monkey
25th March 2020, 10:00
This thread is about rescaling and cropping. If you don't have anything to say about rescaling or cropping, then STFU and GTFO.

Well you refuse to say anything about it as well. I posted a solution and you ignored it. Eventually you said it was "wrong" but refused to elaborate, so I'm unable to offer a better solution.

It's like you don't actually want an answer.

Katie Boundary
31st March 2020, 21:30
Dont be daft, given output size and fractional cropping, you have to have input size to calc input fractional cropping.

The question is "is there a way to perform a resize followed by a sub-pixel crop as part of a single rescale operation, rather than a crop followed by a rescale or using two separate rescale operations?". The answer to this question does not depend on the resolution of the video. If there's a way to do it on 720x480 video, then there's a way to do it on video of any other resolution. If there isn't a way to do it on 720x480 video, then there won't be a way to do it on video of any other resolution.

Alternatively, if there's a way to use fractions like 1616/27 instead of decimals as values for the crop parameters for AVIsynth's existing resize filters, that would be an acceptable workaround.

StainlessS
31st March 2020, 21:36
Try

NOP

That should work nicely. (Let us know how it goes)

Katie Boundary
31st March 2020, 22:11
Can you explain?

Groucho2004
31st March 2020, 22:25
Can you explain?I'm not saying that Stainless' suggestion will yield acceptable results (although it's non-destructive and quite safe to use) but I feel compelled to point you to the Wiki where NOP() is explained in detail:
http://avisynth.nl/index.php/Internal_functions/NOP#NOP

Katie Boundary
31st March 2020, 22:37
Unfortunately, I don't understand that explanation :\

EDIT: after re-reading it and the explanation for "?" several times, I think what it's trying to say is this:

If your script requires an "If X, then do operation Y; otherwise, do operation Z" statement, and you want Z to do nothing, then use NOP for Z

If that is correct, then I don't see how that's at all useful in this situation. But the given examples for how to use NOP don't make any sense with respect to the explanation for "?" so I have no confidence that my understanding is correct.

wonkey_monkey
1st April 2020, 00:30
The question is "is there a way to perform a resize followed by a sub-pixel crop as part of a single rescale operation, rather than a crop followed by a rescale or using two separate rescale operations?". The answer to this question does not depend on the resolution of the video. If there's a way to do it on 720x480 video, then there's a way to do it on video of any other resolution. If there isn't a way to do it on 720x480 video, then there won't be a way to do it on video of any other resolution.

Wrong. Given your nonsensical restrictions (using a decimal approximation is not going to give you a different result than you would have got if you could have used an exact value, and even if it did there will still be internal approximations inside the filter, so you're never going to reach this platonic ideal that you're so desparately aiming for), whether or not you can specify the resize/shift "precisely" without using an approximation does depend on your input resolution.

It also depends on how you came up with the numbers in your initial example, about which we have no information. We don't know whether, for some other input resolution, you would still be resizing to 405 and then to 304, because we have no idea why you came up with those numbers in the first place.

Alternatively, if there's a way to use fractions like 1616/27 instead of decimals as values for the crop parameters for AVIsynth's existing resize filters, that would be an acceptable workaround.

1616/27 can't be stored precisely as either a floating point number or as a finite decimal. Just use a decimal approximation. You'll almost certainly get a pixel-identical result anyway, and it will certainly be better than your two resizes.

It sounds like nothing short of reimplementing every filter using an arbitrary precision library is going to satisfy you, but you're never going to find someone to do that for you (and it would likely be hundreds if not thousands of times slower).

Katie Boundary
1st April 2020, 06:59
Monkey, the only reason I looked at your original post was because Stainless claimed it was good, and he usually knows what he's talking about. Don't assume that this means you got taken off my ignore list.

wonkey_monkey
1st April 2020, 09:55
a) What's that got to do with anything? It's petty enough to put someone on ignore in the first place; it's even pettier to keep bringing it up at every opportunity.
b) I'm obviously not on your ignore list - if I ever was - because you just acknowledged my post without prompting from another user.

I see, once again, that the simple act of saying "thank you" - or even any kind of acknowledgement of the post's content, even to tell me if I've got something wrong - when someone provides you with information that you've asked for (or rather, appear to have asked for, because one can never be certain what you mean) remains beyond you.

Groucho2004
1st April 2020, 11:03
Don't assume that this means you got taken off my ignore list.I bet hundreds of forum members are terrified by the thought of appearing on your ignore list. Do you really think that is a threat? If so, I think there's medication to cut one's ego to an appropriate size.

richardpl
1st April 2020, 11:08
I bet hundreds of forum members are terrified by the thought of appearing on your ignore list.

This whole situation was funny at start, but now? It is very sad.

Groucho2004
1st April 2020, 11:15
Unfortunately, I don't understand that explanationThe clue is in the first sentence:This is a no-operation function

StainlessS
1st April 2020, 13:38
The clue is in the first sentence:

OK, I've been found out. Twas a childish prank, sorry for that Katie. [Early April Fool - bout 2.5 hours early, Nobody Expects The Spanish Inquisition]

hello_hello
2nd April 2020, 02:40
One of the coolest thing about AVIsynth's built-in resizer is that they can perform both a resize and a sub-pixel crop with a single rescale. HOWEVER, the way they're set up assumes that the user wishes to crop first and then resize. If I wanted to resize first and then crop by a fractional number of pixels, I'd have to rescale twice like this:

mpeg2source("101.d2v")
bilinearresize(720,405)
spline144resize(720,304,0,50.5,720,304)

You can't crop fractional pixels unless you resize because the output must have "whole pixels".
How would a resizer resize before it crops though? If it resized first, the resized width and height would have to be cropped, so the output wouldn't match the specified width and height, or something....

Why not resize and crop whole pixels instead?

mpeg2source("101.d2v")
bilinearresize(720,405)
Crop(0, 51, 0, -50)


Has anyone here made your ignore list by suggesting there's no sub-pixel shifting in your example. The area to be resized mightn't always start or end on a whole pixel, but it's not the same thing as pixel shifting.

This is IanB's example of sub-pixel shifting.
W=Width()
H=Height()
Spline36Resize(W, H, -0.25, 0.5, W, H)

I'm not 100% sure how it works, or if it's even possible to pixel shift and resize in one operation, and because I almost never need to pixel shift, I've not given it any thought.

I assume you've decided to avoid aspect ratio calculations by resizing the DVD to 16:9 and then crop, and therefore without risk of distorting the picture, but why not crop whole pixels so you don't need to resize again?
Copping the black with a resizer mightn't be the cleverest thing to do anyway.

If avoiding the chroma shift when resizing is the only reason for the RGB conversion, I mentioned a resizing function when I replied to your post in this thread (https://forum.doom9.org/showthread.php?p=1905122#post1905122) recently. It uses Avisynth's resizers and corrects the chroma shift. It has the same arguments for cropping.

If my ID is still on your ignore list, with a backup entry in the "Criticised My Deinterlacing" subsection, and another copy in the "Disagreeing With Me Is Off-Topc" subsection, you mightn't have seen my post.

Are there any tricks or filters I can use to do this with only a single rescale? Assume that all numbers must be exact, and that God will kill a kitten if I use 59.85 (or any other number) as an approximation of 59.85185185185...

Floating point math can only be relied on to be accurate to around 4 decimal places for these sorts of numbers, but that's plenty. I'm sure God doest smite kittens because your demand was based on a false premise. It appears you were again asking the wrong question while dismissing anything that might have helped answer the correct one, and so far that hasn't triggered Armageddon for kittens

The following should produce the same result for an NTSC DVD source as your example in the opening post, but requiring only a single serving of resizer. The cropping is rounded to 2 decimal places.

mpeg2source("101.d2v")
Crop(0, 59, 0, -59)
BilinearResize(720,304, 0, 0.85, 0, -0.85)

or

mpeg2source("101.d2v")
BilinearResize(720,304, 0, 59.85, 0, -59.85)

Although I did use CropResize (https://forum.doom9.org/showthread.php?t=176667) instead, and copied the cropping it displays when Info=true for the last two examples.

mpeg2source("101.d2v")
CropResize(720,304, InDAR=16.0/9.0, Resizer="CR_Resize8", Info=true)

For the record, if it floats your boat to use fractions for float arguments you can.... if they're float.

1616.0/27.0

If not, they're rounded to an integer by dropping the decimal places, although CropResize checks it's aspect ratio arguments are specified as float and outputs an error message when they're not.

Katie Boundary
4th April 2020, 22:42
I bet hundreds of forum members are terrified by the thought of appearing on your ignore list. Do you really think that is a threat?

No, I'm pointing out that Monkey is wasting time and forum space.

The clue is in the first sentence:

No clue was given as to how a no-op would be useful for this situation.

wonkey_monkey
4th April 2020, 23:53
No, I'm pointing out that Monkey is wasting time and forum space.

I've done nothing but try to help. You've been nothing but ungrateful and obstructive. Your attitude is completely at odds with the ethos of this forum.

Forteen88
5th May 2020, 19:27
Exactly. (https://www.youtube.com/watch?v=dQw4w9WgXcQ)"You never let a serious crisis go to waste. And what I mean by that it's an opportunity to do things you think you could not do before." -DNC Rahm Emanuel