Log in

View Full Version : Looking for a 64-bit Non-Linear Resizer


Qaenos
17th December 2018, 20:32
I'm upgrading to AVS+ 64-bit and I have a few scripts that need to undo some videos that took the original 4:3 image and non-linearly stretched it to 16:9. Basically the center pixels were almost unchanged, but the stretching got exponentially worse towards the edge of the images.

I've been using WarpedResize from SimpleResize.dll and it works well in 32-bit. Problem is there's inline assembly in the source code that's preventing me from compiling a 64-bit version myself.

wonkey_monkey
18th December 2018, 00:02
Can you give this a try?

http://horman.net/avisynth/download/widen.zip

It takes four parameters:

width : the new width of the video
scale : stretch the center by this amount (to compensate for distortion at the edges). Defaults to 1 (maintains the original aspect ratio of the center)
quality : 0 = nearest neighbour, 1 = bilinear, 2 = bicubic ( can also use WIDEN_DRAFT, WIDEN_BILINEAR, or WIDEN_BICUBIC . defaults to WIDEN_BICUBIC )
threads : number of threads to use. Defaults to number of logical processors

Example:

colorbars(pixel_type="yv12")
widen(960,1.25)


It's very thrown together so it may well crash. I've tried to reject invalid values for the parameters but I'm not certain what's good and bad. It can only handle Y8, YV12, YV24 and 8-bit planar RGB (Avisynth+) video.

8-bit planar RGB gives the best results because it is (approximately) gamma-aware.

Qaenos
18th December 2018, 16:17
Can you give this a try?
http://horman.net/avisynth/download/widen.zip


I did, thank you!

Unfortunately, when I went to run it, I got a error message from AVISynth+ stating that there was no function named "Widen". I double checked that I had placed widen.dll in my 64-bit plugin folder (where I have MaskTools2.dll, etc.,) and it's there. I'm not sure what the problem is.

StainlessS
18th December 2018, 16:58
Works here, (tested in 64 bit, plugins, plugins+ and avs LoadPlugin).
Req CPP runtimes from VS 2013.

#LoadPlugin(".\Widen.dll") # if not in plugins dir
Colorbars(Pixel_Type="YV24")
widen(960,1.25)
Return Last


https://i.postimg.cc/gXynphzz/widen.jpg (https://postimg.cc/gXynphzz)

