View Full Version : I propose a new resizing algorithm
StainlessS
7th February 2015, 06:04
Never could.
Punk ass adolescent. :)
Katie Boundary
7th February 2015, 20:12
When Asmodian first proposed the 1280x960 thought experiment, I thought to myself "bilinear will only subjectively look better because humans tolerate blurriness much better than we tolerate blockiness. Mathematically, you might as well just be taking the point-resized image and smearing vaseline all over it. That's not going to result in more accurate data".
Last night, I decided to actually try the comparison. I didn't have my DVDs with me, so I had to use what was already on my drive, and I had only one thing that was non-interlaced and less than 40 minutes long: the final chapter of the theatrical cut of Alien 3. Why is this important? Because it has shots like these:
http://img.photobucket.com/albums/v415/DWJohnson/chainlink1_zpsw7bymoqn.jpg
http://img.photobucket.com/albums/v415/DWJohnson/chainlink2_zpsfzid4bky.jpg
http://img.photobucket.com/albums/v415/DWJohnson/chainlink3_zps49jemrnu.jpg
http://img.photobucket.com/albums/v415/DWJohnson/chainlink4_zps6lmszxac.jpg
http://img.photobucket.com/albums/v415/DWJohnson/chainlink5_zpsln2gq0ot.jpg
http://img.photobucket.com/albums/v415/DWJohnson/chainlink6_zpsfiakjz9e.jpg
http://img.photobucket.com/albums/v415/DWJohnson/chainlink7_zpsv4t2epfx.jpg
HOLY GOD, have you ever seen so many diagonal lines? LOL. That was when vivian's comment about diagonal lines finally clicked with Asmodian's comments about looking like the original image and I realized what you guys were talking about. Smearing vaseline on the point-resized images basically cuts corners off of pixels, which really DOES make those diagonal lines look more like they did in the original image :) There are tradeoffs elsewhere, of course (for example, sharp horizontal and vertical lines are better-preserved under nearest neighbor), but I get what you're saying now.
colours
12th February 2015, 00:49
I admit, I know very little about how resizing filters work.
It shows.
This is hardly a new idea; see http://entropymine.com/imageworsener/pixelmixing/. (I also came up with this independently circa 2011, fwiw.)
Anyway, it's not hard to show that while this grid overlay method is effectively a convolution of two box filters, just as the triangular kernel (aka bilinear resize) is, the triangular kernel always has the two box filters being of identical width, while grid overlay doesn't. In other words, it's not obvious that you should be able to emulate grid overlay with a nearest-neighbour up followed by a bilinear down, and indeed it's not always possible.
To modify an earlier example slightly, consider resampling from three samples to five. I'm not going to write out the calculations in detail, but take my word for it that if you label the three input samples x_0, x_1, x_2 and the five output samples y_0, y_1, y_2, y_3, y_4, we have the following.
Grid overlay:
y_0 = x_0
y_1 = (2x_0+x_1)/3
y_2 = x_1
y_3 = (x_1+2x_2)/3
y_4 = x_2
Nearest neighbour to six samples, then bilinear down to five:
y_0 = (x_{-1}+14x_0)/15
y_1 = (9x_0+5x_1)/14
y_2 = x_1
y_3 = (5x_1+9x_2)/14
y_4 = (14x_2+x_3)/15
Note that the boundary points actually also sample outside the original range, but even if you adopt the convention of extending the border pixels (as Avisynth, Imagemagick, etc. do), the second and fourth output samples will still differ between the two methods.
vivan
12th February 2015, 09:04
Dunno how/why avisynth calculates it that way, but shader sample centers of pixels.
Coordinates for texture with width of x pixels lie in range [0.5 / x, 1 - 0.5 / x]. Multiply by x and you'll be in range [0.5 .. x - 0.5].
For 6 to 5 (destination -> source (distance to centers)):
0.5 -> 0.6 (0.1, 0.9)
1.5 -> 1.8 (0.3, 0.7)
2.5 -> 3.0 (0.5, 0.5)
3.5 -> 4.2 (0.7, 0.3)
4.5 -> 5.4 (0.9, 0.1)
Then sampling is done:
y0 = x0 * 0.9 + x0 * 0.1
y1 = x0 * 0.7 + x1 * 0.3
y2 = x1 * 0.5 + x1 * 0.5
y3 = x1 * 0.3 + x2 * 0.7
y4 = x2 * 0.1 + x2 * 0.9
... and this is exactly what I'm getting in Paint.NET
http://i.imgur.com/SjXSSjx.png
Here's a visualization of weights:
http://i.imgur.com/J77hULO.png
Top ones are distances from the borders of source pixels to destination pixels (~area)
Middle ones are distances from centers to centers (like how shader samples stuff)
Bottom ones are rescaled destination coordinates for results to match top row (just plain stretch). Here's a formula
double recalc (double x, double y, double dst) {
double factor = (1.5 - y / x) * y / x;
return (dst - 0.5) * (y - 2.0 * factor) / (y - 1.0) + factor;
}(x and y are source and destination sizes, dst is coordinate of the destination to be rescaled)
I've checked and it works on other factors... So, well, it's still bilinear, but stretched by a fraction of pixel.
colours
12th February 2015, 10:15
Dunno how/why avisynth calculates it that way, but shader sample centers of pixels.
I didn't refer to what Avisynth did; the calculations were done by hand, also assuming centred sampling. You seem to be forgetting that the kernel should be enlarged to account for the fact that you're downsampling.
Alternatively, I could have made a dumb mistake somewhere.
But still, neither of our calculations for nearest neighbour → bilinear agree with grid overlay, which was kind of my point.
Katie Boundary
13th February 2015, 05:08
This is hardly a new idea; see http://entropymine.com/imageworsener/pixelmixing/.
It's new until someone actually implements it. I don't suppose you could point me to a plugin for AVIsynth or Vdub?
colours
13th February 2015, 07:29
It's new until someone actually implements it.
You are trolling, aren't you?
This is the first Google result for "netpbm pixel mixing". (http://netpbm.sourceforge.net/doc/pamscale.html)
It's also implemented in ImageMagick. (http://imagemagick.org/Usage/resize/#pixel_mixing)
In fact, that pixel mixing article I linked was from someone who wrote an image processing utility that implemented it (http://entropymine.com/imageworsener/).
Want it as an Avisynth filter? That's easily done with Dither_resize16(kernel="box").
Katie Boundary
13th February 2015, 12:02
This is the first Google result for "netpbm pixel mixing". (http://netpbm.sourceforge.net/doc/pamscale.html)
And I would have googled "netpbm" because...?
Want it as an Avisynth filter? That's easily done with Dither_resize16(kernel="box").
Cool. I assume that documentation related to this filter exists?
Reel.Deel
13th February 2015, 13:46
And I would have googled "netpbm" because...?
Because netpbm is quickly mentioned in the article that colours linked.
This document examines a common image resizing algorithm that doesn’t seem to have a standardized name. It’s sometimes called pixel mixing, pixel averaging, or area map, among other things. I’ll follow netpbm’s terminology, and call it pixel mixing.
Cool. I assume that documentation related to this filter exists?
Documentation for this filter does indeed exist.
Katie Boundary
13th February 2015, 20:25
Documentation for this filter does indeed exist.
I can has links please?
TheSkiller
14th February 2015, 11:38
I can has links please?
Why so lazy, don't you know how to use the board search?
The doc is in the download package of dither.
http://forum.doom9.org/showthread.php?p=1386559#post1386559
Katie Boundary
15th February 2015, 03:31
Why so lazy, don't you know how to use the board search?
more like "I had no idea what to search for"
EDIT: I can find nothing in the documentation to indicate that this is how the filter in question works.
colours
15th February 2015, 17:15
I don't normally mind spoonfeeding but you seem to think you have an IQ well above all the other posters here, so I'll refrain from that and let you educate yourself.
[…] this grid overlay method is effectively a convolution of two box filters […]
Hint: the key words are "convolution" and "box filters".
Discretisation of the above concepts is left as an exercise for the reader.
Katie Boundary
15th February 2015, 19:01
you seem to think you have an IQ well above all the other posters here
I started out humble, but repeated exposure to obvious idiocy changed my attitude somewhat. I'm as sensitive to logical fallacies and semantic dissonance as a shark's nose is to blood, and some of these posters are just hemorrhaging.
[…] this grid overlay method is effectively a convolution of two box filters […]
That's funny, I can't find that phrase anywhere in the Dither documentation.
colours
15th February 2015, 20:01
Firstly, it doesn't matter whether it's in Dither's documentation or not because, in case you can't put two and two together, I wrote that post before I even mentioned anything about Avisynth.
Secondly, it still doesn't matter because you're wrong anyway: Dither's documentation does in fact mention "box filter" and "convolution", albeit the discrete versions of them. If you're whining about the whole sentence I wrote not being in there, well duh, why would a sentence I wrote recently be in documentation written by someone else years ago? Since you didn't seem to get the hint earlier, let me make this explicit for you: search those terms on Google yourself.
You say other posters have exhibited "obvious idiocy", but have you ever looked in a mirror?
Katie Boundary
15th February 2015, 20:19
Firstly, it doesn't matter whether it's in Dither's documentation or not
It does when you're specifically responding to the statement "I can find nothing in the documentation to indicate that this is how the filter in question works."
Bloax
15th February 2015, 21:18
I started out humble, but repeated exposure to obvious idiocy changed my attitude somewhat. I'm as sensitive to logical fallacies and semantic dissonance as a shark's nose is to blood, and some of these posters are just hemorrhaging.
Your very first post wasn't exactly good, and the one after that (http://forum.doom9.org/showthread.php?t=171736) is complete trollbait.
You're the worst shitposter I've seen, but if it's just your autistic fury that flares up at every single post by anyone then you should probably just go away until you calm down.
Because until then everyone is definitely going to treat you like a shitposter.
colours
15th February 2015, 21:21
It does when you're specifically responding to the statement "I can find nothing in the documentation to indicate that this is how the filter in question works."
Of course you found nothing; that's just not how the filter in question works, and nobody claimed so. Did I say that implementing a grid overlay filter in Avisynth would involve a Dither_resize16 call and nothing else? (For the record, I wasn't even responding to that statement.)
Do yourself a favour and read up on some basic image processing before making another post in this thread.
Katie Boundary
15th February 2015, 22:39
Of course you found nothing; that's just not how the filter in question works, and nobody claimed so. Did I say that implementing a grid overlay filter in Avisynth would involve a Dither_resize16 call and nothing else?
You did. Your exact words were:
Want it as an Avisynth filter? That's easily done with Dither_resize16(kernel="box").
If you meant to say "That's easily done with Dither_resize16(kernel="box") and some other stuff", then you should have said that. For comparison, I have a multi-step process for dealing with hard-telecined content, and one of those steps is resizing, but if I told someone "IVTC is easily done with Dither_resize16(kernel="box")" and left out the separatefields step, they'd have every right to wonder what the hell I was going on about.
Stereodude
15th February 2015, 23:20
Your very first post wasn't exactly good, and the one after that (http://forum.doom9.org/showthread.php?t=171736) is complete trollbait.
You're the worst shitposter I've seen, but if it's just your autistic fury that flares up at every single post by anyone then you should probably just go away until you calm down.
Because until then everyone is definitely going to treat you like a shitposter.
Too bad we can't like posts on this forum because this one would gather a lot of them. I sense a lot of ignore lists growing.
colours
16th February 2015, 00:08
For comparison, I have a multi-step process for dealing with hard-telecined content, and one of those steps is resizing, but if I told someone "IVTC is easily done with Dither_resize16(kernel="box")" and left out the separatefields step, they'd have every right to wonder what the hell I was going on about.
I'd have every right to wonder why the hell you think that resizing is in any way a core part of inverse telecine.
Maybe this is one of those "strawman" (https://yourlogicalfallacyis.com/strawman) arguments you yourself brought up earlier? :rolleyes:
Katie Boundary
16th February 2015, 01:54
I'd have every right to wonder why the hell you think that resizing is in any way a core part of inverse telecine.
lol that too :)
Maybe this is one of those "strawman" (https://yourlogicalfallacyis.com/strawman) arguments you yourself brought up earlier? :rolleyes:
How? Nobody's position has been misrepresented in the past several posts.
EDIT: perhaps we should clarify which definition of convolution (http://en.wikipedia.org/wiki/Convolute) we're using so that the discussion is less opaque. I'm only familiar with the convolution matrices in Vdub and AVIsynth that are used for sharpening, blurring, emboss effects, etc.
colours
16th February 2015, 13:18
EDIT: perhaps we should clarify which definition of convolution (http://en.wikipedia.org/wiki/Convolute) we're using so that the discussion is less opaque.
https://en.wikipedia.org/wiki/Convolution#Definition
Take note that the domain we're talking about is ℝ^2, not ℤ^2; in other words, stop thinking about pixels as being square boxes and instead treat them as point samples, like people have been telling you to since the very first page of this thread.
Katie Boundary
18th February 2015, 02:20
Take note that the domain we're talking about is ℝ^2, not ℤ^2
Yeah i dunno what that means lol
in other words, stop thinking about pixels as being square boxes and instead treat them as point samples
But they're squares :/
Katie Boundary
19th February 2015, 00:56
if it's just your autistic fury that flares up at every single post by anyone
I made this just for you: :cool:
Image removed by mod manono
Clean up your act Miss Boundary or we'll clean it up for you.
jmac698
21st August 2015, 01:14
Hmm this thread didn't seem to go anywhere productively, but I read it with interest back when. I was gonna write this filter but then found some programs that already did it, so let me give you the answers you were wondering about.
This has gone by names like pixel mixing or area scaling. Here's places that discuss it:
http://entropymine.com/imageworsener/pixelmixing/
https://tpgit.github.io/UnOfficialLeptDocs/leptonica/scaling.html#area-mapping-or-area-averaging-and-lowpass-filtering
http://netpbm.sourceforge.net/doc/pamscale.html#mixing
In summary:
-keeps overall brightness the same
-good quality for downsizing
-causes a small amount of aliasing/moire and doesn't reduce aliasing
-for large scaling is like a box filter or almost pixel replication
-trapezoidal at 2x or 1/2x
-can be approximated with standard filter kernels (which are chosen depending on scale)
-good at downscaling between .2 and .7
You can download binaries for windows here:
https://onedrive.live.com/?cid=9E7DB242359A93F0&id=9E7DB242359A93F0!28283
use pamscale function.
pandy
21st August 2015, 08:49
But they're squares :/
This one bellow should help you to understand basic sampling concepts: http://www.youtube.com/watch?v=cIQ9IXSUzuM
It is for audio but this particular topic (squares) are mentioned as one of the examples - watch carefully especially from 5:15 (squares appears in 8:10).
jmac698
21st August 2015, 13:32
She hasn't been active since May, maybe ppl scared her away lol
Katie Boundary
31st July 2016, 20:50
I'm resurrecting this topic because, in the past month, I've gained a better understanding of things like the difference between "interpolation" and "filtering" in a signal-processing context, how larger support sizes improve anti-aliasing, etc. and I felt like re-evaluating my approach.
For downscaling, this method really is 100% mathematically perfect in every possible way. It doesn't produce the oversharpening of Simpleresize (approaching Nearest Neighbor-like effects at extreme scaling factors), nor the overblurring of a box or triangle filter. Its suitability for downscaling is reason enough on its own to add it to programs like AVIsynth and Virtualdub.
Upscaling reveals something more interesting. When upscaling, its major advantage is also its biggest downfall: it is content-neutral. Pixel Mixing simply doesn't care whether the image being resized is a photograph, a CAD image, pixel art, or whatever. This makes it by far the best upscaler for images that are expected to look pixelated, but pretty terrible for anything that you're likely to rip from a DVD or Blu-Ray.
Nevilne
31st July 2016, 23:38
She hasn't been active since May, maybe ppl scared her away lol
welp, here goes that wish
Katie Boundary
1st February 2017, 19:32
It looks like Chikuzen wrote one of these approximately four years ago: http://www.mediafire.com/file/kn56wh7r81vk2rx/AreaResize-0.1.0.zip
However, it didn't get very far. Are there any known bugs or deficiencies?
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.