Fix ImageMobject
3D rotation/flipping and remove resampling algorithms lanczos
(antialias
), box
and hamming
#4266
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2412
Therefore, also fixes its duplicates #2979, #3131, #3559 and part of #3646.
As I commented in the "Image issues Tracking" issue #3482:
The solution I described, which was also discussed in some of the issues I mentioned before, consists of leveraging
PIL.Image.Image.transform()
to rewriteCamera.display_image_mobject()
. Figuring out how to usePIL.Image.Image.transform()
was the actual challenge, but this StackOverflow discussion shed light on this problem (thank you very much, mmgp ❤️).I'll use the example provided by @hennels on issue #2412 (thanks!). I'm including the generated video after applying these changes.
There are still some issues, though:
ImageIn3D_new.mp4
However, this PR must introduce a...
BREAKING CHANGE 💥
PIL.Image.Image.transform()
only supports theNEAREST
,BILINEAR
andBICUBIC
resampling algorithms. It does not supportBOX
,HAMMING
orLANCZOS
. That is a big issue, sinceCamera.display_image_mobject()
runs for every frame and you can't opt out of using it. Even in 2D scenes where there's no actual need for a perspective transform, one still has to account for possible shears of an image, which seems to require.transform()
anyways. There doesn't seem to exist a proper fix to the 3D rotation / flipping / shear issue without usingPIL.Image.Image.transform()
.If such fix does not exist, then it is not possible to support
BOX
,HAMMING
orLANCZOS
. Therefore, I removed support for them in this PR by removing the following constants:I also rewrote
tests/test_graphical_units/test_img_and_svg.py::test_ImageInterpolation
to remove those now unsupported resamping algorithms and rewroteAbstractImageMobject.set_resampling_algorithm()
to better capture invalid values.Reviewer Checklist