try Groucho2004 AvsMeter avsinfo
(me guesses that you is usin' 32 bit avs+, you got both installed ?, try load into Vdub2 64 bit.).

Qaenos
18th December 2018, 17:33
I was missing VC 2013 CPP runtime. Now it runs, thanks!

Now my problem is using this. I can stretch an image, just like the colorbars example

Colorbars(Pixel_Type="YV24")
widen(960,1.25)

but I need to go the other way. I need to shrink a 16:9 image that has been non-linearly stretched from it's original 4:3. I want to go back to the 4:3 by non-linearly shrinking the image with the shrinkage being highest at the edges and very little at the center.

I tried using a width that is less than the original, as well as a fraction for scale (e.g. 0.75) and a negative for the scale (e.g. -1.25) but all I get is error messages such as "Stretch must bust be less than 1.7777" etc.

wonkey_monkey
18th December 2018, 21:14
Okay, how about this?

http://horman.net/avisynth/download/unwiden.zip

The filter name is, rather unimaginatively, unwiden. I'm not sure what it'll do if you give it a bigger width then the input image, so don't do that. Try stretch<=1 - it should throw an error if you give it an out of range value.

Edit: I have no idea how the original resizer used worked, so I don't know how good the result will be with unwiden.

StainlessS
18th December 2018, 22:49
According to my free WordWeb popup dictionary (very old from maybe Win98/2000 or thereabouts, apparently last updated Oct 2017),
Widen, Antonym = Narrow.
Perhaps you would like to rename Widen to UnNarrow.

Qaenos
19th December 2018, 00:01
Okay, how about this?

http://horman.net/avisynth/download/unwiden.zip

The filter name is, rather unimaginatively, unwiden. I'm not sure what it'll do if you give it a bigger width then the input image, so don't do that. Try stretch<=1 - it should throw an error if you give it an out of range value.

Edit: I have no idea how the original resizer used worked, so I don't know how good the result will be with unwiden.

It worked with planar RGB, thanks! I'll play with it for a bit and see what scale value works best but ~0.6 is not bad for the videos I am trying to fix.

FYI, it did not work with YV12, though. There was color in the center of the image, but it was messed up. The sides of the image had no color (monochrome).

Qaenos
19th December 2018, 00:49
By the way, do you happen to have a 32-bit dll compiled for widen/unwiden.dll? Once in a while, I still need to run a 32-bit version of AVISynth and I like to keep the same filters, if possible. If not, I'll just keep using WarpedResize from SimpleResize.dll when I have to run a 32-bit version of AVISynth, but your filter seems to work pretty good.

wonkey_monkey
19th December 2018, 00:56
Obviously a scaling problem with subsampled chroma. It probably works fine with YV24, but Planar RGB gives the technically best result (if not distinguishable with normal footage).

I can compile 32-bit versions at some point, but my project's a bit all over the place at the moment.

Qaenos
19th December 2018, 01:05
Obviously a scaling problem with subsampled chroma. It probably works fine with YV24, but Planar RGB gives the technically best result (if not distinguishable with normal footage).

I can compile 32-bit versions at some point, but my project's a bit all over the place at the moment.

No rush! The 64-bit was what I really needed, thanks! If you ever do get around to making a 32-bit dll I'd love to get a copy, but please don't go out of your way.

Qaenos
19th December 2018, 04:37
Obviously a scaling problem with subsampled chroma. It probably works fine with YV24, but Planar RGB gives the technically best result (if not distinguishable with normal footage).

I can compile 32-bit versions at some point, but my project's a bit all over the place at the moment.

Yep, tested it with YV24 and it works fine.

Qaenos
19th December 2018, 05:56
Hmmm...tried a few more videos and I keep getting a "bad stretch parameter?" error when I try to Unwiden.

The error seems to be related to the ratio between the input width and the output width. For example, I have a 1920x1080 video I want to unwiden to 640x480.


Unwiden(640, 0.6)
BiCubicResize(640,480)

will give "bad stretch parameter?" error

If I go

BiCubicResize(640,480)
Unwiden(640, 0.6)

I also get the "bad stretch parameter?" error.

But if I go

BiCubicResize(640 * 2,480)
Unwiden(640, 0.6)

It works!

Yet if I go,

BiCubicResize(640 * 3,480)
Unwiden(640, 0.6)

I once again get the "bad stretch parameter?" error.

Qaenos
19th December 2018, 06:00
Actually, forgive me if it's obvious (I'm still sort of new to AVISynth) but why do you recommend PlanarRGB instead of YV24? What do you mean by it gives the technically best result? Sometimes I work with RGB footage, but more often than not I'm dealing with YV12. I was under the impression that a YV12 to YV24 conversion would be better than a YV12 to PlanarRGB conversion.

jpsdr
19th December 2018, 10:06
Is there by any chance, out of curiosity, the source code of theses widen/unwiden somewhere ?

wonkey_monkey
19th December 2018, 11:22
I used some pretty dodgy maths to work out the remapping and some even dodgier assumptions to try and avoid getting stuck in an infinite loop. I'm not sure why some parameter combinations don't work.

RGB is best because it can take gamma into account. You'd get this with YUV:

http://www.panotools.org/dersch/gamma/PS_nogamma.PNG

but with RGB and taking gamma into account, you get this:

http://www.panotools.org/dersch/gamma/PT_g2.5.PNG

widen/unwiden does slightly better than the first image with YUV because it still takes gamma into account with the Y channel, but not the UV channels, so colours can still be slightly messed up. With natural footage you probably won't notice the problem.