VSE: Fix various "off by half a pixel" issues in image transform #116628
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#116628
Loading…
Reference in New Issue
No description provided.
Delete Branch "aras_p/blender:vse-fix-filter"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Code inside
IMB_transform
(which is pretty much only used inside VSE to do translation/rotation/scale of image or movie strips) was not correctly doing mapping between pixel and texel spaces. This is similar to e.g. GPU rasterization rules and has to do with whether some coordinate refers to pixel/texel "corner" or "center" etc. It's a long topic, but short summary would be:floor(x-0.5)
andfloor(x-0.5)+1
texels.Also, there was a sign error introduced in Subsampling 3x3 filter, in commit
b3fd169259
(shipped in Blender 3.5 and later).After making the PR, I found out that this seems to fix #90785, #112923 and possibly some others.
Question 1: should IMB_transform get some sort of test coverage to ensure all the sampling mode edge cases work as expected? Maybe similar to the images below, actually.
Question 2: looks like VSE "transform" effect bilinear and bicubic options also have the "result is shifted by half a pixel" issue. Should that also be fixed here, or separately?
Long explanation with lots of images!
All of this is best explained with images. VSE render output is setup to be 192x108 and image strips with very thin single-pixel features. Resulting images scaled up 400% with nearest neighbor filtering, so that things can be seen better. Test input images:
Current behavior in main:
And now the same input images scaled as needed to cover "full frame", also with some cases of rotation. Under the image is pure magenta color strip. 12x6 scaled up to 192x108, using nearest, bilinear, subsampling 3x3 respectively:
Nearest ✅:
Bilinear ❌ shifted by half the (very enlarged) pixel, magenta background leaks in:
Subsampled ❌ almost correct, but a tiny sliver of magenta leaks in top/right:
96x54 scaled up to 192x108:
Nearest ✅:
Bilinear ❌ again shifted by half a texel:
Subsampled ❌ again magenta sliver at top/right:
192x108 image: this needs no scaling, and looks identical between different filter modes, both before and after the PR ✅:
384x216 image scaled down to 192x108:
Nearest ✅ (misses half of pixel-size features, but by design):
Bilinear ❌ - this downsamples exactly 2x, so you'd expect it would average each 2x2 pixel block. It does not!
Subsampled ❌ - not great, not terrible. Strangely misses any trace of green pixel at top/right edge:
96x54 image, rotated -90 degrees, scaled up to 192x108:
Nearest ❌: introduces diagonal "shift line":
Bilinear ❌: magenta background leaks on the left side:
Subsampled ❌ slight magenta leak on top; horizontal lines at top/left not fully horizontal:
384x216 image, rotated -90 degrees, scaled down to 192x108:
Nearest ❌ magenta leak on left:
Bilinear ❌: magenta background leaks on left, also similar to un-rotated, it does not average 2x2 pixels at all:
Subsampled ❌: loses any trace of green outline on top/right:
And here's things after this PR
I'm only including things that are different, and all of them I think are "clearly better".
12x6 scaled up, bilinear:
12x6 scaled up, subsampled:
96x54 scaled up, bilinear:
96x54 scaled up, subsampled:
384x216 scaled down, nearest (this now picks different features than before, expected):
384x216 scaled down, bilinear:
384x216 scaled down, subsampled:
96x54, rotated -90 degrees, scaled up, nearest:
96x54, rotated -90 degrees, scaled up, bilinear:
96x54, rotated -90 degrees, scaled up, subsampled:
384x216, rotated -90 degrees, scaled down, nearest:
384x216, rotated -90 degrees, scaled down, bilinear:
384x216, rotated -90 degrees, scaled down, subsampled:
@blender-bot build
WIP: VSE: Fix various "off by half a pixel" issues in image transformto VSE: Fix various "off by half a pixel" issues in image transformThis is great! I have spent quite a bit of time on this issue, but never got it quite right :/ I guess there will be still some limitations around image edges, but this is big improvement
When. I refactored IMB_transform I kept the previous behavior. I am fine to mark this to solve a bug. I will leave the code reviewing to Richard for this one. To my knowledge the image editor doesn't use interpolation.
On topic of tests, I don't see any harm done by including some. I think, that it would make sense to ensure quality of this feature.
For Q2, I am not quite sure what the issue is right now, so would have to leave up to you.
Alright, I'll add some tests separately.
It's kinda the same issue as here, just in different place of the code. Why "strip transform" effect uses a separate code instead of IMB_transform... that's a good question :) I'll fix that later separately.