

- Modul8 preload bilinear filter vs lossless quality how to#
- Modul8 preload bilinear filter vs lossless quality series#
The most typical way of doing bilinear downsampling is the same as box downsampling.

After discretizing them (evaluating filter weights at sample points), there is no difference, as we no longer know what was the formula to generate them, and how the filter kernel looked outside of the evaluation points. The reason for it is that in this case, both filters are centered between the pixels. We can see that a 2 tap box filter is the same as a 2 tap bilinear filter. Blue lines represents discretized weights of the kernel. Black dots represent pixel centers, upper row is the target/low resolution texture, and the bottom row the source, higher resolution one. (Bi)linear vs box downsampling give us the same effective weights. Let’s have a look at the following diagram:

When downsampling images by 2, we every often use terms box filter and bilinear filter interchangeably. Is this box or bilinear downsampling? Two ways of addressing it I will circle back to it, but first address the first common confusion. It is using a bilinear filter to prevent signal aliasing when decimating the input image – ugh, lots of technical terms. Let’s start with the most simple explanation, without the nitty gritty: it is creating a larger resolution image where every sample is created from bilinear filtering of a smaller resolution image.įor the bilinear downsampling, things get a bit muddy. I will focus here exclusively on 2x up/downsampling and hope that some thought framework I propose and use here will be beneficial for you to also look at and analyze different (and non-integer factors).īecause of bilinear separability, I will again abuse the notation and call “bilinear” a filter when applied to 1D signals and generally a lot of my analysis will be in 1D. So let’s have a look at what’s the problem. I also respect how he amended and improved the post multiple times. “Magic kernel” is just an example of why it’s so hard and confusing to talk about “bilinear”. Some parts of it like phase shifting are so tricky that a famous blog post of “magic kernel” comes up every few years and again, experts re(read) it a few times to figure out what’s going on there, while the author simply rediscovered the bilinear! ( Important note: I don’t want to pick on the author, far from it, as he is a super smart and knowledgeable person, and willingness to share insights is always respect worthy. Image credit/source: Oleksandr Savsunenko I know of some of my colleagues that spent months on fixing it in Tensorflow 2 – imagine effort of fixing incorrect uses and “fixing” already trained models that were trained around this bug… It’s also surprisingly hard to get it right even by image processing professionals, and a source of long standing bugs and confusion in top libraries (and I know of some actual production bugs caused by this Tensorflow inconsistency)!Įdit: there’s a blog post titled “How Tensorflow’s tf.image.resize stole 60 days of my life” and it’s describing same issue. Which is kind of surprising for a bread and butter type of image processing operation that is used all the time! One of the few ideas I’d like to convey in this post is that bilinear upsampling / downsampling doesn’t have a single meaning or a consensus around this term use. The term bilinear upsampling and downsampling is used a lot, but what does it mean? Let’s go!Įdit: I wrote a follow-up post to this one, about designing downsampling filters to compensate for bilinear filtering. I highly recommend my previous post as a primer on the topic, as I’ll use some of the tools and terminology from there, but it’s not strictly required. We will touch here on GPU half pixel offsets, aligning pixel grids, a bug / confusion in Tensorflow, deeper signal processing analysis of what’s going on during bilinear operations, and analysis of the magic of the famous “magic kernel”. So I figured it’s an opportunity for another short blog post – on bilinear filtering, but in context of down/upsampling.
Modul8 preload bilinear filter vs lossless quality series#
😅 Similarly, just last week a colleague asked for a very fast implementation of bilinear on a CPU and it caused a series of questions “which kind of bilinear?”. It’s been more than two decades of me using bilinear texture filtering, a few months since I’ve written about bilinear resampling, but only two days since I discovered a bug of mine related to it.
Modul8 preload bilinear filter vs lossless quality how to#
See this ugly pixel shift when upsampling a downsampled image? My post describes where it can come from and how to avoid those!
